Ex. 2 - Understanding the elements in output

Yuan-Ling Liaw and Waldir Leoncio

library(lsasim)
packageVersion("lsasim")
[1] '2.1.2'
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.

The output is a list containing the following elements: bg, c_mean, c_sd, cat_prop, cat_prop_W_p, cor_matrix, cov_matrix, family, n_W, n_X, n_obs, n_tot, sd_YXW, sd_YXZ, theta, var_W, var_YX, verbose, linear_regression.

`?`(questionnaire_gen)
set.seed(1234)
(props <- list(1, c(0.25, 1), c(0.2, 0.8, 1)))
[[1]]
[1] 1

[[2]]
[1] 0.25 1.00

[[3]]
[1] 0.2 0.8 1.0
(yw_cov <- matrix(c(1, 0.5, 0.5, 0.5, 1, 0.8, 0.5, 0.8, 1), nrow = 3))
     [,1] [,2] [,3]
[1,]  1.0  0.5  0.5
[2,]  0.5  1.0  0.8
[3,]  0.5  0.8  1.0
questionnaire_gen(n_obs = 10, cat_prop = props, cov_matrix = yw_cov, theta = TRUE, family = "gaussian",
    full_output = TRUE)
$bg
   subject      theta q1 q2
1        1 -0.8440231  2  2
2        2 -2.0198262  2  2
3        3 -0.7921984  1  1
4        4 -1.1724355  1  1
5        5 -0.5099209  2  2
6        6 -0.4202077  1  1
7        7 -0.2292551  2  3
8        8 -0.4616903  2  2
9        9 -0.8524573  1  2
10      10 -1.1829590  2  1

$c_mean
[1] 0

$c_sd
[1] 1

$cat_prop
$cat_prop[[1]]
[1] 1

$cat_prop[[2]]
[1] 0.25 1.00

$cat_prop[[3]]
[1] 0.2 0.8 1.0


$cat_prop_W_p
$cat_prop_W_p[[1]]
[1] 0.25 0.75

$cat_prop_W_p[[2]]
[1] 0.2 0.6 0.2


$cor_matrix
      theta  q1  q2
theta   1.0 0.5 0.5
q1      0.5 1.0 0.8
q2      0.5 0.8 1.0

$cov_matrix
      theta  q1  q2
theta   1.0 0.5 0.5
q1      0.5 1.0 0.8
q2      0.5 0.8 1.0

$family
[1] "gaussian"

$n_W
[1] 2

$n_X
[1] 0

$n_obs
[1] 10

$n_tot
n_vars    n_X    n_W  theta 
     3      0      2      1 

$sd_YXW
[1] 1.0000000 0.4330127 0.4330127 0.4000000 0.4898979 0.4000000

$sd_YXZ
[1] 1 1 1

$theta
[1] TRUE

$var_W
$var_W[[1]]
[1] 0.1875 0.1875

$var_W[[2]]
[1] 0.16 0.24 0.16


$var_YX
[1] 1

$verbose
[1] TRUE

$linear_regression
$linear_regression$betas
     theta       q1.2       q2.2       q2.3 
-0.8218134  0.4547365  0.4450622  1.0686187 

$linear_regression$vcov_YXW
             theta       q1.2          q2.2        q2.3
theta 1.000000e+00 0.15888829  5.551115e-17  0.13998096
q1.2  1.588883e-01 0.18750000  4.710271e-02  0.04928003
q2.2  5.551115e-17 0.04710271  2.400000e-01 -0.12000000
q2.3  1.399810e-01 0.04928003 -1.200000e-01  0.16000000