# # Beispiel I.6 # # Beispeil 1: Mathe-/Physiknoten (siehe Vorlesung) # noten <- data.frame(Mathe=c(1,2,1,3,4,1,5,3), Physik=c(1,1,2,3,3,1,5,5)) # # Ränge rank( noten$Mathe ) rank( noten$Physik ) # # (Pearsons) Korrelationskoeffizient # summary(noten) sd( noten$Mathe ) sd( noten$Physik ) cor( noten ) # # Spearmans Korrelationskoeffizient # mean( rank( noten$Mathe ) ) # nur zur Überprüfung unserer Formel, hängt nicht mean( rank( noten$Physik ) ) # von den Werten ab, nur von der Anzahl sd( rank( noten$Mathe ) ) sd( rank( noten$Physik ) ) # von Hand (sum( (rank(noten$Mathe) - 4.5)* (rank(noten$Physik) - 4.5) ) / (7*sd( rank( noten$Mathe ) )*sd( rank( noten$Physik ) )) ) # komfortabler mit Formel cor( noten, method = "spearman" ) # # Beispiel 2: mtcars # # Streudiagramm für mpg and hp # plot(mtcars$mpg, mtcars$hp) # # Korrelation zwischen mpg und hp cor( mtcars$mpg, mtcars$hp) # # Streudiagramm für wt und hp # plot(mtcars$wt, mtcars$hp) # # Korrelation zwischen wt und hp cor( mtcars$wt, mtcars$hp) # # Streudiagramm für wt und qsec # plot(mtcars$wt, mtcars$qsec) # # Korrelation zwischen wt und qsec cor( mtcars$wt, mtcars$qsec) # # Streudiagramme für alle # möglichen Paare von mtcars plot(mtcars)