Learn R Programming

BGGM (version 2.1.5)

gen_ordinal: Generate Ordinal and Binary data

Description

Generate Multivariate Ordinal and Binary data.

Usage

gen_ordinal(n, p, levels = 2, cor_mat, empirical = FALSE)

Value

A n by p data matrix.

Arguments

n

Number of observations (n).

p

Number of variables (p).

levels

Number of categories (defaults to 2; binary data).

cor_mat

A p by p matrix including the true correlation structure.

empirical

Logical. If true, cor_mat specifies the empirical not population covariance matrix.

References

Examples

Run this code
################################
######### example 1 ############
################################

main <-  ptsd_cor1[1:5,1:5]
p <- ncol(main)

pcors <- -(cov2cor(solve(main)) -diag(p))
diag(pcors) <- 1
pcors <- ifelse(abs(pcors) < 0.05, 0, pcors)

inv <-  -pcors
diag(inv) <- 1
cors <- cov2cor( solve(inv))

# example data
Y <- BGGM::gen_ordinal(n = 500, p = 5,
                       levels = 2,
                       cor_mat = cors,
                       empirical = FALSE)



################################
######### example 2 ############
################################
# empirical = TRUE

Y <-  gen_ordinal(n = 500,
                  p = 16,
                  levels = 5,
                  cor_mat = ptsd_cor1,
                  empirical = TRUE)

Run the code above in your browser using DataLab