
Dataframe of correlated scales from different dataframes of scale items
Source:R/correlateScales.R
correlateScales.RdcorrelateScales() creates a dataframe of
scale items representing correlated constructs,
as one might find in a completed questionnaire.
Value
Returns a dataframe whose columns are taken from the starter dataframes and whose summated values are correlated according to a user-specified correlation matrix
Details
Correlated rating-scale items generally are summed or
averaged to create a measure of an "unobservable", or "latent", construct.
correlateScales() takes several such dataframes of rating-scale
items and rearranges their rows so that the scales are correlated according
to a predefined correlation matrix. Univariate statistics for each dataframe
of rating-scale items do not change,
but their correlations with rating-scale items in other dataframes do.
Examples
## three attitudes and a behavioural intention
n <- 32
lower <- 1
upper <- 5
### attitude #1
cor_1 <- makeCorrAlpha(items = 4, alpha = 0.90)
means_1 <- c(2.5, 2.5, 3.0, 3.5)
sds_1 <- c(0.9, 1.0, 0.9, 1.0)
Att_1 <- makeScales(
n = n, means = means_1, sds = sds_1,
lowerbound = rep(lower, 4), upperbound = rep(upper, 4),
items = 4,
cormatrix = cor_1
)
#> Variable 1 : item01 -
#> reached maximum of 1024 iterations
#> Variable 2 : item02 -
#> reached maximum of 1024 iterations
#> Variable 3 : item03 -
#> best solution in 242 iterations
#> Variable 4 : item04 -
#> reached maximum of 1024 iterations
#>
#> Arranging data to match correlations
#>
#> Successfully generated correlated variables
#>
### attitude #2
cor_2 <- makeCorrAlpha(items = 5, alpha = 0.85)
means_2 <- c(2.5, 2.5, 3.0, 3.0, 3.5)
sds_2 <- c(1.0, 1.0, 0.9, 1.0, 1.5)
Att_2 <- makeScales(
n = n, means = means_2, sds = sds_2,
lowerbound = rep(lower, 5), upperbound = rep(upper, 5),
items = 5,
cormatrix = cor_2
)
#> Variable 1 : item01 -
#> best solution in 1023 iterations
#> Variable 2 : item02 -
#> reached maximum of 1024 iterations
#> Variable 3 : item03 -
#> reached maximum of 1024 iterations
#> Variable 4 : item04 -
#> best solution in 133 iterations
#> Variable 5 : item05 -
#> reached maximum of 1024 iterations
#>
#> Arranging data to match correlations
#>
#> Successfully generated correlated variables
#>
### attitude #3
cor_3 <- makeCorrAlpha(items = 6, alpha = 0.75)
means_3 <- c(2.5, 2.5, 3.0, 3.0, 3.5, 3.5)
sds_3 <- c(1.0, 1.5, 1.0, 1.5, 1.0, 1.5)
Att_3 <- makeScales(
n = n, means = means_3, sds = sds_3,
lowerbound = rep(lower, 6), upperbound = rep(upper, 6),
items = 6,
cormatrix = cor_3
)
#> Variable 1 : item01 -
#> reached maximum of 1024 iterations
#> Variable 2 : item02 -
#> reached maximum of 1024 iterations
#> Variable 3 : item03 -
#> reached maximum of 1024 iterations
#> Variable 4 : item04 -
#> reached maximum of 1024 iterations
#> Variable 5 : item05 -
#> best solution in 259 iterations
#> Variable 6 : item06 -
#> reached maximum of 1024 iterations
#>
#> Arranging data to match correlations
#>
#> Successfully generated correlated variables
#>
### behavioural intention
intent <- lfast(n, mean = 3.0, sd = 3, lowerbound = 0, upperbound = 10) |>
data.frame()
#> reached maximum of 1024 iterations
names(intent) <- "int"
### target scale correlation matrix
scale_cors <- matrix(
c(
1.0, 0.6, 0.5, 0.3,
0.6, 1.0, 0.4, 0.2,
0.5, 0.4, 1.0, 0.1,
0.3, 0.2, 0.1, 1.0
),
nrow = 4
)
data_frames <- list("A1" = Att_1, "A2" = Att_2, "A3" = Att_3, "Int" = intent)
### apply the function
my_correlated_scales <- correlateScales(
dataframes = data_frames,
scalecors = scale_cors
)
#> scalecors is positive-definite
#>
#> New dataframe successfully created
head(my_correlated_scales)
#> A1_1 A1_2 A1_3 A1_4 A2_1 A2_2 A2_3 A2_4 A2_5 A3_1 A3_2 A3_3
#> 1 3.75 2.25 3.00 3.50 3.4 4.4 3.4 3.6 4.6 2.833333 1.000000 1.666667
#> 2 4.50 4.00 4.25 4.50 1.4 2.8 3.4 3.8 3.4 4.666667 3.833333 4.833333
#> 3 2.75 2.50 2.75 4.25 2.0 2.4 3.2 1.6 3.8 2.833333 1.666667 3.833333
#> 4 1.00 2.25 3.00 3.25 2.6 1.2 1.4 1.2 2.4 2.333333 1.000000 2.000000
#> 5 1.50 1.50 1.75 2.00 2.4 2.2 2.4 3.4 4.2 2.000000 3.500000 2.166667
#> 6 1.75 1.50 2.50 2.50 1.8 1.6 3.0 2.2 4.2 3.333333 3.833333 3.333333
#> A3_4 A3_5 A3_6 Int_1
#> 1 3.000000 2.666667 4.000000 2
#> 2 4.666667 4.666667 5.000000 0
#> 3 3.333333 4.333333 5.000000 5
#> 4 4.500000 4.166667 1.000000 0
#> 5 3.000000 3.666667 1.833333 0
#> 6 3.000000 3.833333 3.666667 6