-
-
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.
include_reference = TRUE
doesn't work in combination with `as.facto…
…r()` (#957) * `include_reference = TRUE` doesn't work in combination with `as.factor()` Fixes #956 * desc, news * add tests * lintr * update test * comment non working test * update snapshots * update snapshot * skip test * like that?
- Loading branch information
1 parent
043b3ff
commit 00b5ec8
Showing
8 changed files
with
164 additions
and
16 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
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
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
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
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
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
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,66 @@ | ||
# include_reference, on-the-fly factors | ||
|
||
Code | ||
print(out1) | ||
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) | ||
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_md(out, engine = "tt") | ||
Output | ||
+--------------+----------------------+----------------------+ | ||
| Parameter | m1 | m2 | | ||
+==============+======================+======================+ | ||
| (Intercept) | 27.48 (23.43, 31.53) | 27.48 (23.43, 31.53) | | ||
+--------------+----------------------+----------------------+ | ||
| gear (3) | 0.00 | 0.00 | | ||
+--------------+----------------------+----------------------+ | ||
| gear (4) | 0.08 (-3.68, 3.83) | 0.08 (-3.68, 3.83) | | ||
+--------------+----------------------+----------------------+ | ||
| gear (5) | 2.39 (-2.50, 7.29) | 2.39 (-2.50, 7.29) | | ||
+--------------+----------------------+----------------------+ | ||
| am (0) | 0.00 | 0.00 | | ||
+--------------+----------------------+----------------------+ | ||
| am (1) | 4.14 (0.42, 7.85) | 4.14 (0.42, 7.85) | | ||
+--------------+----------------------+----------------------+ | ||
| hp | -0.06 (-0.09, -0.04) | -0.06 (-0.09, -0.04) | | ||
+--------------+----------------------+----------------------+ | ||
| | | | | ||
+--------------+----------------------+----------------------+ | ||
| Observations | 32 | 32 | | ||
+--------------+----------------------+----------------------+ | ||
|
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,44 @@ | ||
skip_if_not_installed("tinytable") | ||
|
||
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, include_reference = TRUE) | ||
out2 <- model_parameters(m2, include_reference = TRUE) | ||
|
||
expect_snapshot(print(out1)) | ||
expect_snapshot(print(out2)) | ||
|
||
expect_equal(attributes(out1)$pretty_names, attributes(out2)$pretty_names, ignore_attr = TRUE) | ||
expect_equal(out1$Coefficient, out2$Coefficient, tolerance = 1e-4) | ||
|
||
out <- compare_parameters(m1, m2, include_reference = TRUE) | ||
expect_snapshot(print_md(out, engine = "tt")) | ||
}) | ||
|
||
skip_if(getRversion() < "4.3.3") | ||
skip_if_not_installed("datawizard") | ||
|
||
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, include_reference = TRUE) | ||
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) | ||
}) |