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

`expand.model.frame.DA` #102

Closed josherrickson closed 1 year ago

josherrickson commented 1 year ago

@jwasserman2 I'm running into an issue where stats::expand.model.frame() isn't working as expected because lmitt() is producing a model whose terms are not found in its data= argument.

I've created a flexida:::.expand.model.frame.DA function which is basically a clone of stats::expand.model.frame() but fixes this issue.

It's not ready for primetime yet, but I pushed it onto a branch and mostly wanted your eyes on its inclusion in R/SandwichLayerVariance.R to make sure that I'm replacing stats::expand.model.frame() with flexida:::.expand.model.frame.DA() appropriate, and explicitly not replacing in cases where it's not operating on a DA object.

josherrickson commented 1 year ago

https://github.com/benbhansen-stats/flexida/commit/40572a40cfe31cafffaef9bbdc648bfbb7c92efb#diff-cbf9a6ed1b800b6d815513f707520237bccf6542567cf950a177918a25ed778e

jwasserman2 commented 1 year ago

I think I understand what you're running into. These changes make sense. I don't think we need to use it in SandwichLayerVariance.R though because we force users to have the columns we need to grab in the original dataframe. So the default expand.model.frame should suffice.

josherrickson commented 1 year ago

With the absorb branch pulled in, this is now live. I've included a test which will flag if stats::expand.model.frame() changes such that it no longer matches flexida:::expand.model.frame.DA() (sans my modifiations).