View source: R/makeCorrAlpha.R
| makeCorrAlpha | R Documentation |
Generate a Positive-Definite Correlation Matrix for a target Cronbach's alpha.
makeCorrAlpha(
items,
alpha,
variance = 0.1,
alpha_noise = 0,
diagnostics = FALSE
)
items |
Integer. Number of items (>= 2). |
alpha |
Numeric. Target Cronbach's alpha (0 < alpha < 1). |
variance |
Numeric. Controls heterogeneity of item loadings in the underlying one-factor model. Larger values produce greater dispersion among item loadings, which results in a wider spread of inter-item correlations while preserving the requested Cronbach's alpha. Typical guidance:
For most applied psychometric scales (k < 20), values between
|
alpha_noise |
Numeric. Controls random variation in the target Cronbach's alpha before the correlation matrix is constructed. When When Internally, noise is added on the Fisher z-transformed scale to ensure the resulting alpha remains within valid bounds (0, 1). Typical guidance:
Larger values increase the spread of achieved alpha across runs. |
diagnostics |
Logical. If |
Constructs a correlation matrix with a specified number of items and target Cronbach's alpha using a constructive one-factor model.
Such a correlation matrix can be applied to the makeScales()
function to generate synthetic data with the predefined alpha.
The algorithm directly builds a positive-definite correlation matrix by solving for item loadings that reproduce the desired average inter-item correlation implied by alpha. Unlike earlier versions of this function, this method guarantees positive definiteness by construction, without post-hoc repair.
The function computes the average inter-item correlation implied by the requested alpha and solves for a one-factor loading structure that reproduces this value. A small adaptive reduction in dispersion may be applied when necessary to ensure a valid positive-definite solution.
The constructive generator assumes a single common factor structure, consistent with typical psychometric scale construction.
If diagnostics = FALSE, a positive-definite correlation matrix.
If diagnostics = TRUE, a list containing:
R: the correlation matrix
diagnostics: list including achieved alpha,
minimum eigenvalue, and internal variance used
# Example 1
# define parameters
items <- 4
alpha <- 0.85
# apply function
set.seed(42)
cor_matrix <- makeCorrAlpha(
items = items,
alpha = alpha
)
# test function output
print(cor_matrix) |> round(3)
alpha(cor_matrix)
eigenvalues(cor_matrix, 1)
# Example 2
# higher alpha, more items, more variability
cor_matrix2 <- makeCorrAlpha(
items = 8,
alpha = 0.95,
variance = 0.10
)
# test output
cor_matrix2 |> round(2)
alpha(cor_matrix2) |> round(3)
eigenvalues(cor_matrix2, 1) |> round(3)
# Example 3
# large random variation around alpha
cor_matrix3 <- makeCorrAlpha(
items = 6,
alpha = 0.85,
alpha_noise = 0.10
)
# test output
cor_matrix3 |> round(2)
alpha(cor_matrix3) |> round(3)
eigenvalues(cor_matrix3, 1) |> round(3)
# Example 4
# with diagnostics
cor_matrix4 <- makeCorrAlpha(
items = 4,
alpha = 0.80,
diagnostics = TRUE
)
# test output
cor_matrix4
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.