[R] MITOOLS: Error in eval(expr, envir, enclos) : invalid 'envir' argument

Inman, Brant A. M.D. Inman.Brant at mayo.edu
Thu Jun 7 21:30:16 CEST 2007


R-users & helpers:

I am using Amelia, mitools and cmprsk to fit cumulative incidence curves
to multiply imputed datasets.  The error message that I get 

"Error in eval(expr, envir, enclos) : invalid 'envir' argument"

occurs when I try to fit models to the 50 imputed datasets using the
"with.imputationList" function of mitools.  The problem seems to occur
intermittently, depending on the type of model that I try to fit to the
datasets as well as the previous code that has been executed during the
R session.  I have read the previous postings for similar problems and
have tried renaming many of my objects which has not solved the problem.


What is weird is that I have not been able to reproduce the problem
using other standard survival datasets (like pbc). It therefore seems to
have something to do with my particular analysis, likely the names of my
objects.  I cannot find the source of the problem and would greatly
appreciate any help.

Brant

Below is my session information and some code demonstrating the issue
occuring with coxph.

> sessionInfo()
R version 2.5.0 (2007-04-23) 
i386-pc-mingw32 

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United 

attached base packages:
[1] "splines"   "grid"      "stats"     "graphics"  "grDevices" "utils"

[7] "datasets"  "methods"   "base"     

other attached packages:
      cmprsk      mitools       Amelia     survival    RGraphics
latticeExtra 
     "2.1-7"        "1.0"     "1.1-23"       "2.31"      "1.0-6"
"0.2-1" 
     lattice      foreign         MASS 
    "0.15-8"     "0.8-20"     "7.2-34" 


> str(utt.mi)    # My dataset
'data.frame':   168 obs. of  25 variables:
 $ age      : num  79.5 67.1 63.7 76.9 69.0 ...
 $ gender   : Factor w/ 2 levels "0","1": 1 2 2 2 1 2 2 2 2 2 ...
 $ symptoms : Factor w/ 2 levels "0","1": 1 2 1 1 2 1 2 1 1 2 ...
 $ site     : Factor w/ 3 levels "1","2","3": 1 1 2 1 2 1 1 2 1 3 ...
 $ multifoc : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 2 ...
 $ ctnm     : Factor w/ 2 levels "1","2": 1 NA 2 1 2 2 1 NA 1 2 ...
 $ prebca   : Factor w/ 2 levels "0","1": 1 1 1 1 2 1 2 1 1 1 ...
 $ precystec: Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
 $ surgery  : Factor w/ 2 levels "1","2": 1 1 2 1 2 1 1 1 1 1 ...
 $ ptnm.t   : Factor w/ 5 levels "0","1","2","3",..: 3 3 5 1 2 4 2 1 1 5
...
 $ grade    : Factor w/ 3 levels "1","2","3": 2 2 3 2 2 3 2 1 1 3 ...
 $ histol   : Factor w/ 2 levels "0","1": 2 2 2 2 2 2 2 2 2 2 ...
 $ postbca  : Factor w/ 2 levels "0","1": 2 1 2 2 2 NA 2 1 1 1 ...
 $ postcyst : Factor w/ 2 levels "0","1": 1 1 1 2 1 1 1 1 1 1 ...
 $ chemo    : Factor w/ 2 levels "0","1": 1 1 2 1 1 2 2 1 1 2 ...
 $ mets     : Factor w/ 2 levels "0","1": 1 2 2 1 2 2 2 1 1 2 ...
 $ status   : Factor w/ 4 levels "1","2","3","4": 1 3 2 1 3 3 3 1 1 3
...
 $ futime   : num  10.46  1.15  2.43  2.83  6.82 ...
 $ smk      : Factor w/ 2 levels "0","1": 2 2 2 1 2 1 2 1 2 2 ...
 $ surg.yr  : int  88 94 92 93 86 85 95 98 91 85 ...
 $ nodes    : Factor w/ 2 levels "0","1": 1 1 2 1 1 2 1 1 1 2 ...
 $ os       : num  0 1 0 0 1 1 1 0 0 1 ...
 $ css      : num  0 1 0 0 1 1 1 0 0 1 ...
 $ rfs      : num  0 1 1 0 1 1 1 0 0 1 ...
 $ comp     : num  0 1 1 0 1 1 1 0 0 1 ...

> set.seed(200)
> M <- 50 			# Number of imputations
> am.imp <- amelia(utt.mi, m=M, p2s=1, startvals=1, write.out=F,
+ idvars=c('os','css','rfs','comp'), 
+
noms=c('gender','symptoms','site','multifoc','ctnm','prebca','precystec'
,
+ 'smk','surgery','ptnm.t','nodes','grade','histol','postbca',
+ 'postcyst','chemo','mets','status'),
+ sqrts=c('futime'))
-- Imputation 1 --

 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 

<snip>

-- Imputation 50 --

 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 
21 22 23 24 25 26 

> MIset <- imputationList(am.imp[1:M])
> mifit <- with(MIset, 
+ coxph(Surv(futime, os) ~ age + symptoms + ctnm + smk))

Error in eval(expr, envir, enclos) : invalid 'envir' argument



More information about the R-help mailing list