Learn R Programming

LikertMakeR (version 1.0.0)

makeCorrAlpha: Correlation matrix from Cronbach's Alpha

Description

makeCorrAlpha() generates a random correlation matrix of given dimensions and predefined Cronbach's Alpha.

Such a correlation matrix can be applied to the makeItems() function to generate synthetic data with the predefined alpha.

Usage

makeCorrAlpha(items, alpha, variance = 0.5, precision = 0)

Value

a correlation matrix

Arguments

items

(positive, int) matrix dimensions: number of rows & columns to generate

alpha

(real) target Cronbach's Alpha (usually positive, must be between about -0.3 and +1)

variance

(positive, real) Default = 0.5. User-provided standard deviation of values sampled from a normally-distributed log transformation.

precision

(positive, real) Default = 0. User-defined value ranging from '0' to '3' to add some random variation around the target Cronbach's Alpha. '0' gives an exact alpha (to two decimal places)

Examples

Run this code

# define parameters
items <- 4
alpha <- 0.85
variance <- 0.5

# apply function
set.seed(42)
cor_matrix <- makeCorrAlpha(items = items, alpha = alpha, variance = variance)

# test function output
print(cor_matrix)
alpha(cor_matrix)
eigenvalues(cor_matrix, 1)

# higher alpha, more items
cor_matrix2 <- makeCorrAlpha(items = 8, alpha = 0.95)

# test output
cor_matrix2 |> round(2)
alpha(cor_matrix2) |> round(3)
eigenvalues(cor_matrix2, 1) |> round(3)


# large random variation around alpha
set.seed(42)
cor_matrix3 <- makeCorrAlpha(items = 6, alpha = 0.85, precision = 2)

# test output
cor_matrix3 |> round(2)
alpha(cor_matrix3) |> round(3)
eigenvalues(cor_matrix3, 1) |> round(3)

Run the code above in your browser using DataLab