## Example 1: four correlated items (questions)
### define parameters
n <- 16
dfMeans <- c(2.5, 3.0, 3.0, 3.5)
dfSds <- c(1.0, 1.0, 1.5, 0.75)
lowerbound <- rep(1, 4)
upperbound <- rep(5, 4)
corMat <- matrix(
c(
1.00, 0.30, 0.40, 0.60,
0.30, 1.00, 0.50, 0.70,
0.40, 0.50, 1.00, 0.80,
0.60, 0.70, 0.80, 1.00
),
nrow = 4, ncol = 4
)
scale_names <- c("Q1", "Q2", "Q3", "Q4")
rownames(corMat) <- scale_names
colnames(corMat) <- scale_names
### apply function
df1 <- makeScales(
n = n, means = dfMeans, sds = dfSds,
lowerbound = lowerbound, upperbound = upperbound, cormatrix = corMat
)
### test function
str(df1)
#### means
apply(df1, 2, mean) |> round(3)
#### standard deviations
apply(df1, 2, sd) |> round(3)
#### correlations
cor(df1) |> round(3)
## Example 2: five correlated Likert scales
### a study on employee engagement and organizational climate:
# Job Satisfaction (JS)
# Organizational Commitment (OC)
# Perceived Supervisor Support (PSS)
# Work Engagement (WE)
# Turnover Intention (TI) (reverse-related to others).
### define parameters
n <- 128
dfMeans <- c(3.8, 3.6, 3.7, 3.9, 2.2)
dfSds <- c(0.7, 0.8, 0.7, 0.6, 0.9)
lowerbound <- rep(1, 5)
upperbound <- rep(5, 5)
items <- c(4, 4, 3, 3, 3)
corMat <- matrix(
c(
1.00, 0.72, 0.58, 0.65, -0.55,
0.72, 1.00, 0.54, 0.60, -0.60,
0.58, 0.54, 1.00, 0.57, -0.45,
0.65, 0.60, 0.57, 1.00, -0.50,
-0.55, -0.60, -0.45, -0.50, 1.00
),
nrow = 5, ncol = 5
)
scale_names <- c("JS", "OC", "PSS", "WE", "TI")
rownames(corMat) <- scale_names
colnames(corMat) <- scale_names
### apply function
df2 <- makeScales(
n = n, means = dfMeans, sds = dfSds,
lowerbound = lowerbound, upperbound = upperbound,
items = items, cormatrix = corMat
)
### test function
str(df2)
#### means
apply(df2, 2, mean) |> round(3)
#### standard deviations
apply(df2, 2, sd) |> round(3)
#### correlations
cor(df2) |> round(3)
Run the code above in your browser using DataLab