benbhansen-stats / propertee

Prognostic Regression Offsets with Propagation of ERrors, for Treatment Effect Estimation (IES R305D210029).
https://benbhansen-stats.github.io/propertee/
Other
2 stars 0 forks source link

Storing model data when invoking `lmitt.lm` #117

Closed jwasserman2 closed 1 year ago

jwasserman2 commented 1 year ago

When calling lmitt.lm, we evaluate the lm object's data call in eval_env. This usually won't work if someone has created a function where they pass a generic data argument to lmitt.lm:

> lmitt_wrapper <- function(form, design, model_data) {
+   return(lmitt(lm(form, data = model_data), design = design))
+ }
> y <- lmitt_wrapper(y ~ z.(des), des, simdata)
Error in eval(lm_model$call$data, envir = eval_env) :
object 'model_data' not found

It will only work if someone were to pass a the model_data argument a dataframe named model_data. I propose we use an approach similar to fallback_data_search, but instead use eval rather than get to ensure that any subsetting, rbinding, or cbinding is properly accounted for. I've linked a PR with my propsed changes.

josherrickson commented 1 year ago

As long is this passes tests I see no reason not to proceed this way, with one minor coding amendment I'll suggest in the PR itself.