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().
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.
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.)