openpharma / mmrm

Mixed Models for Repeated Measures (MMRM) in R.
https://openpharma.github.io/mmrm/
Other
135 stars 23 forks source link

`predict()` should not require response variable to be present in `newdata` #461

Closed danielinteractive closed 2 months ago

danielinteractive commented 3 months ago

Reprex:

library("mmrm")

fit <- mmrm(
  formula = FEV1 ~ RACE + SEX + ARMCD * AVISIT + us(AVISIT | USUBJID),
  data = fev_data
)

predict(fit, subset(fev_data, select = - FEV1))

fails with:

Error in eval(predvars, data, env) : object 'FEV1' not found

because h_mmrm_tmb_data() is invoked and this uses the full_formula which includes the response variable from the fit.

Reported originally in https://github.com/vincentarelbundock/marginaleffects/pull/1000#issuecomment-2282352569

clarkliming commented 2 months ago

as by default we are conducting the "conditional prediction", not the "unconditional prediction", so the response is always required by default.

danielinteractive commented 2 months ago

Thanks @clarkliming , I still think that this is a bug to the user. It should in that case just default to "unconditional prediction"?