Learn R Programming

matie (version 1.2)

spa: Semi-partial association (computes association while controlling for variables)

Description

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

Usage

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

Value

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

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.

References

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

See Also

ma

Examples

Run this code
    # 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)

Run the code above in your browser using DataLab