-
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow export_table()
to split to more than 3 tables
#952
Conversation
I think that would be better. One other thing I wonder—could we repeat the model label columns on each line so that output with many models are able to be read easily on subsequent rows? |
This PR is not fully working yet. See this example (from https://easystats.github.io/parameters/articles/model_parameters_print.html#splitting-wide-tables-into-multiple-table-parts): library(parameters)
data(iris)
lm1 <- lm(Sepal.Length ~ Species, data = iris)
lm2 <- lm(Sepal.Length ~ Species + Petal.Length, data = iris)
lm3 <- lm(Sepal.Length ~ Species * Petal.Length, data = iris)
lm4 <- lm(Sepal.Length ~ Species * Petal.Length + Petal.Width, data = iris)
tab <- compare_parameters(lm1, lm2, lm3, lm4)
print(tab, table_width = 80) The first column should be repeated for each table. Current PRlibrary(parameters)
data(iris)
lm1 <- lm(Sepal.Length ~ Species, data = iris)
lm2 <- lm(Sepal.Length ~ Species + Petal.Length, data = iris)
lm3 <- lm(Sepal.Length ~ Species * Petal.Length, data = iris)
lm4 <- lm(Sepal.Length ~ Species * Petal.Length + Petal.Width, data = iris)
tab <- compare_parameters(lm1, lm2, lm3, lm4)
print(tab, table_width = 80)
#> Parameter | lm1 | lm2
#> ------------------------------------------------------------------------------
#> (Intercept) | 5.01 (4.86, 5.15) | 3.68 ( 3.47, 3.89)
#> Species [versicolor] | 0.93 (0.73, 1.13) | -1.60 (-1.98, -1.22)
#> Species [virginica] | 1.58 (1.38, 1.79) | -2.12 (-2.66, -1.58)
#> Petal Length | | 0.90 ( 0.78, 1.03)
#> Species [versicolor] × Petal Length | |
#> Species [virginica] × Petal Length | |
#> Petal Width | |
#> ------------------------------------------------------------------------------
#> Observations | 150 | 150
#>
#> lm3 | lm4
#> -------------------------------------------
#> 4.21 ( 3.41, 5.02) | 4.21 ( 3.41, 5.02)
#> -1.81 (-2.99, -0.62) | -1.80 (-2.99, -0.62)
#> -3.15 (-4.41, -1.90) | -3.19 (-4.50, -1.88)
#> 0.54 ( 0.00, 1.09) | 0.54 (-0.02, 1.09)
#> 0.29 (-0.30, 0.87) | 0.28 (-0.30, 0.87)
#> 0.45 (-0.12, 1.03) | 0.45 (-0.12, 1.03)
#> | 0.03 (-0.28, 0.34)
#> -------------------------------------------
#> 150 | 150 Created on 2024-10-30 with reprex v2.1.1 Desiredlibrary(parameters)
data(iris)
lm1 <- lm(Sepal.Length ~ Species, data = iris)
lm2 <- lm(Sepal.Length ~ Species + Petal.Length, data = iris)
lm3 <- lm(Sepal.Length ~ Species * Petal.Length, data = iris)
lm4 <- lm(Sepal.Length ~ Species * Petal.Length + Petal.Width, data = iris)
tab <- compare_parameters(lm1, lm2, lm3, lm4)
print(tab, table_width = 80)
#> Parameter | lm1 | lm2
#> ------------------------------------------------------------------------------
#> (Intercept) | 5.01 (4.86, 5.15) | 3.68 ( 3.47, 3.89)
#> Species [versicolor] | 0.93 (0.73, 1.13) | -1.60 (-1.98, -1.22)
#> Species [virginica] | 1.58 (1.38, 1.79) | -2.12 (-2.66, -1.58)
#> Petal Length | | 0.90 ( 0.78, 1.03)
#> Species [versicolor] × Petal Length | |
#> Species [virginica] × Petal Length | |
#> Petal Width | |
#> ------------------------------------------------------------------------------
#> Observations | 150 | 150
#>
#> Parameter | lm3 | lm4
#> ---------------------------------------------------------------------------------
#> (Intercept) | 4.21 ( 3.41, 5.02) | 4.21 ( 3.41, 5.02)
#> Species [versicolor] | -1.81 (-2.99, -0.62) | -1.80 (-2.99, -0.62)
#> Species [virginica] | -3.15 (-4.41, -1.90) | -3.19 (-4.50, -1.88)
#> Petal Length | 0.54 ( 0.00, 1.09) | 0.54 (-0.02, 1.09)
#> Species [versicolor] × Petal Length | 0.29 (-0.30, 0.87) | 0.28 (-0.30, 0.87)
#> Species [virginica] × Petal Length | 0.45 (-0.12, 1.03) | 0.45 (-0.12, 1.03)
#> Petal Width | | 0.03 (-0.28, 0.34)
#> ---------------------------------------------------------------------------------
#> Observations | 150 | 150 Created on 2024-10-30 with reprex v2.1.1 |
Was this working before? |
Yes |
See this code snippet from the original code: # copy first column, and all columns that did not fit into the first line
# into the second table matrix
if (i > 2 && i < ncol(final)) {
final2 <- final[, c(1, i:ncol(final))]
final <- final[, 1:(i - 1)]
} |
Fixed data(iris)
lm1 <- lm(Sepal.Length ~ Species, data = iris)
lm2 <- lm(Sepal.Length ~ Species + Petal.Length, data = iris)
lm3 <- lm(Sepal.Length ~ Species * Petal.Length, data = iris)
lm6 <- lm5 <- lm4 <- lm(Sepal.Length ~ Species * Petal.Length + Petal.Width, data = iris)
tab <- parameters::compare_parameters(lm1, lm2, lm3, lm4, lm5, lm6)
print(tab, table_width = 80)
#> Parameter | lm1 | lm2
#> ------------------------------------------------------------------------------
#> (Intercept) | 5.01 (4.86, 5.15) | 3.68 ( 3.47, 3.89)
#> Species (versicolor) | 0.93 (0.73, 1.13) | -1.60 (-1.98, -1.22)
#> Species (virginica) | 1.58 (1.38, 1.79) | -2.12 (-2.66, -1.58)
#> Petal Length | | 0.90 ( 0.78, 1.03)
#> Species (versicolor) × Petal Length | |
#> Species (virginica) × Petal Length | |
#> Petal Width | |
#> ------------------------------------------------------------------------------
#> Observations | 150 | 150
#>
#> Parameter | lm3
#> ----------------------------------------------------------
#> (Intercept) | 4.21 ( 3.41, 5.02)
#> Species (versicolor) | -1.81 (-2.99, -0.62)
#> Species (virginica) | -3.15 (-4.41, -1.90)
#> Petal Length | 0.54 ( 0.00, 1.09)
#> Species (versicolor) × Petal Length | 0.29 (-0.30, 0.87)
#> Species (virginica) × Petal Length | 0.45 (-0.12, 1.03)
#> Petal Width |
#> ----------------------------------------------------------
#> Observations | 150
#>
#> Parameter | lm4
#> ----------------------------------------------------------
#> (Intercept) | 4.21 ( 3.41, 5.02)
#> Species (versicolor) | -1.80 (-2.99, -0.62)
#> Species (virginica) | -3.19 (-4.50, -1.88)
#> Petal Length | 0.54 (-0.02, 1.09)
#> Species (versicolor) × Petal Length | 0.28 (-0.30, 0.87)
#> Species (virginica) × Petal Length | 0.45 (-0.12, 1.03)
#> Petal Width | 0.03 (-0.28, 0.34)
#> ----------------------------------------------------------
#> Observations | 150
#>
#> Parameter | lm5 | lm6
#> ---------------------------------------------------------------------------------
#> (Intercept) | 4.21 ( 3.41, 5.02) | 4.21 ( 3.41, 5.02)
#> Species (versicolor) | -1.80 (-2.99, -0.62) | -1.80 (-2.99, -0.62)
#> Species (virginica) | -3.19 (-4.50, -1.88) | -3.19 (-4.50, -1.88)
#> Petal Length | 0.54 (-0.02, 1.09) | 0.54 (-0.02, 1.09)
#> Species (versicolor) × Petal Length | 0.28 (-0.30, 0.87) | 0.28 (-0.30, 0.87)
#> Species (virginica) × Petal Length | 0.45 (-0.12, 1.03) | 0.45 (-0.12, 1.03)
#> Petal Width | 0.03 (-0.28, 0.34) | 0.03 (-0.28, 0.34)
#> ---------------------------------------------------------------------------------
#> Observations | 150 | 150 Created on 2024-10-30 with reprex v2.1.1 library(performance)
data(HolzingerSwineford1939, package = "lavaan")
structure <- " visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9 "
model1 <- lavaan::cfa(structure, data = HolzingerSwineford1939)
model2 <- lavaan::cfa(structure, data = HolzingerSwineford1939)
compare_performance(model1, model2) |> print(table_width = 50)
#> When comparing models, please note that probably not all models were fit
#> from same data.
#> # Comparison of Model Performance Indices
#>
#> Name | Model | Chi2(24) | p (Chi2)
#> -------------------------------------
#> model1 | lavaan | 85.306 | < .001
#> model2 | lavaan | 85.306 | < .001
#>
#> Name | Baseline(36) | p (Baseline) | GFI
#> --------------------------------------------
#> model1 | 918.852 | < .001 | 0.943
#> model2 | 918.852 | < .001 | 0.943
#>
#> Name | AGFI | NFI | NNFI | CFI | RMSEA
#> ----------------------------------------------
#> model1 | 0.894 | 0.907 | 0.896 | 0.931 | 0.092
#> model2 | 0.894 | 0.907 | 0.896 | 0.931 | 0.092
#>
#> Name | RMSEA CI | p (RMSEA) | RMR | SRMR
#> -------------------------------------------------
#> model1 | [0.07, 0.11] | < .001 | 0.082 | 0.065
#> model2 | [0.07, 0.11] | < .001 | 0.082 | 0.065
#>
#> Name | RFI | PNFI | IFI | RNI
#> --------------------------------------
#> model1 | 0.861 | 0.605 | 0.931 | 0.931
#> model2 | 0.861 | 0.605 | 0.931 | 0.931
#>
#> Name | Loglikelihood | AIC (weights)
#> ---------------------------------------
#> model1 | -3737.745 | 7517.5 (0.500)
#> model2 | -3737.745 | 7517.5 (0.500)
#>
#> Name | BIC (weights) | BIC_adjusted
#> --------------------------------------
#> model1 | 7595.3 (0.500) | 7528.739
#> model2 | 7595.3 (0.500) | 7528.739 Created on 2024-10-30 with reprex v2.1.1 |
I added some tests. Can be merged when all tests pass. |
How about setting "auto" to be the default... ;) |
This reverts commit ced0fbf.
Let's change to |
Alright, let's do it - we can see that everything is okay in Merging! |
It might be better if we have a global option for this, since looking at the various codes it might be difficult to pass option(easystats.table_width = 80)
# In the function
if (is.numeric(table_width)) {
line_width <- table_width
} else {
line_width <- getOption("easystats.table_width", default = getOption("width"))
} |
test with changes introduced in easystats/insight#952
test with changes introduced in easystats/insight#952
test with changes introduced in easystats/insight#952
test with changes introduced in easystats/insight#952
test with changes introduced in easystats/insight#952
test with changes introduced in easystats/insight#952
test with changes introduced in easystats/insight#952
test with changes introduced in easystats/insight#952
Closes #951
Originally posted by @strengejacke in #951 (comment)
The current implementation will never make a split that leaves a single column table.
Created on 2024-10-30 with reprex v2.1.1
So I think it's safe to set
table_width = "auto"
as the default. WDYT?