Learn R Programming

lavaSearch2 (version 1.2.0)

conditionalMoment: Prepare the Computation of score2

Description

Compute partial derivatives regarding to the mean and the variance, and compute the design matrices.

Usage

conditionalMoment(object, ...)

# S3 method for lm conditionalMoment(object, name.endogenous, ...)

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

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

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

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

Arguments

object, x

a latent variable model.

...

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

name.endogenous

[character vector, optional] name of the endogenous variables

data

[data.frame] data set.

formula

[formula] two-sided linear formula.

param, p

[numeric vector] the fitted coefficients.

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.

second.order

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

cluster

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

n.cluster

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

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.

n.endogenous

[integer >0] the number of outcomes.

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 {
conditionalMoment <- lavaSearch2:::conditionalMoment

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, 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, 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