partialResid | R Documentation |
Extracts partial residuals from a model or psem
object for a given
x
and y
.
partialResid(formula., modelList, data = NULL)
formula. |
A formula where the |
modelList |
A list of structural equations. |
data |
A |
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
.
Returns a data.frame
of residuals of y ~ Z
called
yresids
, of x ~ Z
called xresids
.
Jon Lefcheck <lefcheckj@si.edu>
cerror
# 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(xresid, yresid)
# Use partialResid
presid <- partialResid(y ~ x1, model)
with(presid, plot(xresid, yresid)) # identical plot!
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.