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

ENH improve .get_data_from_model and .get_design #64

Closed jwasserman2 closed 2 years ago

josherrickson commented 2 years ago

The following still fails:

data(simdata)
des <- rct_design(z ~ uoa(cid1, cid2) + block(bid), data = simdata)
camod <- lm(y ~ x, data = simdata)
vcovDA(lmitt(y ~ x, data = simdata, weights = ate(des), offset = cov_adj(camod)))
vcovDA(lmitt(y ~ x, data = simdata, weights = ate(des), offset = cov_adj(camod, design = des)))
jwasserman2 commented 2 years ago

Good testing! These fail due to model.frame failing when called on a DirectAdjusted object. I ended up 1) adding model.frame to our growing list of functions to search in the call stack for and 2) adding the Design object to the DirectAdjusted frozen environment to accommodate cases when model.frame is called using terms(DirectAdjusted) or formula(DirectAdjusted) as an argument. I don't know of a way to access the original fitted model if someone calls terms(DirectAdjusted) or formula(DirectAdjusted), so unless you know of such a way, then accessing the Design slot doesn't work for those cases. Instead, since the model's environment is accessible from either terms or formula, we can search for the design there.

Two issues still to resolve (in next commits):

  1. vcovDA(lmitt(y ~ x, design = z ~ uoa(cid1, cid2) + block(bid), data = simdata, weights = ate(), offset = cov_adj(camod))) fails with an infinite recursion error
  2. vcovDA(lmitt(y ~ x, data = simdata, weights = ate(des), offset = cov_adj(camod))) is returning a 2x2 matrix with dimensions for the intercept and x:adopters(), but this should be a 3x3 matrix including a column for adopters() on its own (since here x is continuous). **EDIT: point # 2 is not an issue for this PR
jwasserman2 commented 2 years ago

Ok this last commit addresses point 1 mentioned above. .get_design() now searches first in the lmitt.formula frame for design, which should have been provided by the user or created from the formula provided by the user, and returns it immediately to prevent reaching a point of infinite recursion. If a Design object is found in the lmitt.formula frame it is no longer compared to other Design objects found in the call stack to ensure agreement. @josherrickson let me know if this is OK. Otherwise, this PR should be ready to merge ** EDIT: change "uniqueness" to "agreement"

jwasserman2 commented 2 years ago

I'm also going to go ahead and merge this in. It fixes a lot of versions of lmitt