Fix yeojohnson lambda estimate ignoring missing values#28
Merged
Conversation
estimate_yeojohnson_lambda computed n with length(x) before dropping NAs, so the count of "observations" included missing values. That inflated n in the log-likelihood, shifting the optimized lambda. Appending NAs to a vector therefore changed the estimated lambda. Compute n after removing missing values so the log-likelihood uses the number of nonmissing observations. Add a regression test asserting the estimated lambda is unchanged when NAs are appended.
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.
Problem
estimate_yeojohnson_lambda()computed the observation count withn <- length(x)before dropping missing values, sonincluded theNAs. That inflatednfeeds the log-likelihood thatoptimize()maximizes:Because the inflated n reweights the first term, the optimized lambda shifts. The practical symptom: appending a few NAs to a vector changed the estimated lambda for the otherwise-identical data.
Fix
Moving
n <- length(x)to after dropping the missing values fixes the issue.Added a regression test as well.
Updated the version to 1.9.3 to reflect the bug fix.