pca - Confidence intervals of loadings in principal components in R -
i using following code principal component analysis of first 4 columns of iris data set using prcomp function in r:
> prcomp(iris[1:4]) standard deviations: [1] 2.0562689 0.4926162 0.2796596 0.1543862 rotation: pc1 pc2 pc3 pc4 sepal.length 0.36138659 -0.65658877 0.58202985 0.3154872 sepal.width -0.08452251 -0.73016143 -0.59791083 -0.3197231 petal.length 0.85667061 0.17337266 -0.07623608 -0.4798390 petal.width 0.35828920 0.07548102 -0.54583143 0.7536574
how can confidence intervals of these values in r? there package can it? help.
you use bootstrapping on this. re-sample data bootstrapping package , record principal components computed every time. use resulting empirical distribution confidence intervals.
the boot
package makes pretty easy.
here example calculating confidence interval @ 95% first pca component respect sepal.length:
library(boot) getprcstat <- function (samdf,vname,pcnum){ prcs <- prcomp(samdf[1:4]) # returns matrix return(prcs$rotation[ vname,pcnum ]) # pick out thing need } bootest <- function(df,d){ sampleddf <- df[ d, ] # resample dataframe return(getprcstat(sampleddf,"sepal.length",1)) } bootout <- boot(iris,bootest,r=10000) boot.ci(bootout,type=c("basic"))
the output is:
bootstrap confidence interval calculations based on 10000 bootstrap replicates call : boot.ci(boot.out = bootout, type = c("basic")) intervals : level basic 95% ( 0.3364, 1.1086 ) calculations , intervals on original scale
so using usual basic bootstrap method 95 percent confidence interval of between 0.3364 , 1.1086. there plenty of other more advanced statistical methods can used too, need know doing.
Comments
Post a Comment