Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

partialResid

Computing partial effects


Description

Extracts partial residuals from a model or psem object for a given x and y.

Usage

partialResid(formula., modelList, data = NULL)

Arguments

formula.

A formula where the lhs is the response and the rhs is the predictor whose partial effect is desired.

modelList

A list of structural equations.

data

A data.frame used to fit the equations.

Details

This function computes the partial residuals of y ~ x + Z in a two-step procedure to remove the variation explained by Z: (1) remove x from the equation and model y ~ Z, and (2) replace y with x and model x ~ Z.

Value

Returns a data.frame of residuals of y ~ Z called yresids, of x ~ Z called xresids.

Author(s)

Jon Lefcheck <lefcheckj@si.edu>

See Also

Examples

# Generate data
dat <- data.frame(y = rnorm(100), x1 = rnorm(100), x2 = rnorm(100))

# Build model
model <- lm(y ~ x1 + x2, dat)

# Compute partial residuals of y ~ x1
yresid <- resid(lm(y ~ x2, dat))

xresid <- resid(lm(x1 ~ x2, dat))

plot(yresid, xresid)

# Use partialResid
presid <- partialResid(y ~ x1, model)

plot(presid) # identical plot!

piecewiseSEM

Piecewise Structural Equation Modeling

v2.1.2
GPL-3
Authors
Jon Lefcheck [aut, cre], Jarrett Byrnes [aut], James Grace [aut]
Initial release
2020-12-09

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.