全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
4639 4
2014-02-07

插补数值mice函数如下:数据集dataname

library(mice)
X=mice(dataname,seed=1000)
Y=with(X,lm(a~b+c))
Z=pool(Y)
summary(Z)


请问我想用插补后的数据进行PCA主成分分析,怎么做呢?

虚心求教!


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2014-12-16 13:44:00
给你一个例子吧

pca
head(iris)
library(psych)
cortest.bartlett(cor(iris[,-5]), n=150)


kmo = function( data ){
   library(MASS)
   X <- cor(as.matrix(data))
   iX <- ginv(X)
   S2 <- diag(diag((iX^-1)))
   AIS <- S2%*%iX%*%S2 # anti-image covariance matrix
   IS <- X+AIS-2*S2 # image covariance matrix
   Dai <- sqrt(diag(diag(AIS)))
   IR <- ginv(Dai)%*%IS%*%ginv(Dai) # image correlation matrix
   AIR <- ginv(Dai)%*%AIS%*%ginv(Dai) # anti-image correlation matrix
   a <- apply((AIR - diag(diag(AIR)))^2, 2, sum)
   AA <- sum(a)
   b <- apply((X - diag(nrow(X)))^2, 2, sum)
   BB <- sum(b)
   MSA <- b/(b+a) # indiv. measures of sampling adequacy
   
   AIR <- AIR-diag(nrow(AIR))+diag(MSA) # Examine the anti-image of the
   # correlation matrix. That is the
   # negative of the partial correlations,
   # partialling out all other variables.
   
   kmo <- BB/(AA+BB) # overall KMO statistic
   
   # Reporting the conclusion
   if (kmo >= 0.00 && kmo < 0.50){
      test <- 'The KMO test yields a degree of common variance
    unacceptable for FA.'
   } else if (kmo >= 0.50 && kmo < 0.60){
      test <- 'The KMO test yields a degree of common variance miserable.'
   } else if (kmo >= 0.60 && kmo < 0.70){
      test <- 'The KMO test yields a degree of common variance mediocre.'
   } else if (kmo >= 0.70 && kmo < 0.80){
      test <- 'The KMO test yields a degree of common variance middling.'
   } else if (kmo >= 0.80 && kmo < 0.90){
      test <- 'The KMO test yields a degree of common variance meritorious.'
   } else {
      test <- 'The KMO test yields a degree of common variance marvelous.'
   }
   
   ans <- list( overall = kmo,
                report = test,
                individual = MSA,
                AIS = AIS,
                AIR = AIR )
   return(ans)
   
} # end of kmo()


kmo(iris[,-5])


iris.pr<-princomp(iris[,-5],cor=TRUE)
summary(iris.pr,loadings=TRUE)
plot(iris.pr,type="lines")


iris.pr$scores
scale(iris.pr$scores)

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-4-23 10:57:04
谢谢你。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-4-23 10:58:04
DM小菜鸟 发表于 2014-12-16 13:44
给你一个例子吧

pca
谢谢您!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2019-12-6 14:22:56
搭车请教个问题:缺失率是多少的时候,就考虑不把该变量纳入PCA中了呢,谢谢。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群