Learn R Programming

lavaSearch2 (version 1.5.6)

estfun: Extract Empirical Estimating Functions (lvmfit Object)

Description

Extract the empirical estimating functions of a lvmfit object. This function is for internal use but need to be public to enable its use by multcomp::glht.

Usage

# S3 method for lvmfit
estfun(x, ...)

# S3 method for gls estfun(x, ...)

# S3 method for lme estfun(x, ...)

Arguments

x

an lvmfit object.

...

arguments passed to methods.

Details

This function enables to use the glht function with lvmfit object. Otherwise when calling multcomp:::vcov.mmm then sandwich::sandwich and then sandwich::meat, sandwich::meat will complain that estfun is not defined for lvmfit objects.

Examples

Run this code
library(multcomp)

#### generative model ####
mSim <- lvm(X ~ Age + 0.5*Treatment,
            Y ~ Gender + 0.25*Treatment,
            c(Z1,Z2,Z3) ~ eta, eta ~ 0.75*treatment,
            Age[40:5]~1)
latent(mSim) <- ~eta
categorical(mSim, labels = c("placebo","SSRI")) <- ~Treatment
categorical(mSim, labels = c("male","female")) <- ~Gender

#### simulate data ####
n <- 5e1
set.seed(10)
df.data <- lava::sim(mSim, n = n, latent = FALSE)

#### fit separate models ####
lmX <- lm(X ~ Age + Treatment, data = df.data)
lvmY <- estimate(lvm(Y ~ Gender + Treatment), data = df.data)
lvmZ <- estimate(lvm(c(Z1,Z2,Z3) ~ eta, eta ~ Treatment), 
                 data = df.data)

#### create mmm object #### 
e.mmm <- mmm(X = lmX, Y = lvmY, Z = lvmZ)

#### create contrast matrix ####
resC <- createContrast(e.mmm, var.test = "Treatment", add.variance = FALSE)

#### adjust for multiple comparisons ####
e.glht <- glht(e.mmm, linfct = resC$mlf)
summary(e.glht)

Run the code above in your browser using DataLab