report
report copied to clipboard
report fails when model formulat built with stats::reformulate
Describe the bug
report::report fails when model is built using reformulate.
To Reproduce See the following reprex:
library(report)
model <- lm(Sepal.Length ~ Species, data = iris)
model$terms
#> Sepal.Length ~ Species
#> attr(,"variables")
#> list(Sepal.Length, Species)
#> attr(,"factors")
#> Species
#> Sepal.Length 0
#> Species 1
#> attr(,"term.labels")
#> [1] "Species"
#> attr(,"order")
#> [1] 1
#> attr(,"intercept")
#> [1] 1
#> attr(,"response")
#> [1] 1
#> attr(,".Environment")
#> <environment: R_GlobalEnv>
#> attr(,"predvars")
#> list(Sepal.Length, Species)
#> attr(,"dataClasses")
#> Sepal.Length Species
#> "numeric" "factor"
report(model)
#> We fitted a linear model (estimated using OLS) to predict Sepal.Length with
#> Species (formula: Sepal.Length ~ Species). The model explains a statistically
#> significant and substantial proportion of variance (R2 = 0.62, F(2, 147) =
#> 119.26, p < .001, adj. R2 = 0.61). The model's intercept, corresponding to
#> Species = setosa, is at 5.01 (95% CI [4.86, 5.15], t(147) = 68.76, p < .001).
#> Within this model:
#>
#> - The effect of Species [versicolor] is statistically significant and positive
#> (beta = 0.93, 95% CI [0.73, 1.13], t(147) = 9.03, p < .001; Std. beta = 1.12,
#> 95% CI [0.88, 1.37])
#> - The effect of Species [virginica] is statistically significant and positive
#> (beta = 1.58, 95% CI [1.38, 1.79], t(147) = 15.37, p < .001; Std. beta = 1.91,
#> 95% CI [1.66, 2.16])
#>
#> Standardized parameters were obtained by fitting the model on a standardized
#> version of the dataset. 95% Confidence Intervals (CIs) and p-values were
#> computed using a Wald t-distribution approximation.
x <- 'Species'
y <- 'Sepal.Length'
model <- lm(reformulate(x, response = y), data = iris)
model$terms
#> Sepal.Length ~ Species
#> attr(,"variables")
#> list(Sepal.Length, Species)
#> attr(,"factors")
#> Species
#> Sepal.Length 0
#> Species 1
#> attr(,"term.labels")
#> [1] "Species"
#> attr(,"order")
#> [1] 1
#> attr(,"intercept")
#> [1] 1
#> attr(,"response")
#> [1] 1
#> attr(,".Environment")
#> <environment: R_GlobalEnv>
#> attr(,"predvars")
#> list(Sepal.Length, Species)
#> attr(,"dataClasses")
#> Sepal.Length Species
#> "numeric" "factor"
report(model)
#> Error in reformulate(x, response = y): 'termlabels' must be a character vector of length at least one
#> 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-09-05 with reprex v2.0.2
Expected behaviour I expected a consistent output from the report function regardless of if the model formula was built using reformulate or not.
Screenshots If applicable, add screenshots to help explain your problem.
Specifications (please complete the following information):
R: sessionInfo()
R version 4.3.1 (2023-06-16)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Arch Linux
Matrix products: default
BLAS: /usr/lib/libblas.so.3.11.0
LAPACK: /usr/lib/liblapack.so.3.11.0
locale:
[1] LC_CTYPE=en_CA.UTF-8 LC_NUMERIC=C LC_TIME=en_CA.UTF-8 LC_COLLATE=en_CA.UTF-8
[5] LC_MONETARY=en_CA.UTF-8 LC_MESSAGES=en_CA.UTF-8 LC_PAPER=en_CA.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C
time zone: Canada/Atlantic
tzcode source: system (glibc)
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] report_0.5.7
loaded via a namespace (and not attached):
[1] vctrs_0.6.3 cli_3.6.1 knitr_1.43 rlang_1.1.1 xfun_0.39
[6] processx_3.8.2 targets_1.2.2 generics_0.1.3 data.table_1.14.8 glue_1.6.2
[11] backports_1.4.1 performance_0.10.4 parameters_0.21.1 ps_1.7.5 datawizard_0.8.0
[16] fansi_1.0.4 tibble_3.2.1 base64url_1.4 yaml_2.3.7 lifecycle_1.0.3
[21] insight_0.19.3 compiler_4.3.1 dplyr_1.1.2 codetools_0.2-19 igraph_1.5.0
[26] fs_1.6.2 pkgconfig_2.0.3 rstudioapi_0.14 digest_0.6.32 R6_2.5.1
[31] effectsize_0.8.5 reprex_2.0.2 tidyselect_1.2.0 utf8_1.2.3 pillar_1.9.0
[36] callr_3.7.3 magrittr_2.0.3 tools_4.3.1 withr_2.5.0 bayestestR_0.13.1