#Vorlesung Multivariate Analysen #=============================== # #Kapitel 1.4: Hauptkomponentenanalyse #==================================== # #Hauptkomponentenanalyse für zwei Variablen #========================================== # #Noten.rda #Grafische Darstellung für zwei Variablen scatterplot(Noten[,"Mathe"], Noten[,"VWL"],ellipse=TRUE,levels=c(0.9545),pch=19, xlim=c(0,4.5),ylim=c(0,4.5),cex=1.4,reg.line=FALSE, smooth=FALSE, boxplots=FALSE, xlab="Note Mathe", ylab="Note VWL") # #Korrelation zwischen zwei Variablen cor(Noten[c("Mathe","VWL")]) # #Berechnungen in R #Menü: Statistik/Dimensionsreduktion und Klassifizieren/Hauptkomponenten-Analyse... .PC <- princomp(~Mathe+VWL, cor=TRUE, data=Noten) unclass(loadings(.PC)) # component loadings .PC$sd^2 # component variances summary(.PC) # proportions of variance Noten$PC1 <- .PC$scores[,1] Noten$PC2 <- .PC$scores[,2] remove(.PC) # #Varianzberechnung der ersten Hauptkomponente var(Noten$PC1) # #Korrektur der Freiheitsgrade var(Noten$PC1)*(17-1)/17 # # #Grafische Darstellung plot(Noten$PC1, type="h",lwd=2, col="blue") abline(h=0, col="gray") # # #Hauptkomponentenanalyse für mehrere Variablen #============================================= # #Berechnungen für mehrere Variablen .PC <- princomp(~BWL+Mathe+Methoden+VWL, cor=TRUE, data=Noten) unclass(loadings(.PC)) # component loadings .PC$sd^2 # component variances summary(.PC) # proportions of variance screeplot(.PC) Noten$PC1 <- .PC$scores[,1] Noten$PC2 <- .PC$scores[,2] #remove(.PC) # #Grafische Darstellung für zwei Variablen plot(.PC$scores[,1:2],type="n") text(Noten$PC1,Noten$PC2,1:17) lines(c(-3.2,3.2),c(0,0)) lines(c(0,0),c(-1.6,1.6)) # # #Bestimmung der Anzahl der Hauptkomponenten #========================================== # #Screeplot screeplot(.PC, type="lines") # #Kaiser-Kriterium erg<-eigen(cor(Noten[,1:4]))$values erg mean(erg) # # # #Beispiel und Übung #================== # #AutoTest (Daten vom ADAC) # .PC <- princomp(~Motor+Umwelt+Fahreigenschaften, cor=TRUE, data=AutoTest) unclass(loadings(.PC)) # component loadings .PC$sd^2 # component variances summary(.PC) # proportions of variance plot(.PC$scores[,1:2],xlim=c(-2.8,2.8),ylim=c(-2,2),type="n",cex.lab=1.3, xlab="(+) Fahrspaß (-)",ylab="(-) Umweltverantwortung (+)") text(.PC$scores[,1],.PC$scores[,2],AutoTest[,1]) #remove(.PC) # #Aufgabe: Erweiterung um (a) Wirtschaftlichkeit, (b) Innenraum und #(c) alle Variablen. Versuch der Interpretation # # #Für alle Variablen screeplot(.PC, type="lines") # # erg<-eigen(var(Noten[,1:4]))$values erg mean(erg) # # # #Übung: Evaluation Statistik "StatSS09" # # ###