Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: parameters
Title: Processing of Model Parameters
Version: 0.28.2.9
Version: 0.28.2.10
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# parameters (devel)

* fixed bug in `standardize_info(<fixest>)` that was preventing
`standardise_parameters()` from working for `fixest` models.

* `equivalence_test()` gets methods for objects from the *modelbased* package.

* Improved support for objects from package *survey*.
Expand Down
6 changes: 5 additions & 1 deletion R/standardize_info.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ standardize_info.default <- function(model,
insight::find_parameters(model, effects = "fixed", flatten = TRUE, ...)
}
types <- parameters_type(model)
# model_matrix <- as.data.frame(stats::model.matrix(model))
model_matrix <- as.data.frame(insight::get_modelmatrix(model))
model_data <- insight::get_data(model, source = "mf", verbose = FALSE)
wgts <- insight::get_weights(model, remove_na = TRUE)
Expand Down Expand Up @@ -323,9 +322,12 @@ standardize_info.default <- function(model,
if (info$is_linear) {
if (inherits(model, c("gls", "lme"))) {
response <- insight::get_response(model)
} else if (inherits(model, "fixest")) {
response <- model.matrix(model, type = "lhs")
} else {
response <- stats::model.frame(model)[[1]]
}

means <- deviations <- rep(NA_real_, length = length(names(model_matrix)))
for (i in seq_along(names(model_matrix))) {
variable <- names(model_matrix)[i]
Expand Down Expand Up @@ -367,6 +369,8 @@ standardize_info.default <- function(model,
.std_info_response_basic <- function(model, info, params, robust = FALSE, w = NULL, ...) {
if (inherits(model, c("gls", "lme"))) {
response <- insight::get_response(model)
} else if (inherits(model, "fixest")) {
response <- model.matrix(model, type = "lhs")
} else {
response <- stats::model.frame(model)[[1]]
}
Expand Down
15 changes: 7 additions & 8 deletions tests/testthat/test-standardize_parameters.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,23 +178,22 @@
m1 <- lm(Y ~ X * Z)
m2 <- lm(Y ~ X * scale(Z))
m3 <- lm(Y ~ scale(X) * Z)
m4 <- lm(Y ~ scale(X) * scale(Z))
m4 <- lm(scale(Y) ~ scale(X) + scale(Z) + scale(scale(X) * scale(Z))) # ground truth

expect_equal(
standardize_parameters(m1, method = "basic")$Std_Coefficient,
model_parameters(m4)$Coefficient,
ignore_attr = TRUE
)
expect_equal(
standardize_parameters(m2, method = "basic")$Std_Coefficient,
model_parameters(m4)$Coefficient,
ignore_attr = TRUE
)
expect_equal(

Check warning on line 193 in tests/testthat/test-standardize_parameters.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=tests/testthat/test-standardize_parameters.R,line=193,col=3,[expect_identical_linter] Use expect_identical(x, y) by default; resort to expect_equal() only when needed, e.g. when setting ignore_attr= or tolerance=.
standardize_parameters(m1, method = "basic")$Std_Coefficient,
standardize_parameters(m3, method = "basic")$Std_Coefficient,
ignore_attr = TRUE
model_parameters(m4)$Coefficient
)
# expect_equal(
# standardize_parameters(m1, method = "basic")$Std_Coefficient,
# standardize_parameters(m4, method = "basic")$Std_Coefficient
# )


# transformed resp or pred should not affect
mtcars$cyl_exp <- exp(mtcars$cyl)
Expand Down
Loading