-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b8fcfc
commit 6a369e3
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# include_reference, on-the-fly factors | ||
|
||
Code | ||
print(out1, include_reference = TRUE) | ||
Output | ||
Parameter | Coefficient | SE | 95% CI | t(27) | p | ||
------------------------------------------------------------------ | ||
(Intercept) | 27.48 | 1.97 | [23.43, 31.53] | 13.92 | < .001 | ||
gear [3] | 0.00 | | | | | ||
gear [4] | 0.08 | 1.83 | [-3.68, 3.83] | 0.04 | 0.967 | ||
gear [5] | 2.39 | 2.38 | [-2.50, 7.29] | 1.00 | 0.324 | ||
am [0] | 0.00 | | | | | ||
am [1] | 4.14 | 1.81 | [ 0.42, 7.85] | 2.29 | 0.030 | ||
hp | -0.06 | 0.01 | [-0.09, -0.04] | -6.24 | < .001 | ||
Message | ||
Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed | ||
using a Wald t-distribution approximation. | ||
|
||
--- | ||
|
||
Code | ||
print(out2, include_reference = TRUE) | ||
Output | ||
Parameter | Coefficient | SE | 95% CI | t(27) | p | ||
------------------------------------------------------------------ | ||
(Intercept) | 27.48 | 1.97 | [23.43, 31.53] | 13.92 | < .001 | ||
gear [3] | 0.00 | | | | | ||
gear [4] | 0.08 | 1.83 | [-3.68, 3.83] | 0.04 | 0.967 | ||
gear [5] | 2.39 | 2.38 | [-2.50, 7.29] | 1.00 | 0.324 | ||
am [0] | 0.00 | | | | | ||
am [1] | 4.14 | 1.81 | [ 0.42, 7.85] | 2.29 | 0.030 | ||
hp | -0.06 | 0.01 | [-0.09, -0.04] | -6.24 | < .001 | ||
Message | ||
Uncertainty intervals (equal-tailed) and p-values (two-tailed) computed | ||
using a Wald t-distribution approximation. | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
test_that("include_reference, on-the-fly factors", { | ||
data(mtcars) | ||
d <- as.data.frame(mtcars) | ||
d$gear <- as.factor(d$gear) | ||
d$am <- as.factor(d$am) | ||
|
||
m1 <- lm(mpg ~ as.factor(gear) + factor(am) + hp, data = mtcars) | ||
m2 <- lm(mpg ~ gear + am + hp, data = d) | ||
|
||
out1 <- model_parameters(m1) | ||
out2 <- model_parameters(m2) | ||
|
||
expect_snapshot(print(out1, include_reference = TRUE)) | ||
expect_snapshot(print(out2, include_reference = TRUE)) | ||
|
||
out1 <- model_parameters(m1, include_reference = TRUE) | ||
out2 <- model_parameters(m2, include_reference = TRUE) | ||
|
||
expect_equal(attributes(out1)$pretty_names, attributes(out2)$pretty_names, ignore_attr = TRUE) | ||
expect_equal(out1$Coefficient, out2$Coefficient, tolerance = 1e-4) | ||
|
||
skip_if(getRversion() < "4.3.0") | ||
skip_if_not_installed("datawizard") | ||
out3 <- mtcars |> | ||
datawizard::data_modify(gear = factor(gear), am = as.factor(am)) |> | ||
lm(mpg ~ gear + am + hp, data = _) |> | ||
model_parameters(include_reference = TRUE) | ||
|
||
expect_equal(attributes(out1)$pretty_names, attributes(out3)$pretty_names, ignore_attr = TRUE) | ||
}) |