Skip to content
Prev 278583 / 398502 Next

computationally singular error with mice()

Hi Fei,
On Sat, Nov 26, 2011 at 9:07 AM, Fei <fayechen0807 at hotmail.com> wrote:
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