Factors don't always work as intended
mattansb opened this issue · 0 comments
mattansb commented
library(correlation)
#> Warning: package 'correlation' was built under R version 4.2.3
data("mtcars")
mtcars$cyl <- factor(mtcars$cyl)
correlation(mtcars,
select = c("mpg", "cyl"),
include_factors = TRUE)
#> # Correlation Matrix (pearson-method)
#>
#> Parameter1 | Parameter2 | r | 95% CI | t(30) | p
#> --------------------------------------------------------------------
#> mpg | cyl.4 | 0.80 | [ 0.63, 0.90] | 7.35 | < .001***
#> mpg | cyl.6 | -0.03 | [-0.38, 0.32] | -0.17 | 0.866
#> mpg | cyl.8 | -0.74 | [-0.87, -0.53] | -6.06 | < .001***
#> cyl.4 | cyl.6 | -0.38 | [-0.65, -0.04] | -2.27 | 0.061
#> cyl.4 | cyl.8 | -0.64 | [-0.81, -0.37] | -4.54 | < .001***
#> cyl.6 | cyl.8 | -0.47 | [-0.70, -0.14] | -2.89 | 0.021*
#>
#> p-value adjustment method: Holm (1979)
#> Observations: 32
Fails
correlation(mtcars,
select = c("mpg"),
select2 = c("cyl"),
include_factors = TRUE)
#> Warning: The table is empty, no rows left to print.
#> Can't export table to
#> text
#> , data frame is empty.
cyl
is in Parameter1
not in Parameter2
:
correlation(mtcars,
select = c("mpg"),
select2 = c("cyl", "am"),
include_factors = TRUE)
#> # Correlation Matrix (pearson-method)
#>
#> Parameter1 | Parameter2 | r | 95% CI | t(30) | p
#> ------------------------------------------------------------------
#> mpg | am | 0.60 | [ 0.32, 0.78] | 4.11 | 0.001**
#> cyl.4 | am | 0.47 | [ 0.15, 0.71] | 2.94 | 0.019*
#> cyl.6 | am | 0.02 | [-0.33, 0.37] | 0.13 | 0.896
#> cyl.8 | am | -0.47 | [-0.71, -0.15] | -2.94 | 0.019*
#>
#> p-value adjustment method: Holm (1979)
#> Observations: 32
Created on 2023-07-09 with reprex v2.0.2