Multivariate kansverdelingen in R
Surajit Ray
Professor, University of Glasgow
De functie princomp() berekent PC's

Vereenvoudigd formaat
princomp(x, cor = FALSE, scores = TRUE)
x: een numerieke matrix of data framecor: gebruik correlatiematrix in plaats van covariantiescores: scores/projectie van de data op principal components worden geproduceerdDe gegevensset mtcars bevat 11 variabelen over brandstofverbruik voor 32 auto's
head(mtcars,5)
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1
Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2
vs en am uit — beide binairmtcars.sub <- mtcars[ , -c(8,9)]
$$cars.pca <- princomp(mtcars.sub, cor = TRUE, scores = TRUE)
cars.pca
Standaardafwijkingen:
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6 Comp.7 Comp.8 Comp.9
2.378 1.443 0.710 0.515 0.428 0.352 0.324 0.242 0.149
summary(cars.pca)
Belang van componenten:
Comp.1 Comp.2 Comp.3 Comp.4 Comp.5 Comp.6 Comp.7 Comp.8 Comp.9
Standaardafwijking 2.378 1.443 0.710 0.5148 0.4280 0.3518 0.3241 0.2419 0.14896
Aandeel van variantie 0.628 0.231 0.056 0.0294 0.0204 0.0138 0.0117 0.0065 0.00247
Cumulatief aandeel 0.628 0.860 0.916 0.9453 0.9656 0.9794 0.9910 0.9975 1.00000
Multivariate kansverdelingen in R