Skip to content

Commit f2f6206

Browse files
committed
fix tests
1 parent d13e1da commit f2f6206

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

R/standardize_info.R

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,13 @@ standardize_info.default <- function(model,
320320
#' @keywords internal
321321
.std_info_response_smart <- function(model, info, data, model_matrix, types, robust = FALSE, w = NULL, ...) {
322322
if (info$is_linear) {
323-
response <- insight::get_response(model)
323+
if (inherits(model, c("gls", "lme"))) {
324+
response <- insight::get_response(model)
325+
} else if (inherits(model, "fixef")) {
326+
response <- model.matrix(model, type = "lhs")
327+
} else {
328+
response <- stats::model.frame(model)[[1]]
329+
}
324330

325331
means <- deviations <- rep(NA_real_, length = length(names(model_matrix)))
326332
for (i in seq_along(names(model_matrix))) {
@@ -361,7 +367,13 @@ standardize_info.default <- function(model,
361367

362368
#' @keywords internal
363369
.std_info_response_basic <- function(model, info, params, robust = FALSE, w = NULL, ...) {
364-
response <- insight::get_response(model)
370+
if (inherits(model, c("gls", "lme"))) {
371+
response <- insight::get_response(model)
372+
} else if (inherits(model, "fixef")) {
373+
response <- model.matrix(model, type = "lhs")
374+
} else {
375+
response <- stats::model.frame(model)[[1]]
376+
}
365377

366378
if (info$is_linear) {
367379
if (robust) {

tests/testthat/test-standardize_parameters.R

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,23 +178,22 @@ test_that("standardize_parameters (with functions / interactions)", {
178178
m1 <- lm(Y ~ X * Z)
179179
m2 <- lm(Y ~ X * scale(Z))
180180
m3 <- lm(Y ~ scale(X) * Z)
181-
m4 <- lm(Y ~ scale(X) * scale(Z))
181+
m4 <- lm(scale(Y) ~ scale(X) + scale(Z) + scale(scale(X) * scale(Z))) # ground truth
182182

183183
expect_equal(
184184
standardize_parameters(m1, method = "basic")$Std_Coefficient,
185+
model_parameters(m4)$Coefficient,
186+
ignore_attr = TRUE
187+
)
188+
expect_equal(
185189
standardize_parameters(m2, method = "basic")$Std_Coefficient,
190+
model_parameters(m4)$Coefficient,
186191
ignore_attr = TRUE
187192
)
188193
expect_equal(
189-
standardize_parameters(m1, method = "basic")$Std_Coefficient,
190194
standardize_parameters(m3, method = "basic")$Std_Coefficient,
191-
ignore_attr = TRUE
195+
model_parameters(m4)$Coefficient
192196
)
193-
# expect_equal(
194-
# standardize_parameters(m1, method = "basic")$Std_Coefficient,
195-
# standardize_parameters(m4, method = "basic")$Std_Coefficient
196-
# )
197-
198197

199198
# transformed resp or pred should not affect
200199
mtcars$cyl_exp <- exp(mtcars$cyl)

0 commit comments

Comments
 (0)