Skip to content

feature request: supporting semi-partial correlations #204

Open
@IndrajeetPatil

Description

@IndrajeetPatil
library(ppcor)
#> Loading required package: MASS
library(correlation)

y.data <- data.frame(
  hl=c(7,15,19,15,21,22,57,15,20,18),
  disp=c(0.000,0.964,0.000,0.000,0.921,0.000,0.000,1.006,0.000,1.011),
  deg=c(9,2,3,4,1,3,1,3,6,1),
  BC=c(1.78e-02,1.05e-06,1.37e-05,7.18e-03,0.00e+00,0.00e+00,0.00e+00
       ,4.48e-03,2.10e-06,0.00e+00)
)

# partial correlation
pcor(y.data)$estimate
#>              hl       disp        deg        BC
#> hl    1.0000000 -0.6720863 -0.6161163 0.1148459
#> disp -0.6720863  1.0000000 -0.7215522 0.2855420
#> deg  -0.6161163 -0.7215522  1.0000000 0.6940953
#> BC    0.1148459  0.2855420  0.6940953 1.0000000
correlation(y.data, partial = TRUE)
#> # Correlation Matrix (pearson-method)
#> 
#> Parameter1 | Parameter2 |     r |         95% CI |  t(8) |     p
#> ----------------------------------------------------------------
#> hl         |       disp | -0.67 | [-0.91, -0.07] | -2.57 | 0.133
#> hl         |        deg | -0.62 | [-0.90,  0.02] | -2.21 | 0.174
#> hl         |         BC |  0.11 | [-0.55,  0.69] |  0.33 | 0.848
#> disp       |        deg | -0.72 | [-0.93, -0.17] | -2.95 | 0.111
#> disp       |         BC |  0.29 | [-0.42,  0.78] |  0.84 | 0.848
#> deg        |         BC |  0.69 | [ 0.11,  0.92] |  2.73 | 0.130
#> 
#> p-value adjustment method: Holm (1979)
#> Observations: 10

# semi-partial (part) correlation
spcor(y.data)$estimate
#>              hl       disp        deg         BC
#> hl    1.0000000 -0.5791734 -0.4991364 0.07377194
#> disp -0.5505041  1.0000000 -0.6320921 0.18071040
#> deg  -0.3180603 -0.4237587  1.0000000 0.39204867
#> BC    0.0669124  0.1724434  0.5580398 1.00000000
correlation(y.data, partial = "semi")
#> Error in cor_test(data, x = x, y = y, ci = ci, method = method, bayesian = bayesian, : Semi-partial correlations are not supported yet. Get in touch if you want to contribute.

Created on 2021-07-23 by the reprex package (v2.0.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement 💥Implemented features can be improved or revised

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions