Error in str2lang(x) : <text>:1:15: unexpected ')' in multilevel multiple imputation using miceadds

Hi,
I'm trying to perform multilevel multiple imputation using miceadds.
My dataset includes survival time and hence I calculated the Nelson-Aalen estimator using nelsonaalen (df, time, event). When I included the output in the model, I get Error in str2lang(x) : :1:15: unexpected ')' .

I was able to reproduce the error (see the code below) by using a few estimates that were obtained using nelsonaalen().

k<-data.frame(studyname=rep(c(1,2),50), t=
              rep(c(0.02298016, 0.02499735, 0.02280831,
                    0.02160165),25
                    ))
k$t[3]<-NA

predMatrix <- make.predictorMatrix(data = k)
predMatrix[,"studyname"]<--2
impMethod<-rep("2l.pmm",ncol(predMatrix))
names(impMethod)<-names(k)
mice(k, m = 1, predictorMatrix = predMatrix,maxit = 20,meth=impMethod,printFlag = T)

Would really appreciate your help.

Verion info below.
R version 4.1.2 (2021-11-01) -- "Bird Hippie"
Platform: x86_64-w64-mingw32/x64 (64-bit)
mice 3.14.0
miceadds 3.11-6

What's the motivation for this step?

library(mice)
#> 
#> Attaching package: 'mice'
#> The following object is masked from 'package:stats':
#> 
#>     filter
#> The following objects are masked from 'package:base':
#> 
#>     cbind, rbind
library(miceadds)
#> * miceadds 3.11-6 (2021-01-21 11:48:47)
k <- data.frame(studyname = rep(c(1,2),50), 
        t= rep(c(0.02298016, 0.02499735, 0.02280831, 0.02160165),25))

# without introducing NA
# set random seed
set.seed(42)
predMatrix <- make.predictorMatrix(data = k)
predMatrix[,"studyname"]<--2
impMethod<-rep("2l.pmm",ncol(predMatrix))
names(impMethod)<-names(k)
mice(k, m = 1, predictorMatrix = predMatrix,maxit = 20,meth=impMethod,printFlag = T)
#> 
#>  iter imp variable
#>   1   1
#>   2   1
#>   3   1
#>   4   1
#>   5   1
#>   6   1
#>   7   1
#>   8   1
#>   9   1
#>   10   1
#>   11   1
#>   12   1
#>   13   1
#>   14   1
#>   15   1
#>   16   1
#>   17   1
#>   18   1
#>   19   1
#>   20   1
#> Class: mids
#> Number of multiple imputations:  1 
#> Imputation methods:
#> studyname         t 
#>        ""        "" 
#> PredictorMatrix:
#>           studyname t
#> studyname         0 1
#> t                -2 0

This is to reproduce the error. The script works without NAs and my data include NA.

Color me inattentive. If I have it right, the problem lies in method being applied to both columns. Using the default works.

library(mice)
#> 
#> Attaching package: 'mice'
#> The following object is masked from 'package:stats':
#> 
#>     filter
#> The following objects are masked from 'package:base':
#> 
#>     cbind, rbind
library(miceadds)
#> * miceadds 3.11-6 (2021-01-21 11:48:47)

k <- data.frame(studyname = rep(c(1,2),50), 
                t= rep(c(0.02298016, 0.02499735, 0.02280831, 0.02160165),25))

# set random seed and use default method, because there is only one column
# to be imputed--t, not studyname also

set.seed(42)
k$t[30] <- NA
predMatrix <- make.predictorMatrix(data = k)
mice(k, m = 1, predictorMatrix = predMatrix,maxit = 20,printFlag = T)
#> 
#>  iter imp variable
#>   1   1  t
#>   2   1  t
#>   3   1  t
#>   4   1  t
#>   5   1  t
#>   6   1  t
#>   7   1  t
#>   8   1  t
#>   9   1  t
#>   10   1  t
#>   11   1  t
#>   12   1  t
#>   13   1  t
#>   14   1  t
#>   15   1  t
#>   16   1  t
#>   17   1  t
#>   18   1  t
#>   19   1  t
#>   20   1  t
#> Class: mids
#> Number of multiple imputations:  1 
#> Imputation methods:
#> studyname         t 
#>        ""     "pmm" 
#> PredictorMatrix:
#>           studyname t
#> studyname         0 1
#> t                 1 0

Thank you. But my actual data set has a level two variable (i.e. studyname) as the dataset is for individual participant data meta-analysis from multiple studies.
Thus, I would like to use multi-level imputation using "2l.pmm" accounting for clustering.
When I use "2l.pmm", "2l.2stage.norm", "2l.2stage.pmm", those for two-level impuation, the script does not work.

Just to add that the script runs without a problem if I multiply k$t by 10. It seems the error is triggered when there are small values.

I may have traced this to the {lme4} lme4() function:

formula
a two-sided linear formula object describing both the fixed-effects and random-effects part of the model, with the response on the left of a ~ operator and the terms, separated by + operators, on the right. Random-effects terms are distinguished by vertical bars (|) separating expressions for design matrices from grouping factors. Two vertical bars (||) can be used to specify multiple uncorrelated random effects for the same grouping variable. (Because of the way it is implemented, the ||-syntax works only for design matrices containing numeric (continuous) predictors; to fit models with independent categorical effects, see dummy or the lmer_alt function from the afex package.)

Thanks. I'm not sure if I understand the implication of this. Is there a way to resolve the error?

For this purpose, studygroup isn't continuous,

Thanks. But it is weird that cluster variables are usually categorical or descrite variables.

Also, interestingly, if I do k$t<-k$t*10, the code runs without a problem when the manipulation does not change the type of the variable.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.