Closed edvinsyk closed 6 months ago
Yes, the predict()
method from panelr is a bit tricky, as it either requires a panel_data
object, or a data.frame that already did all the transformations that is done internally in wbm()
.
I post this code example for me as reminder.
library(panelr)
library(lme4)
library(data.table)
set.seed(1)
dt <- setDT(datasets::ChickWeight)
dt[, x := runif(.N, 0, 10), by = Chick]
dt <- dt[complete.cases(dt), Diet := factor(Diet)]
pss <- panel_data(dt, id = Chick, wave = Time)
m1 <- wbm(weight ~ x | Diet, data = pss)
datagrid <- insight::get_datagrid(m1, at = "x", range = "grid", length = 5)
datagrid
#> x weight Diet Chick Time
#> 1 -5.412990e+00 121.8183 1 18 10.71799
#> 2 -2.706495e+00 121.8183 1 18 10.71799
#> 3 -2.540409e-17 121.8183 1 18 10.71799
#> 4 2.706495e+00 121.8183 1 18 10.71799
#> 5 5.412990e+00 121.8183 1 18 10.71799
predict(m1, newdata = datagrid)
#> Error in `is.data.frame()`:
#> ! Can't subset columns that don't exist.
#> ✖ Columns `Diet2`, `Diet3`, and `Diet4` don't exist.
Created on 2022-08-21 by the reprex package (v2.0.1)
maybe @jacob-long has also ideas how to address this?
I've been playing around with different
panelr::wbm
models.I keep getting a number of different errors with both
ggeffect (mostly Can't compute marginal effects, 'effects::Effect()' returned an error."
and
ggpredict (Error in complete.cases(data[[variable]]) : no input has determined the number of cases)
I've included a small reproducible example using the chick weight dataset (and some output).