`model_parameters`: Add variables names for `chisq.test` objects
rempsyc opened this issue · 0 comments
rempsyc commented
Working on easystats/report#309 and experiencing the continuous joy of htest
objects.
For example, model_parameters
on a cor.test
object will provide the names of the variables:
x <- cor.test(mtcars$mpg, mtcars$drat)
parameters::model_parameters(x)
#> Pearson's product-moment correlation
#>
#> Parameter1 | Parameter2 | r | 95% CI | t(30) | p
#> ---------------------------------------------------------------
#> mtcars$mpg | mtcars$drat | 0.68 | [0.44, 0.83] | 5.10 | < .001
#>
#> Alternative hypothesis: true correlation is not equal to 0
Which report
then relies on to report the test. But model_parameters
does not report the variable names for chisq.test
objects:
m <- as.table(rbind(c(762, 327, 468), c(484, 239, 477)))
dimnames(m) <- list(gender = c("F", "M"), party = c("Democrat", "Independent", "Republican"))
x <- chisq.test(m)
parameters::model_parameters(x)
#> Pearson's Chi-squared test
#>
#> Chi2(2) | p
#> ----------------
#> 30.07 | < .001
Yet the variable names seem available:
attributes(x$observed)
#> $dim
#> [1] 2 3
#>
#> $dimnames
#> $dimnames$gender
#> [1] "F" "M"
#>
#> $dimnames$party
#> [1] "Democrat" "Independent" "Republican"
#>
#>
#> $class
#> [1] "table"
Fixing this would allow me to fix the current bug with chisq.test
objects in report
.
report::report(x)
#> Error in UseMethod("interpret"): no applicable method for 'interpret' applied to an object of class "NULL"
Created on 2023-08-27 with reprex v2.0.2