auto_var: Write scripts of latent variables and/or residual...

Description Usage Arguments Value Examples

View source: R/modaw.R

Description

Automatically generate the scripts of latent variables and/or residual correlations of items used for lavaan model

Usage

1
2
auto_var(variable_name, item_names = NULL, resi_cor = TRUE,
  item = NULL, data = NULL)

Arguments

variable_name

Charater. Name of the variable.

item_names

Charater or charater vector. Names of the items.

resi_cor

Logical. Whether include residual correlations.

item

Integer. The column number of items in a data frame

data

The input data frame

Value

Characters.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## item names
item_names <- c("em1.an1", "em1.an2", "em1.an3", "em2.an1", "em2.an2", "em2.an3",
                "em3.an1", "em3.an2", "em3.an3")

## get the scripts used for lavaan model by entering the item names
auto_var(variable_name = "E.A", item_names = item_names)

## creat a data frame with 9 items
df <- data.frame(
  em1.an1 = c(3, 4, 5, 1),
  em1.an2 = c(1, 2, 5, 3),
  em1.an3 = c(1, 4, 5, 3),
  em2.an1 = c(1, 2, 5, 5),
  em2.an2 = c(5, 2, 5, 5),
  em2.an3 = c(5, 1, 4, 5),
  em3.an1 = c(4, 1, 4, 1),
  em3.an2 = c(2, 1, 1, 1),
  em3.an3 = c(2, 3, 2, 1),
  stringsAsFactors = FALSE
)

## get the scripts used for lavaan model by entering the column number of the data frame
auto_var(variable_name = "E.A", item = 1:9, data = df)

LingshuHu/modaw documentation built on Oct. 30, 2019, 8:26 p.m.