DeclareDesign / estimatr

estimatr: Fast Estimators for Design-Based Inference
https://declaredesign.org/r/estimatr
Other
131 stars 20 forks source link

bug in tidy.lh results in repeating rows for multiple linear hypotheses #296

Closed lukesonnet closed 5 years ago

lukesonnet commented 5 years ago

tidy(lh_robust(mpg ~ cyl + am, data = mtcars, linear_hypothesis = c("cyl=1", "cyl=am"))$lh) Output:

    term  estimate std.error  statistic      p.value  conf.low conf.high df outcome
1  cyl=1 -3.500958 0.3114269 -11.241666 4.349494e-12 -4.137897 -2.864018 29     mpg
2 cyl=am -5.067992 1.0643572  -4.761552 4.919824e-05 -7.244847 -2.891137 29     mpg
3  cyl=1 -3.500958 0.3114269 -11.241666 4.349494e-12 -4.137897 -2.864018 29     mpg
4 cyl=am -5.067992 1.0643572  -4.761552 4.919824e-05 -7.244847 -2.891137 29     mpg
lukesonnet commented 5 years ago

This is caused by the way we repeat outcome to accommodate multiple outcomes in multivariate regressions. I believe the solution is to just break the lh data.frame into a list and clobber the outcome to be unique(outcome) when we tidy or print an lh object.

Otherwise, we could have lh be a list instead of a data.frame, and turn it into a data.frame with tidy.lh, but it's probably too late to change that.