Skip to content

standardize() fails in some cases #441

@etiennebacher

Description

@etiennebacher

Cf easystats/report#379

library(datawizard)

data(sleep)
d <- data_modify(sleep, group = as.integer(group) - 1L)
d_wide <- data_to_wide(
  d,
  names_from = "group",
  values_from = "extra",
  names_prefix = "group"
)

model1 <- lm(d_wide$group0 - d_wide$group1 ~ 1)
standardize(model1)
#> Warning: Using `$` in model formulas can produce unexpected results. Specify your
#>   model using the `data` argument instead.
#>   Try: group0 - group1 ~ 1,
#>   data =

#> Warning: Using `$` in model formulas can produce unexpected results. Specify your
#>   model using the `data` argument instead.
#>   Try: group0 - group1 ~ 1,
#>   data =

#> Warning: Using `$` in model formulas can produce unexpected results. Specify your
#>   model using the `data` argument instead.
#>   Try: group0 - group1 ~ 1,
#>   data =
#> 
#> Call:
#> lm(formula = d_wide$group0 - d_wide$group1 ~ 1, data = data_std)
#> 
#> Coefficients:
#> (Intercept)  
#>       -1.58

model1 <- lm(group0 - group1 ~ 1, data = d_wide)
standardize(model1)
#> Error in eval(predvars, data, env): objet 'group0' introuvable
#> Error: Unable to refit the model with standardized data.
#>   Try instead to standardize the data (standardize(data)) and refit the
#>   model manually.

Created on 2023-07-01 with reprex v2.0.2

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions