spa: Semi-partial association (computes association while...

Description Usage Arguments Details Value Note Author(s) References See Also Examples

Description

Computes the semi-partial association between a response variable and an explanatory variable, after controlling for a control variable.

Usage

1
spa(Y,X,C)

Arguments

Y

the response variable, a vector or column from a dataset

X

the explanatory variable, a vector or column from a dataset

C

the control variable, a vector or column from a dataset

Details

A semi-partial association (possibly nonlinear) is computed via:

ma(cbind(C,X,Y))$A - ma(cbind(C,Y))$A .

Inspired by the linear semi-partial correlation given by:

spcor.test(Y,X,C)

from the ppcor package.

Value

Returns a real number in the range [0,1].

Note

The parameters Y, X and C must be vectors of the same length.

Author(s)

Ben Murrell, Dan Murrell & Hugh Murrell.

References

Discovering general multidimensional associations, http://arxiv.org/abs/1303.1828

See Also

ma

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
    # When the association between Y and X is entirely explained by C
    C <- rnorm(1000)
    X <- C+rnorm(1000)*0.5
    Y <- C+rnorm(1000)*0.5
    # See the relationship without controlling for C
    ma(cbind(X,Y))$A
    # See the relationship with C as a covariate (should be close to 0)
    spa(Y,X,C)
    # if you have ppcor then you can verify that 
    # the linear semi-partial correlation is similar, 
    # as these associations are all linear
    # spcor.test(Y,X,C)$estimate^2
    #
    # When the association between Y and X is only partially explained by C
    C <- rnorm(1000)
    X <- C+rnorm(1000)*0.5
    Y <- X+rnorm(1000)*0.5
    # See the relationship without controlling for C
    ma(cbind(X,Y))$A
    # See the relationship with C as a covariate 
    # (should be lower than the uncontrolled one, but not as low as 0)
    spa(Y,X,C)
    # if you have ppcor then you can verify that 
    # the linear semi-partial correlation is similar, 
    # as these associations are all linear
    # spcor.test(Y,X,C)$estimate^2
    #
    #   
    # if you have rgl you can plot the data
    # library(rgl)
    # plot3d(X,C,Y)

matie documentation built on May 2, 2019, 3:52 a.m.