Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Unable to compute predicted values with this model. This error can arise when insight::get_data() is unable to extract the dataset from the model object #389

Closed
zhaoliang0302 opened this issue Oct 12, 2023 · 6 comments

Comments

@zhaoliang0302
Copy link

Hi, I encountered the following error while attempting to calculate p-values for the interaction between two groups in a linear mixed-effect model using hypothesis_test.

The relevant code is provided below:

tmp
# A tibble: 2,702 x 7
       Y  YEAR   age duration_yrs SEX    PATNO Group
   <dbl> <dbl> <dbl>        <dbl> <fct>  <dbl> <fct>
 1    29     0  65.1        0.882 Male    3001 low  
 2    30     1  65.1        0.882 Male    3001 low  
 3    30     2  65.1        0.882 Male    3001 low  
 4    29     3  65.1        0.882 Male    3001 low  
 5    29     4  65.1        0.882 Male    3001 low  
 6    29     0  67.6        1.07  Female  3002 low  
 7    29     1  67.6        1.07  Female  3002 low  
 8    29     2  67.6        1.07  Female  3002 low  
 9    27     3  67.6        1.07  Female  3002 low  
10    24     4  67.6        1.07  Female  3002 low  
# i 2,692 more rows
# i Use `print(n = ...)` to see more rows
LME_model <- lmer(Y~YEAR*Group+age+duration_yrs+SEX+(1+YEAR|PATNO), tmp)
mydf <- ggpredict(LME_model, c("YEAR", "Group"))
plot(mydf)

image

hypothesis_test(mydf)
# Error: Unable to compute predicted values with this model. 
# This error can arise when `insight::get_data()` is unable to extract the dataset from the model 
# object, or when the data frame was modified since fitting the model. You can try to supply a 
# different dataset to the `newdata` argument. If this does not work, you can file a report on the 
# Github Issue Tracker: https://github.com/vincentarelbundock/marginaleffects/issues.
@strengejacke
Copy link
Owner

Do you have a reproducible example? Furthermore, have you tried to convert the tibble tmp into a real data frame (using as.data.frame())?

@zhaoliang0302
Copy link
Author

Thanks for your rapid reply! tmp data file is uploaded: https://www.dropbox.com/scl/fi/brl335xg23w1e3u6v224c/tmp.rda?rlkey=xyutctt6q5yd4yl8qoy42ihlb&dl=0

@strengejacke
Copy link
Owner

For some reason, dropbox server don't seem to work (temporarily?). Could you zip the file and add as attachment to this thread?

@zhaoliang0302
Copy link
Author

tmp.zip
Thanks a lot!

@strengejacke
Copy link
Owner

hm, can't reproduce, works for me:

library(easystats)
#> # Attaching packages: easystats 0.6.0.13
#> ✔ bayestestR  0.13.1.7     ✔ correlation 0.8.4.9000
#> ✔ datawizard  0.9.0.1      ✔ effectsize  0.8.6.1   
#> ✔ insight     0.19.5.13    ✔ modelbased  0.8.6.4   
#> ✔ performance 0.10.6       ✔ parameters  0.21.2.6  
#> ✔ report      0.5.7.11     ✔ see         0.8.0.5
library(ggeffects)
#> 
#> Attaching package: 'ggeffects'
#> The following object is masked from 'package:easystats':
#> 
#>     install_latest
library(lme4)
#> Loading required package: Matrix

load("c:/Users/mail/Desktop/tmp.rda")

LME_model <- lmer(Y ~ YEAR * Group + age + duration_yrs + SEX + (1 + YEAR | PATNO), tmp)
mydf <- ggpredict(LME_model, c("YEAR", "Group"))
plot(mydf)

hypothesis_test(mydf)
#> # Linear trend for YEAR
#> 
#> Group    | Contrast |        95% CI |     p
#> -------------------------------------------
#> low-high |    -0.10 | [-0.24, 0.04] | 0.150

Created on 2023-10-12 with reprex v2.0.2

Can you try following two steps:

  1. easystats::install_latest(force = TRUE)
  2. ggeffects::install_latest(force = TRUE)

and then retry?

@zhaoliang0302
Copy link
Author

It works after install_latest(force = TRUE). Thanks for your time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants