residuals2 {lavaSearch2} | R Documentation |
Residuals With Small Sample Correction.
Description
Extract residuals from a latent variable model.
Similar to stats::residuals
but with small sample correction.
Usage
residuals2(object, type, format, ssc, ...)
## S3 method for class 'lvmfit'
residuals2(
object,
type = "response",
format = "wide",
ssc = lava.options()$ssc,
...
)
Arguments
object |
a |
type |
[character] the type of residual to extract:
|
format |
[character] Use |
ssc |
[character] method used to correct the small sample bias of the variance coefficients: no correction ( |
... |
additional argument passed to |
Details
When argument object is a lvmfit
object, the method first calls estimate2
and then extract the residuals.
The raw residuals are defined by observation minus the fitted value:
The studentized residuals divided the raw residuals relative to each endogenous variable by the modeled variance of the endogenous variable.
The normalized residuals multiply the raw residuals by the inverse of the square root of the modeled residual variance covariance matrix.
Value
a matrix containing the residuals relative to each sample (in rows) and each endogenous variable (in column).
See Also
estimate2
to obtain lvmfit2
objects.
Examples
#### simulate data ####
set.seed(10)
n <- 101
Y1 <- rnorm(n, mean = 0)
Y2 <- rnorm(n, mean = 0.3)
Id <- findInterval(runif(n), seq(0.1,1,0.1))
data.df <- rbind(data.frame(Y=Y1,G="1",Id = Id),
data.frame(Y=Y2,G="2",Id = Id)
)
#### latent variable models ####
library(lava)
e.lvm <- estimate(lvm(Y ~ G), data = data.df)
residuals(e.lvm)
residuals2(e.lvm)
residuals(e.lvm) - residuals2(e.lvm)