fix(otis): cluster-robust SE with empty cluster levels + bump to 0.9.6#9
Merged
Conversation
.otis_cluster_se computed sum(grp^2) where grp = tapply(scores, cluster, sum).
When `cluster` is a factor carrying levels absent from a subset (e.g. per-year
analysis of an individual-clustered panel), tapply emits NA for the empty
clusters, so the sum became NA -> NA SE -> downstream `if (se > 0)` errored
("missing value where TRUE/FALSE needed"). Add na.rm = TRUE: empty clusters
contribute nothing, so drop them. Verified -- OTIS per-year clustered IRM now
returns finite cluster-robust SEs matching the published values. Regression
test added. Version unchanged (0.9.9).
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Vansh Singh Ruhela (rootcoder007) <vsruhela@proton.me>
Bump DESCRIPTION 0.9.5.12 -> 0.9.6 to match the already-open "rmorie 0.9.6 (in development)" NEWS section, and bring the src/ User-Agent literals + the SIU parser_version macro into lockstep (AGENTS.md requires the C++ UA to track DESCRIPTION). Ships with the cluster-robust SE empty-levels bugfix. Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Vansh Singh Ruhela (rootcoder007) <vsruhela@proton.me>
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment Thanks for integrating Codecov - We've got you covered ☂️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
.otis_cluster_se()computedsum(grp^2)wheregrp = tapply(scores, cluster, sum). When theclusterfactor carries levels absent from a subset (e.g. per-year analysis of an individual-clustered panel),tapply()emitsNAfor the empty clusters →sumbecomesNA→NASE → downstreamif (se > 0)errors with "missing value where TRUE/FALSE needed". This brokemorie_otis_irm_dml()on every by-year clustered run (pooled worked).Fix
One line:
sum(grp^2, na.rm = TRUE)— empty clusters contribute nothing, so drop them.Verification (live OTIS public data)
All 3 by-year clustered IRM runs now return finite cluster-robust SEs matching the published values:
Regression test added (
test-otis-cluster-se.R): an unused factor level must not change the SE.Version
DESCRIPTION 0.9.5.12 → 0.9.6 (matches the already-open "0.9.6 (in development)" NEWS section), with
src/UA literals + SIUparser_versionbumped in lockstep.0.9.6 > 0.9.5.12(forward bump, no downgrade).Isolated off
main— none of the in-flight 0.9.9 ecosystem-connect work is included.