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