[R] effects & lme4: error since original dataframenotfoundWASeffects: error when original data frame is missing

Gerrit Eichner Gerrit.Eichner at math.uni-giessen.de
Thu Jan 18 15:58:01 CET 2018


Thanks, John,

for your hint! (Unfortunately, I was not aware of this vignette,
but I am glad that I seem to habe been on the right track.)

Indeed very helpful, in particular of course, the warning regarding
the danger of overwriting already existing objects. That danger might
be reduced by pre-checking the intended name and if neccessary
changing it (somehow ...) automatically. (Have to think about that ...)

  Best regards  --  Gerrit

---------------------------------------------------------------------
Dr. Gerrit Eichner                   Mathematical Institute, Room 212
gerrit.eichner at math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104          Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32109            http://www.uni-giessen.de/eichner
---------------------------------------------------------------------

Am 17.01.2018 um 15:55 schrieb Fox, John:
> Dear Gerrit,
> 
> This issue is discussed in a vignette in the car package (both for functions in the car and effects packages): vignette("embedding", package="car") . The solution suggested there is the essentially the one that you used.
> 
> I hope this helps,
>   John
> 
> -----------------------------
> John Fox, Professor Emeritus
> McMaster University
> Hamilton, Ontario, Canada
> Web: socialsciences.mcmaster.ca/jfox/
> 
> 
>> -----Original Message-----
>> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Gerrit
>> Eichner
>> Sent: Wednesday, January 17, 2018 9:50 AM
>> To: r-help at r-project.org
>> Subject: Re: [R] effects & lme4: error since original data frame
>> notfoundWASeffects: error when original data frame is missing
>>
>> Third "hi" in this regard and for the archives:
>>
>> I found a (maybe "dirty") workaround which at least does what I need by
>> creating a copy of the required data frame in the .GlobalEnv by means of
>> assign:
>>
>> foo <- function() {
>>     assign("X", sleepstudy, pos = 1)
>>     fm <- lmer(Reaction ~ Days + (Days | Subject), data = X)
>>     Effect("Days", fm)
>> }
>>
>>
>>    Hth  --  Gerrit
>>
>> ---------------------------------------------------------------------
>> Dr. Gerrit Eichner                   Mathematical Institute, Room 212
>> gerrit.eichner at math.uni-giessen.de   Justus-Liebig-University Giessen
>> Tel: +49-(0)641-99-32104          Arndtstr. 2, 35392 Giessen, Germany
>> Fax: +49-(0)641-99-32109            http://www.uni-giessen.de/eichner
>> ---------------------------------------------------------------------
>>
>> Am 17.01.2018 um 15:02 schrieb Gerrit Eichner:
>>> Hi, again,
>>>
>>> I have to modify my query since my first (too simple) example doesn't
>>> reflect my actual problem. Second try:
>>>
>>> When asking Effect() inside a function to compute an effect of an
>>> lmer-fit which uses a data frame local to the body of the function, as
>>> in the following example (simplifying my actual application), I get
>>> the "Error in is.data.frame(data) :
>>> object 'X' not found":
>>>
>>>   > foo <- function() {
>>> +  X <- sleepstudy
>>> +  fm <- lmer(Reaction ~ Days + (Days | Subject), data = X)
>>> +  Effect("Days", fm)
>>> + }
>>>
>>>   > foo()
>>>
>>> Error in is.data.frame(data) : object 'X' not found
>>>
>>>
>>> With lm-objects there is no problem:
>>>
>>>   > foo2 <- function() {
>>> +   X <- sleepstudy
>>> +   fm <- lm(Reaction ~ Days, data = X)
>>> +   Effect("Days", fm)
>>> + }
>>>
>>>   > foo2()
>>>
>>> ....
>>>
>>> Any idea how to work around this problem?
>>> Once again, thx in advance!
>>>
>>>    Regards  --  Gerrit
>>>
>>> PS: > sessionInfo()
>>> R version 3.4.2 (2017-09-28)
>>> Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8
>>> x64 (build 9200)
>>>
>>> Matrix products: default
>>>
>>> locale:
>>> [1]
>> LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252 [3]
>>> LC_MONETARY=German_Germany.1252 LC_NUMERIC=C [5]
>>> LC_TIME=German_Germany.1252
>>>
>>> attached base packages:
>>> [1] stats     graphics  grDevices utils     datasets  methods   base
>>>
>>> other attached packages:
>>> [1] effects_4.0-0   carData_3.0-0   lme4_1.1-14     Matrix_1.2-11
>>> car_2.1-5 [6] lattice_0.20-35
>>>
>>> loaded via a namespace (and not attached):
>>>    [1] Rcpp_0.12.13       MASS_7.3-47        grid_3.4.2
>>> MatrixModels_0.4-1
>>>    [5] nlme_3.1-131       survey_3.32-1      SparseM_1.77 minqa_1.2.4
>>>    [9] nloptr_1.0.4       splines_3.4.2      tools_3.4.2
>>> survival_2.41-3 [13] pbkrtest_0.4-7     yaml_2.1.14
>>> parallel_3.4.2 compiler_3.4.2 [17] colorspace_1.3-2   mgcv_1.8-22
>>> nnet_7.3-12 quantreg_5.33
>>>
>>> ---------------------------------------------------------------------
>>> Dr. Gerrit Eichner                   Mathematical Institute, Room 212
>>> gerrit.eichner at math.uni-giessen.de   Justus-Liebig-University Giessen
>>> Tel: +49-(0)641-99-32104          Arndtstr. 2, 35392 Giessen, Germany
>>> Fax: +49-(0)641-99-32109            http://www.uni-giessen.de/eichner
>>> ---------------------------------------------------------------------
>>>
>>> Am 17.01.2018 um 10:55 schrieb Gerrit Eichner:
>>>> Hello, everyody,
>>>>
>>>> when asking, e.g., Effect() to compute the effects of a fitted, e.g.,
>>>> linear model after having deleted the data frame from the workspace
>>>> for which the model was obtained an error is reported:
>>>>
>>>>   > myair <- airquality
>>>>   > fm <- lm(Ozone ~ Temp, data = myair)
>>>>   > rm(myair)
>>>>   > Effect("Temp", fm)
>>>> Error in eval(model$call$data, envir) : object 'myair' not found
>>>>
>>>> Has anybody a better "workaround" for this than, e.g., explicitly
>>>> saving the fitted model object fm together with its original
>>>> environment or just the data needed frame (maybe in a list like
>>>> fm.plus.origdata <- list(fm, myair = myair)) to be able to restore
>>>> the original environemt (or at least the needed opriginal data
>>>> frame) of the time when fm was created?
>>>>
>>>> Thx for any hint!
>>>>
>>>>    Regards  --  Gerrit
>>>>
>>>> ---------------------------------------------------------------------
>>>> Dr. Gerrit Eichner                   Mathematical Institute, Room 212
>>>> gerrit.eichner at math.uni-giessen.de   Justus-Liebig-University Giessen
>>>> Tel: +49-(0)641-99-32104          Arndtstr. 2, 35392 Giessen, Germany
>>>> Fax: +49-(0)641-99-32109            http://www.uni-giessen.de/eichner
>>>>
>>>> ______________________________________________
>>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>>> 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.
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> 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.
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.



More information about the R-help mailing list