gen_ordinal: Generate Ordinal and Binary data

Description Usage Arguments Value Note References Examples

View source: R/gen_ordinal.R

Description

Generate Multivariate Ordinal and Binary data.

Usage

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

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.

Value

A n by p data matrix.

Note

In order to allow users to enjoy the functionality of BGGM, we had to make minor changes to the function rmvord_naiv from the R package orddata \insertCiteorddataBGGM. All rights to, and credit for, the function rmvord_naiv belong to the authors of that package.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. A copy of the GNU General Public License is available online.

References

\insertAllCited

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
################################
######### 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)

BGGM documentation built on Aug. 20, 2021, 5:08 p.m.