Skip to content
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

method = "auto" not working for ordinal variables #260

Open
shirdekel opened this issue Sep 9, 2022 · 0 comments
Open

method = "auto" not working for ordinal variables #260

shirdekel opened this issue Sep 9, 2022 · 0 comments

Comments

@shirdekel
Copy link

I assumed that if I use method = "auto" for ordinal variables I'd get a polychoric correlation, but instead I get the following:

library(correlation)

d <- data.frame(
  x = as.ordered(sample(1:5, 20, TRUE)),
  y = as.ordered(sample(letters[1:5], 20, TRUE))
)

# Expected

correlation(d, method = "polychoric", include_factors = TRUE)
#> # Correlation Matrix (polychoric-method)
#> 
#> Parameter1 | Parameter2 |  rho |        95% CI | t(18) |     p
#> --------------------------------------------------------------
#> x          |          y | 0.10 | [-0.36, 0.52] |  0.41 | 0.688
#> 
#> p-value adjustment method: Holm (1979)
#> Observations: 20

# Weird output

correlation(d, method = "auto", include_factors = TRUE)
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> For i = 2 j = 1  A cell entry of 0 was replaced with correct =  0.5.  Check your data!
#> # Correlation Matrix (auto-method)
#> 
#> Parameter1 | Parameter2 |       rho |         95% CI |     t(18) |         p
#> ----------------------------------------------------------------------------
#> x.1        |        x.2 |     -0.38 | [-0.70,  0.08] |     -1.72 | > .999   
#> x.1        |        x.3 |     -0.38 | [-0.70,  0.08] |     -1.72 | > .999   
#> x.1        |        x.4 |     -0.38 | [-0.70,  0.08] |     -1.72 | > .999   
#> x.1        |        x.5 |     -0.27 | [-0.63,  0.20] |     -1.17 | > .999   
#> x.1        |        y.a |     -0.12 | [-0.53,  0.34] |     -0.51 | > .999   
#> x.1        |        y.b |      0.16 | [-0.30,  0.56] |      0.69 | > .999   
#> x.1        |        y.c |     -0.47 | [-0.75, -0.03] |     -2.24 | > .999   
#> x.1        |        y.d |      0.16 | [-0.30,  0.56] |      0.69 | > .999   
#> x.1        |        y.e |      0.49 | [ 0.06,  0.76] |      2.36 | > .999   
#> x.2        |        x.3 |     -0.29 | [-0.65,  0.18] |     -1.26 | > .999   
#> x.2        |        x.4 |     -0.29 | [-0.65,  0.18] |     -1.26 | > .999   
#> x.2        |        x.5 |     -0.18 | [-0.57,  0.29] |     -0.76 | > .999   
#> x.2        |        y.a |      0.82 | [ 0.60,  0.93] |      6.15 | < .001***
#> x.2        |        y.b |      0.27 | [-0.19,  0.64] |      1.20 | > .999   
#> x.2        |        y.c | -1.86e-05 | [-0.44,  0.44] | -7.90e-05 | > .999   
#> x.2        |        y.d |     -0.18 | [-0.57,  0.29] |     -0.76 | > .999   
#> x.2        |        y.e |     -0.52 | [-0.79, -0.11] |     -2.62 | 0.718    
#> x.3        |        x.4 |     -0.29 | [-0.65,  0.18] |     -1.26 | > .999   
#> x.3        |        x.5 |     -0.18 | [-0.57,  0.29] |     -0.76 | > .999   
#> x.3        |        y.a |     -0.03 | [-0.47,  0.42] |     -0.13 | > .999   
#> x.3        |        y.b |     -0.18 | [-0.57,  0.29] |     -0.76 | > .999   
#> x.3        |        y.c |      0.82 | [ 0.59,  0.93] |      6.06 | < .001***
#> x.3        |        y.d |     -0.18 | [-0.57,  0.29] |     -0.76 | > .999   
#> x.3        |        y.e |     -0.20 | [-0.59,  0.27] |     -0.86 | > .999   
#> x.4        |        x.5 |     -0.18 | [-0.57,  0.29] |     -0.76 | > .999   
#> x.4        |        y.a |     -0.03 | [-0.47,  0.42] |     -0.13 | > .999   
#> x.4        |        y.b |     -0.18 | [-0.57,  0.29] |     -0.76 | > .999   
#> x.4        |        y.c | -1.86e-05 | [-0.44,  0.44] | -7.90e-05 | > .999   
#> x.4        |        y.d |      0.75 | [ 0.46,  0.90] |      4.84 | 0.006**  
#> x.4        |        y.e |     -0.20 | [-0.59,  0.27] |     -0.86 | > .999   
#> x.5        |        y.a |      0.07 | [-0.38,  0.50] |      0.31 | > .999   
#> x.5        |        y.b |      0.41 | [-0.04,  0.72] |      1.91 | > .999   
#> x.5        |        y.c |     -0.27 | [-0.63,  0.20] |     -1.17 | > .999   
#> x.5        |        y.d |     -0.07 | [-0.49,  0.39] |     -0.28 | > .999   
#> x.5        |        y.e |      0.50 | [ 0.07,  0.77] |      2.43 | > .999   
#> y.a        |        y.b |      0.07 | [-0.38,  0.50] |      0.31 | > .999   
#> y.a        |        y.c |     -0.12 | [-0.53,  0.34] |     -0.51 | > .999   
#> y.a        |        y.d |      0.07 | [-0.38,  0.50] |      0.31 | > .999   
#> y.a        |        y.e |     -0.27 | [-0.64,  0.20] |     -1.18 | > .999   
#> y.b        |        y.c |     -0.27 | [-0.63,  0.20] |     -1.17 | > .999   
#> y.b        |        y.d |     -0.07 | [-0.49,  0.39] |     -0.28 | > .999   
#> y.b        |        y.e |     -0.42 | [-0.72,  0.03] |     -1.94 | > .999   
#> y.c        |        y.d |     -0.27 | [-0.63,  0.20] |     -1.17 | > .999   
#> y.c        |        y.e |     -0.61 | [-0.83, -0.23] |     -3.28 | 0.174    
#> y.d        |        y.e |     -0.42 | [-0.72,  0.03] |     -1.94 | > .999   
#> 
#> p-value adjustment method: Holm (1979)
#> Observations: 20

Created on 2022-09-09 by the reprex package (v2.0.1)

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.2.1 (2022-06-23)
#>  os       macOS Big Sur ... 10.16
#>  system   x86_64, darwin17.0
#>  ui       X11
#>  language (EN)
#>  collate  en_AU.UTF-8
#>  ctype    en_AU.UTF-8
#>  tz       Australia/Sydney
#>  date     2022-09-09
#>  pandoc   2.19 @ /usr/local/bin/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  bayestestR    0.12.1  2022-05-02 [1] CRAN (R 4.2.0)
#>  cli           3.3.0   2022-04-25 [1] CRAN (R 4.2.0)
#>  correlation * 0.8.2   2022-08-09 [1] CRAN (R 4.2.0)
#>  datawizard    0.5.1   2022-08-17 [1] CRAN (R 4.2.0)
#>  digest        0.6.29  2021-12-01 [1] CRAN (R 4.2.0)
#>  evaluate      0.16    2022-08-09 [1] CRAN (R 4.2.0)
#>  fansi         1.0.3   2022-03-24 [1] CRAN (R 4.2.0)
#>  fastmap       1.1.0   2021-01-25 [1] CRAN (R 4.2.0)
#>  fs            1.5.2   2021-12-08 [1] CRAN (R 4.2.0)
#>  glue          1.6.2   2022-02-24 [1] CRAN (R 4.2.0)
#>  highr         0.9     2021-04-16 [1] CRAN (R 4.2.0)
#>  htmltools     0.5.3   2022-07-18 [1] CRAN (R 4.2.0)
#>  insight       0.18.2  2022-08-10 [1] CRAN (R 4.2.0)
#>  knitr         1.39    2022-04-26 [1] CRAN (R 4.2.0)
#>  lattice       0.20-45 2021-09-22 [1] CRAN (R 4.2.1)
#>  lifecycle     1.0.1   2021-09-24 [1] CRAN (R 4.2.0)
#>  magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.2.0)
#>  mnormt        2.1.0   2022-06-07 [1] CRAN (R 4.2.0)
#>  nlme          3.1-157 2022-03-25 [1] CRAN (R 4.2.1)
#>  parameters    0.18.2  2022-08-10 [1] CRAN (R 4.2.0)
#>  pillar        1.8.1   2022-08-19 [1] CRAN (R 4.2.0)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.2.0)
#>  psych         2.2.5   2022-05-10 [1] CRAN (R 4.2.0)
#>  purrr         0.3.4   2020-04-17 [1] CRAN (R 4.2.0)
#>  R.cache       0.16.0  2022-07-21 [1] CRAN (R 4.2.0)
#>  R.methodsS3   1.8.2   2022-06-13 [1] CRAN (R 4.2.0)
#>  R.oo          1.25.0  2022-06-12 [1] CRAN (R 4.2.0)
#>  R.utils       2.12.0  2022-06-28 [1] CRAN (R 4.2.0)
#>  reprex        2.0.1   2021-08-05 [1] CRAN (R 4.2.0)
#>  rlang         1.0.4   2022-07-12 [1] CRAN (R 4.2.0)
#>  rmarkdown     2.14    2022-04-25 [1] CRAN (R 4.2.0)
#>  sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.2.0)
#>  stringi       1.7.8   2022-07-11 [1] CRAN (R 4.2.0)
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 4.2.0)
#>  styler        1.7.0   2022-03-13 [1] CRAN (R 4.2.0)
#>  tibble        3.1.8   2022-07-22 [1] CRAN (R 4.2.0)
#>  utf8          1.2.2   2021-07-24 [1] CRAN (R 4.2.0)
#>  vctrs         0.4.1   2022-04-13 [1] CRAN (R 4.2.0)
#>  withr         2.5.0   2022-03-03 [1] CRAN (R 4.2.0)
#>  xfun          0.31    2022-05-10 [1] CRAN (R 4.2.0)
#>  yaml          2.3.5   2022-02-21 [1] CRAN (R 4.2.0)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.2/Resources/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant