Skip to contents

correlateScales() creates a dataframe of scale items representing correlated constructs, as one might find in a completed questionnaire.

Usage

correlateScales(dataframes, scalecors)

Arguments

dataframes

a list of 'k' dataframes to be rearranged and combined

scalecors

target correlation matrix - should be a symmetric k*k positive-semi-definite matrix, where 'k' is the number of dataframes

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)
#> correlation values consistent with desired alpha in 1319 iterations
#> The correlation matrix is positive definite
#> 
means_1 <- c(2.5, 2.5, 3.0, 3.5)
sds_1 <- c(0.9, 1.0, 0.9, 1.0)

Att_1 <- makeItems(
  n = n, means = means_1, sds = sds_1,
  lowerbound = rep(lower, 4), upperbound = rep(upper, 4),
  cormatrix = cor_1
)
#> Variable  1
#> reached maximum of 1024 iterations
#> Variable  2
#> reached maximum of 1024 iterations
#> Variable  3
#> reached maximum of 1024 iterations
#> Variable  4
#> reached maximum of 1024 iterations
#> 
#> Arranging data to match correlations
#> 
#> Successfully generated correlated variables
#> 



### attitude #2
cor_2 <- makeCorrAlpha(items = 5, alpha = 0.85)
#> correlation values consistent with desired alpha in 12573 iterations
#> The correlation matrix is positive definite
#> 
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 <- makeItems(
  n = n, means = means_2, sds = sds_2,
  lowerbound = rep(lower, 5), upperbound = rep(upper, 5),
  cormatrix = cor_2
)
#> Variable  1
#> reached maximum of 1024 iterations
#> Variable  2
#> reached maximum of 1024 iterations
#> Variable  3
#> reached maximum of 1024 iterations
#> Variable  4
#> reached maximum of 1024 iterations
#> Variable  5
#> reached maximum of 1024 iterations
#> 
#> Arranging data to match correlations
#> 
#> Successfully generated correlated variables
#> 



### attitude #3
cor_3 <- makeCorrAlpha(items = 6, alpha = 0.75)
#> correlation values consistent with desired alpha in 13699 iterations
#> The correlation matrix is positive definite
#> 
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 <- makeItems(
  n = n, means = means_3, sds = sds_3,
  lowerbound = rep(lower, 6), upperbound = rep(upper, 6),
  cormatrix = cor_3
)
#> Variable  1
#> reached maximum of 1024 iterations
#> Variable  2
#> reached maximum of 1024 iterations
#> Variable  3
#> reached maximum of 1024 iterations
#> Variable  4
#> reached maximum of 1024 iterations
#> Variable  5
#> reached maximum of 1024 iterations
#> Variable  6
#> 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 A3_4 A3_5 A3_6
#> 1    3    3    4    4    3    3    4    3    5    1    4    2    1    3    2
#> 2    2    1    2    2    3    1    3    2    4    2    1    3    2    2    1
#> 3    3    3    3    4    2    4    4    5    5    2    2    4    4    4    4
#> 4    1    1    2    2    1    2    2    2    3    2    2    2    5    4    2
#> 5    3    2    3    3    4    3    4    4    5    3    1    3    1    4    5
#> 6    2    2    3    3    3    1    3    4    5    3    4    4    2    2    1
#>   Int_1
#> 1     2
#> 2     2
#> 3     3
#> 4     4
#> 5     1
#> 6     1