Learn R Programming

matie (version 1.0)

spa: Semi-Partial Association (for a set of 3 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

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

coming soon

See Also

ma

Examples

Run this code
# Example showing similar behavior of linear and non-linear 
    # semi-partial associations when the data is truly linear
    # Y is the response variable, X is the explanatory variable, and C is the control
    # k is a factor that controls how much of Y is taken from X and how much from C
    k <- 0.5
    C = rnorm(1000)
    X = rnorm(1000)
    Y = C*(1-k) + X*k + rnorm(1000)*0.1

    # if you have rgl you can plot the data
    # plot3d(X,C,Y)
    
    # compute the semi-partial association
    spa(Y,X,C)
    
    # if you have ppcor then you can compute the linear semi-partial correlation as well
    # spcor.test(Y,X,C)$estimate^2

Run the code above in your browser using DataLab