4

I'm uncertain on how I would run a PCA analysis via prcomp after running the mice function in R

If I run:

imp <- mice(Data, maxit = 20, m = 5)

It is my understanding that I now have 5 imputations of the data. In the JSS Buuren paper they then run:

fit <- with(imp, lm(chl ~ age + bmi))
pool(fit)

Which I understand that as running a linear regression with the 5 imputated data sets and then pooling the findings.

If I'm interested in instead running prcomp would I insert prcomp instead of lm in the with function?

Or would I possibly be better off extracting the 5 imputations via the complete function and averaging them and then inputing the averaged data into the prcomp function?

Thanks

Michael
  • 41
  • 3
  • Here is a minimal reproducible example. Lines end where there are #. `#reproducible example# library(mice) # x = data.frame(matrix(rnorm(100),10,10)) #create random data # colnames(x) = paste0("x",LETTERS[1:10]) # x[9:10,] = NA #add missingness # x.mice = mice(x) #make imputed data set # prcomp(x.mice) #does not work # x.prcomp = with(x.mice,prcomp(cbind(xA,xB,xC,xD,xE,xF,xG,xH,xI,xJ))) # x.pooled = pool(x.prcomp) #does not work #` – Paul de Barros Mar 29 '16 at 14:03

1 Answers1

0

OK, the question is 7 years old, but it took me a while since I found a solution for the same problem: In the documentation of the miceadds package they give an example how to do this:

prcomp(complete(x.mice))

Standard deviations (1, .., p=10): [1] 1.674322e+00 1.480678e+00 1.139431e+00 1.057412e+00 9.096070e-01 5.692266e-01 4.525504e-01 2.262923e-01 [9] 3.655849e-02 2.080986e-17

Rotation (n x k) = (10 x 10): PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC8 PC9 xA 0.19646003 0.13756831 -0.33982392 0.069017366 -0.14163694 0.713314386 0.42817540 -0.02557612 0.26406627 xB 0.29362035 -0.05717179 0.18365741 -0.099420255 0.18354113 -0.325487631 0.14143764 0.25553536 0.79869087 xC -0.83458775 0.33975219 -0.14013481 -0.050463071 0.02468307 -0.004927709 -0.08765055 -0.07445376 0.38288139 xD -0.38346818 -0.72943808 0.06694925 0.219279568 0.29940640 0.103372672 0.38070191 0.14498401 -0.04125054 xE 0.07672487 0.33595433 -0.09365447 0.799073313 0.29771356 -0.094890402 0.07193397 0.03993132 0.01295771 xF 0.05436489 -0.37888215 0.07342579 0.309004299 -0.18074367 0.301450564 -0.66069343 -0.26573022 0.34512713 xG -0.01068478 0.19632445 0.47721165 -0.274347023 0.51557432 0.513112074 -0.15834345 0.16277618 -0.03726818 xH -0.13117602 -0.02992028 0.12868496 -0.003784248 -0.61694746 0.079079964 0.09069560 0.51198774 0.05424938 xI -0.05834026 0.12078943 0.70341638 0.169541787 -0.27858258 -0.014856917 0.36124512 -0.49151047 0.03382389 xJ 0.04515351 -0.14088749 -0.27096456 -0.310958714 0.10318544 -0.069965683 0.19636183 -0.55232842 0.13894432 PC10 xA 0.19909038 xB 0.06375321 xC 0.07341503 xD 0.01790238 xE -0.35970015 xF -0.05325361 xG -0.27620057 xH -0.55239981 xI 0.08610280 xJ -0.65537939

  • It is great you made the effort to answer an old question. It would be more helpful, though, if you formatted the output a bit so that we can actually read it like a table (or what format should it have?). You may want to see [this useful post](https://meta.stackoverflow.com/questions/251361/how-do-i-format-my-code-blocks) about formatting and code blocks. – benimwolfspelz Jul 11 '23 at 11:50