Ex. 2 - Understanding the elements in output"

library(knitr)
options(width = 90, tidy = TRUE, warning = FALSE, message = FALSE)
opts_chunk$set(comment = "", warning = FALSE, message = FALSE,
               echo = TRUE, tidy = TRUE)
library(lsasim)
packageVersion("lsasim")
questionnaire_gen(n_obs, cat_prop = NULL, n_vars = NULL, n_X = NULL, n_W = NULL,
                  cor_matrix = NULL, cov_matrix = NULL,
                  c_mean = NULL, c_sd = NULL,
                  theta = FALSE, family = NULL,
                  full_output = FALSE, verbose = TRUE)

By default, the function returns a data.frame object where the first column ("subject") is a $1, \ldots, n$ ordered list of the $n$ observations and the other columns correspond to the questionnaire answers. If theta = TRUE, the first column after "subject" will be the latent variable theta; in any case, the continuous variables always come before the categorical ones.

If the logical argument full_output is TRUE, output will be a list containing the questionnaire data as well as several objects that might be of interest for further analysis of the data, listed below:


We generate one continuous and two ordinal covariates. We specify the covariance matrix between the numeric and ordinal variables. The data is generated from a multivariate normal distribution. And we set the logical argument full_output = TRUE.

set.seed(1234)
(props <- list(1, c(.25, 1), c(.2, .8, 1)))
(yw_cov <- matrix(c(1, .5, .5, .5, 1, .8, .5, .8, 1), nrow = 3))
bg <- questionnaire_gen(n_obs = 10, cat_prop = props, cov_matrix = yw_cov, theta = TRUE,
                  family = "gaussian", full_output = TRUE)
names(bg)

The output is a list containing the following elements: r names(bg).

?questionnaire_gen
set.seed(1234)
(props <- list(1, c(.25, 1), c(.2, .8, 1)))
(yw_cov <- matrix(c(1, .5, .5, .5, 1, .8, .5, .8, 1), nrow = 3))
questionnaire_gen(n_obs = 10, cat_prop = props, cov_matrix = yw_cov, theta = TRUE,
                  family = "gaussian", full_output = TRUE)


Try the lsasim package in your browser

Any scripts or data that you put into this service are public.

lsasim documentation built on Aug. 22, 2023, 5:09 p.m.