Learn R Programming

LikertMakeR (version 1.4.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 makeScales() function to generate synthetic data with the predefined alpha.

Usage

makeCorrAlpha(
  items,
  alpha,
  variance = 0.5,
  precision = 0,
  sort_cors = FALSE,
  diagnostics = FALSE
)

Value

If 'diagnostics = FALSE', a k x k correlation matrix. If 'diagnostics = TRUE', a list with components:

R

k x k correlation matrix

diagnostics

list of summary statistics

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. Caution: Larger values increase chance of a non-positive-definite matrix. 'TRUE' is faster, but produces less natural output. Default = FALSE

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)

sort_cors

(logical) If 'TRUE', sorts the correlation coefficients in the final correlation matrix. Similar to an earlier version of this function.

diagnostics

(logical) If 'TRUE', returns a list containing the correlation matrix and a diagnostics list (target/achieved alpha, average inter-item correlation, eigenvalues, PD flag, and key arguments). If 'FALSE' (default), returns the correlation matrix only.

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)


# with diagnostics
cor_matrix4 <- makeCorrAlpha(
  items = 4,
  alpha = 0.80,
  diagnostics = TRUE
)

# test output
cor_matrix4

Run the code above in your browser using DataLab