このページはまだ書きかけです
*はじめに [#l1e65d6c]
*準備 [#j4c98aa4]
データ
#geshi(rsplus){{
> data(iris)
}}
*主成分分析を実行する [#xcf07f9a]
主成分分析を実行
#geshi(rsplus){{
> iris.pc <- princomp(~Sepal.Length+Sepal.Width, cor=T, data=iris)
}}
主成分分析の結果
#geshi(rsplus){{
> iris.pc
Call:
princomp(formula = ~Sepal.Length + Sepal.Width, data = iris,
cor = T)
Standard deviations:
Comp.1 Comp.2
1.0571517 0.9393776
2 variables and 150 observations.
}}
固有ベクトル
#geshi(rsplus){{
> unclass(loadings(iris.pc))
Comp.1 Comp.2
Sepal.Length -0.7071068 -0.7071068
Sepal.Width 0.7071068 -0.7071068
}}
固有値
#geshi(rsplus){{
> iris.pc$sd^2
Comp.1 Comp.2 Comp.3 Comp.4
2.91849782 0.91403047 0.14675688 0.02071484
}}
因子寄与率(主成分寄与率)
#geshi(rsplus){{
> iris.pc$sd^2/sum(iris.pc$sd^2)
Comp.1 Comp.2 Comp.3 Comp.4
0.729624454 0.228507618 0.036689219 0.005178709
}}
因子負荷量(主成分負荷量)
#geshi(rsplus){{
> t(iris.pc$sd * t(iris.pc$loadings))[, drop=F]
Comp.1 Comp.2 Comp.3 Comp.4
Sepal.Length 0.8901688 -0.36082989 0.27565767 0.03760602
Sepal.Width -0.4601427 -0.88271627 -0.09361987 -0.01777631
Petal.Length 0.9915552 -0.02341519 -0.05444699 -0.11534978
Petal.Width 0.9649790 -0.06399985 -0.24298265 0.07535950
}}
tは行列などを転置する関する,drop=F は行列と表示するオプション.
*主成分分析の結果をグラフに表示する [#abbae3e6]
#geshi(rsplus){{
> biplot(iris.pc)
}}