simdata_faov: Simulate Observed Binary and Ordinal Variables Using Factor...

View source: R/simdata_faov.R

simdata_faovR Documentation

Simulate Observed Binary and Ordinal Variables Using Factor Analysis with Ordinal Variables

Description

This function simulates observed binary and ordinal variables in unidimensional and multidimensional models using the common factor model (CFM) factor analysis with ordinal variables, which is also known as the categorical variable methodology, CVM.

Usage

simdata_faov(
  model,
  f_mean,
  f_cov_matrix,
  theta_matrix = NULL,
  vloadings,
  thresholds,
  N,
  R,
  seed = 123456,
  file_dir,
  file_prefix
)

Arguments

model

A model as a list object (see examples).

f_mean

A mean vector for the latent variables.

f_cov_matrix

A m x m matrix of the latent variances and covariances, where m is the total number of dimensions.

theta_matrix

An n x m matrix of latent variables, where n is the number of sample size, and m is the total number of dimensions.

vloadings

A p x 1 vector of factor loadings, where p is the total number of the observed variables. This vector must be

thresholds

An p x Cj-1 matrix of the standardized thresholds, where Cj is the total number of category responses. A category response is represented by k, where k = 1,2,...,Cj.

N

A numeric value for the sample size

R

A numberic value for the total number of replications.

seed

A seed number used to generate the population latent variables variance-covariance matrix. If a seed number is not provided, a seed number 12345 will be used as a default value. When a the latent values are supplied, the seed number is not used.

file_dir

A directory for storing the data sets.

file_prefix

A file prefix in characters or/and numbers but special characters.

Value

It generates data sets with the model specifications given. It provides also response probabilities for each data set and average response probabilities across the items and replications.

References

\insertRef

Muthen1978AUTTT

\insertRef

Muthen1984aAUTTT

\insertRef

DeMars2012AUTTT

Examples

library(AUTTT)
# example: Three-factor model
n_dim <- 3 # n. of dimensions 
mean_vec <- c(-0.1, 0, 0.1) # mean vector for each dimension
sd_vec <- c(0.95, 0.98, 1.1) # sd vector for each dimension
f_cor <- c(0.3, 0.5, 0.6) # interfactor correlation vector
# convert the cor. vector to cor.matrix
library(AUTTT)
my_cormat_input <- to_cormatrix(cor_vec = f_cor, n_dim=3)
my_covmat_input <- to_covmatrix(cor_matrix = my_cormat_input, sd_vec=sd_vec)

nvar <- 12
lambda <- runif(nitems, 0.8, 0.93) # loadings for 12 items
cat_prob2 <- c(0.04, 0.06, 0.11, 0.37, 0.42) # m. skewed prob.
temp <- TSK(n=300, res_prop = cat_prob2)

T2 <- temp$thresholds
thresholds_m <- matrix(rep(T2, nvar), 
                        nrow = nvar, 
                        ncol=length(T2),
                        byrow = TRUE)
                        
setwd("C:/Users/shh6304/Documents/My Documents/test_faov")

simdata_faov(model = list(c(1,2,3,4), c(5,6,7,8), c(9,10,11,12)),
             f_mean = mean_vec,
             f_cov_matrix = my_covmat_input,
             theta_matrix = NULL,
             vloadings = lambda,
             thresholds = thresholds_m,
             N = 300,
             R = 5,
             seed = 123456,
             file_dir = getwd(),
             file_prefix = "test1")
  
# One factor model

simdata_faov(model = list(seq(1,12)),
             f_mean = 0,
             f_cov_matrix = 0.95,
             theta_matrix = NULL,
             vloadings = lambda,
             thresholds = thresholds_m,
             N = 300,
             R = 5,
             seed = 123456,
             file_dir = getwd(),
             file_prefix = "test1")

# Binary responses
# One factor model
 
cat_prob2 <- c(0.4, 0.6) # m. skewed prob.
temp <- TSK(n=300, res_prop = cat_prob2)
T2 <- temp$thresholds
thresholds_m <- matrix(rep(T2, nvar), 
                        nrow = nvar, 
                        ncol=1,
                        byrow = TRUE)
simdata_faov(model = list(seq(1,12)),
             f_mean = 0,
             f_cov_matrix = 0.95,
             theta_matrix = NULL,
             vloadings = lambda,
             thresholds = thresholds_m,
             N = 300,
             R = 5,
             seed = 123456,
             file_dir = getwd(),
             file_prefix = "test1")

Boklauth/AUTTT documentation built on Dec. 9, 2022, 7:37 a.m.