Open wbvguo opened 10 months ago
Thanks for the issue, @wbvguo!
You may find the documentation helpful here:
When the modeling was performed with na.action = "na.exclude", one should provide the original data as a second argument, at which point the augmented data will contain those rows (typically with NAs in place of the new columns).
As in:
library(broom)
df <- data.frame(
id = 1:10,
x = rnorm(10),
y = rnorm(10)
)
df$x[5] = NA
m <- lm(y~x, data = df, na.action = na.exclude)
augment(m, df)
#> # A tibble: 10 × 9
#> id x y .fitted .resid .hat .sigma .cooksd .std.resid
#> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 1 0.593 0.278 -0.480 0.758 0.269 0.629 0.321 1.32
#> 2 2 0.185 -0.639 -0.316 -0.323 0.168 0.712 0.0281 -0.527
#> 3 3 -0.830 -0.224 0.0929 -0.316 0.135 0.713 0.0200 -0.506
#> 4 4 -1.86 1.40 0.509 0.896 0.421 0.545 1.11 1.75
#> 5 5 NA -0.474 NA NA 0 0.672 NA NA
#> 6 6 -0.687 0.583 0.0355 0.547 0.121 0.686 0.0519 0.868
#> 7 7 -0.680 -0.206 0.0324 -0.238 0.120 0.719 0.00977 -0.378
#> 8 8 -1.53 -0.596 0.375 -0.971 0.294 0.552 0.614 -1.72
#> 9 9 0.605 -0.993 -0.485 -0.509 0.273 0.684 0.148 -0.887
#> 10 10 0.332 -0.219 -0.375 0.156 0.199 0.723 0.00834 0.259
Created on 2024-01-22 with reprex v2.1.0
Looks like we fail to raise an informative warning here, as is documented. Will make a note to look into this. :)
Dear
broom
maintainer,the problem
I was runnning
lm
on a dataset with NA values, and foundaugment
doesn't work withna.action = na.exclude
code
output
remove the
na.action = na.exclude
option will work. Actually, the followingz1
andz2
have the same
model
,coefficients
,residuals
components, making me really wonder how thena.exclude
andna.omit
will influenceaugment
's behaviorI'm not entirely sure if the issue we saw above originating from the
augment
function or thelm
function. I would greatly appreciate any insights or guidance you could offer on this matter. Thank you in advance for your assistance.Thanks!
sessioninfo