[R] computationally singular error with mice()

Joshua Wiley jwiley.psych at gmail.com
Sun Nov 27 01:25:23 CET 2011


Hi Fei,

On Sat, Nov 26, 2011 at 9:07 AM, Fei <fayechen0807 at hotmail.com> wrote:
> Hi Josh,
>
> Thanks for the kind reminder of posting the dataframe on. My dataframe
> contains lots of categorical variables, which seems to be problematic.  For
> instance,
>
> dob        status         edu               mrext
> 1111      married       highschool   yes, full time

Still not exactly a useable dataset, but here is a snippet of code I used:

##############################################################################
#                         Multiple Imputation Model                          #
##############################################################################

## specify the predictor matrix for the imputation
pred.matrix <- rbind(
  VFQRoleDifficulties1 = c(0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1),
  MOODVision1 =          c(1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1),
  MOODImpact1 =          c(1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1),
[snip]
  SocialFunctioning1 =   c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1),
  RoleEmotional1 =       c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1),
  MentalHealth1 =        c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0))
## set rownames to column names of the data (this is a square matrix)
colnames(pred.matrix) <- colnames(dat)

## Set the methods used to impute each variable
imp.method <- c(
  VFQRoleDifficulties1 = "pmm",
  MOODVision1 = "pmm",
  MOODImpact1 = "pmm",
[snip]
  SocialFunctioning1 = "pmm",
  RoleEmotional1 = "pmm",
  MentalHealth1 = "pmm"
)

## Create multiply imputed dataset
datimp <- mice(data = dat, m = 500, method = imp.method,
predictorMatrix = pred.matrix,
  seed = 1, print = FALSE)

Basically you can write a k x k matrix where k is the number of
variables in your dataset.  This can control what variables are used
in the imputation model for each variable (all 0s would mean no
variables).  You can also pass a k length character vector controlling
the method used for each variable.  You can also control the order
mice goes in.

Cheers,

Josh


>
> Do you know how to specify the imputation methods and the visitSquence so
> that those categorical variables are not involved in the imputation process?
> Thank you.
>
> Fei
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/computationally-singular-error-with-mice-tp4109583p4110776.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, ATS Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/



More information about the R-help mailing list