-
Notifications
You must be signed in to change notification settings - Fork 8
Description
This is a good first contribution requiring a small change to the R code, that could be made by following the R Contribution Workflow in the R Dev Container and then creating a patch to report back on Bugzilla. (You will need to setup the container and build R in the container before following the workflow).
As described in Bug 16256 the "constant" attribute is not returned by predict(type ="terms") when the na.action is set to "na.exclude".
The default na.action is "na.omit", which removes the missing values and returns the expected "constant" attribute:
y <- rnorm(10)
x <- 1:10
x[3] <- NA
m <- lm(y~x)
predict(m,type="terms")
#> x
#> 1 -0.083554048
#> 2 -0.066065991
#> 4 -0.031089878
#> 5 -0.013601822
#> 6 0.003886235
#> 7 0.021374291
#> 8 0.038862348
#> 9 0.056350404
#> 10 0.073838461
#> attr(,"constant")
#> [1] 0.09991503When we change to na.action="na.exclude", the predicted terms are padded with NAs where there are missing values in the predictors and the "constant" attribute is lost:
m1 <- update(m,na.action="na.exclude")
predict(m1,type="terms")
#> x
#> 1 -0.083554048
#> 2 -0.066065991
#> 3 NA
#> 4 -0.031089878
#> 5 -0.013601822
#> 6 0.003886235
#> 7 0.021374291
#> 8 0.038862348
#> 9 0.056350404
#> 10 0.073838461The underlying function is stats:::naresid.exclude() and this needs fixing to keep the "constant" attribute. @elinw identifies L157 as the place where the attribute is dropped.
Metadata
Metadata
Labels
Type
Projects
Status