Skip to contents

Generates an array of random responses to Likert-type questions based on specified latent variables.

Usage

rlikert(size, n_items, n_levels, mean = 0, sd = 1, skew = 0, corr = 0)

Arguments

size

number of observations.

n_items

number of Likert scale items (number of questions).

n_levels

number of response categories for each item. Integer or vector of integers.

mean

means of the latent variables. Numeric or vector of numerics. Defaults to 0.

sd

standard deviations of the latent variables. Numeric or vector of numerics. Defaults to 1.

skew

marginal skewness of the latent variables. Numeric or vector of numerics. Defaults to 0.

corr

correlations between latent variables. Can be a single numeric value representing the same correlation for all pairs, or an actual correlation matrix. Defaults to 0.

Value

A matrix of random responses with dimensions size by n_items. The column names are Y1, Y2, ..., Yn where n is the number of items. Each entry in the matrix represents a Likert scale response, ranging from 1 to n_levels.

Examples

# Generate responses for a single item with 5 levels
rlikert(size = 10, n_items = 1, n_levels = 5)
#>  [1] 3 5 4 3 3 2 2 3 4 4

# Generate responses for three items with different levels and parameters
rlikert(
  size = 10, n_items = 3, n_levels = c(4, 5, 6),
  mean = c(0, -1, 0), sd = c(0.8, 1, 1), corr = 0.5
)
#>       Y1 Y2 Y3
#>  [1,]  3  1  3
#>  [2,]  2  1  3
#>  [3,]  3  4  2
#>  [4,]  2  1  2
#>  [5,]  2  2  2
#>  [6,]  3  2  2
#>  [7,]  3  4  4
#>  [8,]  2  1  2
#>  [9,]  2  2  4
#> [10,]  3  4  4

# Generate responses with a correlation matrix
corr <- matrix(c(
  1.00, -0.63, -0.39,
  -0.63, 1.00, 0.41,
  -0.39, 0.41, 1.00
), nrow = 3)
data <- rlikert(
  size = 1000, n_items = 3, n_levels = c(4, 5, 6),
  mean = c(0, -1, 0), sd = c(0.8, 1, 1), corr = corr
)