Learn R Programming

lavaSearch2 (version 1.2.0)

residuals2: Extract Corrected Residuals

Description

Extract correct residuals from a gaussian linear model.

Usage

residuals2(object, ...)

# S3 method for lm2 residuals2(object, param = NULL, data = NULL, ...)

# S3 method for gls2 residuals2(object, param = NULL, data = NULL, ...)

# S3 method for lme2 residuals2(object, param = NULL, data = NULL, ...)

# S3 method for lvmfit2 residuals2(object, param = NULL, data = NULL, ...)

Arguments

object

a lm2, gls2, lme2, or lvmfit2 object.

...

arguments to be passed to sCorrect.

param

[optional] the fitted parameters.

data

[optional] the data set.

Value

a matrix containing the residuals relative to each sample (in rows) and each endogenous variable (in column).

Details

If argument p or data is not null, then the small sample size correction is recomputed to correct the residuals.

See Also

sCorrect to obtain lm2, gls2, lme2, or lvmfit2 objects.

Examples

Run this code
# NOT RUN {
## simulate data
set.seed(10)
m <- lvm(Y1~eta,Y2~eta,Y3~eta)
latent(m) <- ~eta
d <- sim(m,20, latent = FALSE)

## standard linear model
e.lm <- lm(Y1~Y2, data = d)
sCorrect(e.lm) <- TRUE

sigma(e.lm)^2
mean(residuals(e.lm)^2)
mean(residuals2(e.lm)^2)

## latent variable model
e.lvm <- estimate(m, data = d)
sCorrect(e.lvm) <- TRUE
mean(residuals2(e.lvm)^2)

# }

Run the code above in your browser using DataLab