0

I have data (pisa_math_tot) that is stored as a list. I want to impute the missing data using the mice function from the mice package.

mice starts with a data frame containing missing data and returns an object containing several complete datasets (the default is 5). Each complete dataset is created by imputing values for the missing data in the original data frame.

type of(pisa_math_tot) # [1] "list"
md.pattern(pisa_math_tot)      # output tell us 194 complete and 436 missing

#   HKG   PISAMATH   TOT   MEANSCORE   SVN   PISAMATH.1   TOT.1
#1  AUS   PISAMATH   TOT   MEANSCORE    A       2000       NA
#2  AUS   PISAMATH   TOT   MEANSCORE    A       2001       NA
#3  AUS   PISAMATH   TOT   MEANSCORE    A       2002       NA
#4  AUS   PISAMATH   TOT   MEANSCORE    A       2003       524
#5  AUS   PISAMATH   TOT   MEANSCORE    A       2004       NA
#6  AUS   PISAMATH   TOT   MEANSCORE    A       2005       NA
#7  AUS   PISAMATH   TOT   MEANSCORE    A       2006       520
#8  AUS   PISAMATH   TOT   MEANSCORE    A       2007       NA
#9  AUS   PISAMATH   TOT   MEANSCORE    A       2008       NA
#10 AUS   PISAMATH   TOT   MEANSCORE    A       2009       514
#11 BEL   PISAMATH   TOT   MEANSCORE    A       2000       NA
#12 BEL   PISAMATH   TOT   MEANSCORE    A       2001       NA
#13 BEL   PISAMATH   TOT   MEANSCORE    A       2002       NA
#14 BEL   PISAMATH   TOT   MEANSCORE    A       2003       529
#15 BEL   PISAMATH   TOT   MEANSCORE    A       2004       NA

I need to impute the missing data in the TOT.1 column which contains the math scores. For that, I use the following code:

library(mice)
imp <- mice(pisa_math_tot, 436)  # 436 is (m) number of what i want to impute
fit <- with(imp, analysis)

However, I get this error:

Error in eval(expr, envir, enclos) : object 'analysis' not found

slamballais
  • 3,161
  • 3
  • 18
  • 29
Hisham
  • 35
  • 7
  • Note that in `imp <- mice(pisa_math_tot, 630)`, `630` is not the number of observations but the number of imputations you want to make (more details [here](https://www.rdocumentation.org/packages/mice/versions/2.30/topics/mice)). Now about the error, what are you trying to do? What is the object `analysis`? – nghauran Oct 21 '17 at 16:12
  • If m is number what I want to impute, then instead of 630 it will be 436. Analysis is a formula object specifying the statistical analysis to be applied to each of the m imputed datasets. – Hisham Oct 22 '17 at 15:14

0 Answers0