Skip to content
RDocumentation: glht
  • AI Chat
  • Code
  • Report
  • if(!require('lavaSearch2')) {
        install.packages('lavaSearch2')
        library('lavaSearch2')
    }
    library(multcomp)
    
    ## Simulate data
    mSim <- lvm(c(Y1,Y2,Y3)~ beta * eta, E ~ 1)
    latent(mSim) <- "eta"
    set.seed(10)
    n <- 1e2
    
    df.data <- sim(mSim, n, latent = FALSE, p = c(beta = 1))
    
    ## Fit separate models
    ls.lvm <- list(Y1 = estimate(lvm(Y1~E), data = df.data),
                   Y2 = estimate(lvm(Y2~E), data = df.data),
                   Y3 = estimate(lvm(Y3~E), data = df.data))
    
    ## Create contrast matrix
    C <- createContrast(ls.lvm, var.test = "E")
    
    lvm.glht <- glht2(ls.lvm, linfct = C)
    summary(lvm.glht) ## adjusted
    
    summary(lvm.glht, test = univariate()) ## not adjusted