Learn R Programming

lavaSearch2 (version 1.4)

conditionalMoment: Prepare the Computation of score2

Description

Compute the conditional mean and variance, and their first and second derivative regarding the model parameters.

Usage

conditionalMoment(object, ...)

# S3 method for lm conditionalMoment(object, data, param, name.endogenous, first.order, second.order, ...)

# S3 method for gls conditionalMoment(object, data, formula, param, attr.param, ref.group, first.order, second.order, index.Omega, vec.OmegaMat, cluster, n.cluster, name.endogenous, n.endogenous, ...)

# S3 method for lme conditionalMoment(object, attr.param, ...)

# S3 method for lvm conditionalMoment(object, data, first.order, second.order, name.endogenous, name.latent, ...)

# S3 method for lvmfit conditionalMoment(object, data, param, first.order, second.order, usefit, ...)

Arguments

object, x

a latent variable model.

...

[internal] only used by the generic method or by the <- methods.

data

[data.frame] data set.

param, p

[numeric vector] the fitted coefficients.

name.endogenous

[character vector, optional] name of the endogenous variables

second.order

[logical] should the terms relative to the third derivative of the likelihood be be pre-computed?

formula

[formula] two-sided linear formula.

attr.param

[character vector] the type of each coefficient (e.g. mean or variance coefficient).

ref.group

[character vector] the levels of the variable defining the variance component in a generic covariance matrix.

cluster

[integer vector] the grouping variable relative to which the observations are iid.

n.cluster

[integer >0] the number of i.i.d. observations.

n.endogenous

[integer >0] the number of outcomes.

name.latent

[character vector, optional] name of the latent variables

usefit, value

[logical] If TRUE the coefficients estimated by the model are used to pre-compute quantities. Only for lvmfit objects.

Details

For lvmfit objects, there are two levels of pre-computation:

  • a basic one that do no involve the model coefficient (conditionalMoment.lvm).

  • an advanced one that require the model coefficients (conditionalMoment.lvmfit).

Examples

Run this code
# NOT RUN {
m <- lvm(Y1~eta,Y2~eta,Y3~eta)
latent(m) <- ~eta

d <- lava::sim(m,1e2)
e <- estimate(m, d)

## basic pre-computation
res1 <- conditionalMoment(e, data = d,
                         first.order = FALSE, second.order = FALSE,
                         name.endogenous = endogenous(e),
                         name.latent = latent(e), usefit = FALSE)
res1$skeleton$Sigma

## full pre-computation
res2 <- conditionalMoment(e, param = coef(e), data = d,
                         first.order = FALSE, second.order = FALSE,
                         name.endogenous = endogenous(e),
                         name.latent = latent(e), usefit = TRUE
)
res2$value$Sigma

# }

Run the code above in your browser using DataLab