Last data update: 2014.03.03

R: Generate measurement model
generateMeasurementModelR Documentation

Generate measurement model

Description

This function automatically generates lavaan syntax for the measurement model for a call to effectLite. It is currently also used in the shiny interface.

Usage

generateMeasurementModel(names, indicators, ncells, model = NULL)

Arguments

names

A vector of character strings with names of latent variables.

indicators

A list of vectors of character strings to specify indicators of latent variables (see example).

ncells

Number of groups/cells.

model

A vector of character strings of the same length as names. It is used to specify the type of measurement model for each of the latent variables. Each element can be one of c("default","parallel","tau-equi","tau-cong") indicating whether a parallel, essentially tau-equivalent, or tau-congeneric measurement model is used. If "default", the function tries to guess a reasonable measurement model: Congeneric for latent variables with three or more indicators, essentially tau-equivalent for latent variables with less than three indicators and for latent variables with cross-loadings (e.g., method factors), and parallel for single-indicator latent variables. If NULL, "default" is assumed for all latent variables.

Examples

## Example with three latent variables
names <- c("eta", "xi1", "xi2")
indicators <- list("eta" = c("y1","y2","y3"), 
                   "xi1" = c("z1","z2"),
                   "xi2" = c("z12","z22","z32","z42"))
ncells = 6
model = c("parallel","tau-equi","tau-cong")
cat(generateMeasurementModel(names, indicators, ncells, model))

## Example with method factor
names <- c("eta", "xi", "mf")
indicators <- list("eta" = c("y12","y22"), 
                   "xi" = c("y11","y21"),
                   "mf" = c("y12","y22"))
ncells = 2
cat(generateMeasurementModel(names, indicators, ncells))

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(EffectLiteR)
Loading required package: lavaan
This is lavaan 0.5-20
lavaan is BETA software! Please report any bugs.
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/EffectLiteR/generateMeasurementModel.Rd_%03d_medium.png", width=480, height=480)
> ### Name: generateMeasurementModel
> ### Title: Generate measurement model
> ### Aliases: generateMeasurementModel
> 
> ### ** Examples
> 
> ## Example with three latent variables
> names <- c("eta", "xi1", "xi2")
> indicators <- list("eta" = c("y1","y2","y3"), 
+                    "xi1" = c("z1","z2"),
+                    "xi2" = c("z12","z22","z32","z42"))
> ncells = 6
> model = c("parallel","tau-equi","tau-cong")
> cat(generateMeasurementModel(names, indicators, ncells, model))
eta =~ c(1,1,1,1,1,1)*y1
eta =~ c(1,1,1,1,1,1)*y2
eta =~ c(1,1,1,1,1,1)*y3
xi1 =~ c(1,1,1,1,1,1)*z1
xi1 =~ c(1,1,1,1,1,1)*z2
xi2 =~ c(1,1,1,1,1,1)*z12
xi2 =~ c(la123,la123,la123,la123,la123,la123)*z22
xi2 =~ c(la133,la133,la133,la133,la133,la133)*z32
xi2 =~ c(la143,la143,la143,la143,la143,la143)*z42
y1 ~ c(0,0,0,0,0,0)*1
y2 ~ c(0,0,0,0,0,0)*1
y3 ~ c(0,0,0,0,0,0)*1
z1 ~ c(0,0,0,0,0,0)*1
z2 ~ c(la022,la022,la022,la022,la022,la022)*1
z12 ~ c(0,0,0,0,0,0)*1
z22 ~ c(la023,la023,la023,la023,la023,la023)*1
z32 ~ c(la033,la033,la033,la033,la033,la033)*1
z42 ~ c(la043,la043,la043,la043,la043,la043)*1> 
> ## Example with method factor
> names <- c("eta", "xi", "mf")
> indicators <- list("eta" = c("y12","y22"), 
+                    "xi" = c("y11","y21"),
+                    "mf" = c("y12","y22"))
> ncells = 2
> cat(generateMeasurementModel(names, indicators, ncells))
eta =~ c(1,1)*y12
eta =~ c(1,1)*y22
xi =~ c(1,1)*y11
xi =~ c(1,1)*y21
mf =~ c(1,1)*y12
mf =~ c(1,1)*y22
y12 ~ c(0,0)*1
y22 ~ c(0,0)*1
y11 ~ c(0,0)*1
y21 ~ c(0,0)*1> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>