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

Test coverage #155

Closed josherrickson closed 7 months ago

josherrickson commented 8 months ago
Here are the files that do not have 100% test coverage: File Lines Code Smells Criticals Majors Minors Code Quality
R/glmrobMethods.R 90 44 0 44 0 0.00%
R/propertee_package.R 12 2 0 2 0 0.00%
R/expand.model.frame.DA.R 95 50 26 24 7 52.00%
R/cov_adj.R 114 50 44 6 207 88.00%
R/lmrob_methods.R 116 64 58 6 5 90.62%
R/get_data_from_model.R 210 89 81 8 3815 91.01%
R/SandwichLayer.R 308 121 112 9 203 92.56%
R/dtable.R 142 51 49 2 33 96.08%
R/as.lmitt.R 195 80 77 3 202 96.25%
R/DirectAdjusted.R 393 126 122 4 115 96.83%
R/get_design.R 147 67 65 2 557 97.01%
R/DesignAccessors.R 664 233 229 4 241 98.28%
R/Design.R 632 214 212 2 316 99.07%

I'll go through most of these. @adamSales Can you generate some basic tests for the glmrobMethods file? Mostly just try to hit each line of code once, as regression tests. I'm happy to place the tests into the appropriate context if you want to just write some testthat code in a temp file.

benthestatistician commented 8 months ago

Adam, this task is something we're looking to address between now and mid-May.

Josh, it strikes me that a reasonable starter regression test would be just to adapt robustbase's regression tests of their vcov calcs for poisson and/ro binomial glms, L25, L77, L84 etc in their file tests/glmrob-1.R. (They're using base R testing, so it's just checks to see that the result matches what's in the reference file.) Given that Adam has essentially just adapted their calculations to the sandwich package framework. Would you agree? Also, are there devtools functions for assessing which lines are being hit in tests, or would you recommend something else? (If Adam already knows the answer to this, it'll still be news to me.

@xinhew0708, Josh's answers will be relevant to testing design branch functions as well.

josherrickson commented 8 months ago

Coverage is checked via the covr package. If you run covr::report(file = 'coverage.html', browse = TRUE) it will show you coverage; clicking on any file will show you line-by-line coverage.

(It generates a bunch of library stuff which is properly on .gitignore and I'd rather not pollute the repo, so I don't want to just upload my version of the results.)

josherrickson commented 8 months ago

I added some real basic tests (just making sure they returned matrices). @adamSales feel free to add more.

josherrickson commented 8 months ago

Here's an updated table.

File Lines Hits Misses Partials Complexity Coverage
R/propertee_package.R 12 2 0 2 0 0.00%
R/expand.model.frame.DA.R 95 50 26 24 7 52.00%
R/cov_adj.R 114 50 44 6 207 88.00%
R/lmrob_methods.R 116 64 58 6 5 90.62%
R/get_data_from_model.R 210 89 81 8 3853 91.01%
R/SandwichLayer.R 309 121 112 9 203 92.56%
R/glmrobMethods.R 105 52 49 3 2 94.23%
R/get_design.R 147 67 65 2 572 97.01%
R/as.lmitt.R 195 80 78 2 203 97.50%
R/dtable.R 145 51 50 1 43 98.04%
R/Design.R 609 214 212 2 338 99.07%

I'm confortable with this level of coverage from my end - the rest of the uncovered lines can't/don't need to be covered. (It's primarily trailing else which can never be hit. The propertee_package.R file can't be tested (as far as I know) as it's just setting options. expand.model.frame.DA.R has a version check, so it's only ever gonna be half-covered depending on the R version.)

Leaving this open in case @adamSales wants to expand any testing, or @jwasserman2 wants to take a pass at SandwichLayer. Feel free to unassign yourselves once those are done.

jwasserman2 commented 7 months ago

Added tests to SandwichLayer and cov_adj in #166

josherrickson commented 7 months ago

Terrific. I'm gonna call this good enough!