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 1 forks source link

vcov_tee internal alignment problem for some SandwichLayer's with NAs #194

Open benthestatistician opened 1 week ago

benthestatistician commented 1 week ago

The following example seems to defeat .get_a21()'s internal logic for handling covariance models with NAs.

data(STARdata)
STARdata$studentID <- rownames(STARdata)

y0hat_read <- lm(readk ~ gender + ethnicity + lunchk +
                     ladderk + experiencek + tethnicityk,
                 data = STARdata, subset = stark !="small")

STARspec <- rct_spec(stark ~ unit_of_assignment(studentID),
                     data = STARdata)

ate_read <- lmitt(readk ~ 1, STARspec, STARdata,
                  dichotomy= stark =="small" ~., 
                  offset = cov_adj(y0hat_read, newdata = STARdata),
                  weights = "ate")
vcov(ate_read)
#>             (Intercept) stark.
#> (Intercept)      0.0421 0.0159
#> stark.           0.0159 0.6526
#> attr(,"type")
#> [1] "CR0"
#> Warning message:
#> In damod_mm[msk, x$qr$pivot[1L:x$rank], drop = FALSE] * w :
#>   longer object length is not a multiple of shorter object length

Going into the .get_a21() call using debug(), I find

Browse[1]> sum(msk)
[1] 5684
Browse[1]> length(w)
[1] 5229

whereas these two should have matched. (This affects the examples we give in the cov_adj() man page.)

jwasserman2 commented 6 days ago

Thanks for catching this. I'll create a PR with a fix