Read in Excel File with Task Load Index (TLX) Data

Read in the Excel file and change column names for easier analysis. Create a Team Size measure.

tlx_df <- read_excel("D:/Documents/R_Working_Directory/TLX Data Analysis/TLI Data(working).xlsx")
colnames(tlx_df)[colnames(tlx_df)=="Number"] <- "Team"
tlx_df <- tlx_df |> group_by(Team, Scenario) |> 
  mutate(team_size = n_distinct(LN)) |>  
  ungroup()
tlx_df$Scenario <- factor(tlx_df$Scenario)

Correlation Matrix with the variables for individual participants

Create an individual correlation matrix displaying values for each Task Load Index factor.

tlx_df_corr <- tlx_df |> select(Performance, Effort, Frustration, MD, TD, PD)
cor_matrix <- cor(tlx_df_corr, use = "complete.obs")
new_labels <- c("Performance", "Effort", "Frustration", "Mental Demand", "Temporal Demand", "Physical Demand")
colnames(cor_matrix) <- new_labels
rownames(cor_matrix) <- new_labels
corrplot(cor_matrix, method = "color", type = "upper", 
         addCoef.col = "black", # Add correlation coefficients to plot
         tl.col = "black", tl.srt = 45, # Rotate x-axis labels for readability
         title = "Correlation Matrix of Individual Measures",
         mar = c(0,0,2,0)) 

Create Team Performance, Frustration, Mental Demand, Effort, Physical Demand, and Temporal Demand Measures

These factors are weighted by team size.

tlx_df <- tlx_df %>%
  group_by(Team, Scenario) %>%
  mutate(team_Performance = round(mean(Performance),2),
         team_Frustration = round(mean(Frustration),2),
         team_MD = round(mean(MD),2),
         team_Effort = round(mean(Effort),2),
         team_PD = round(mean(PD),2),
         team_TD = round(mean(TD),2))|> 
  ungroup()

Correlation Matrix with the variables for aggregated teams measures

Create an correlation matrix displaying values for each Task Load Index factor.

tlx_df_corr_team <- tlx_df |> select(team_Performance, team_Effort, team_Frustration, team_MD, team_TD, team_PD)
cor_matrix_team <- cor(tlx_df_corr_team, use = "complete.obs") 
new_labels <- c("Performance", "Effort", "Frustration", "Mental Demand", "Temporal Demand", "Physical Demand")
colnames(cor_matrix_team) <- new_labels
rownames(cor_matrix_team) <- new_labels
corrplot(cor_matrix_team, method = "color", type = "upper", 
         addCoef.col = "black", # Add correlation coefficients to plot
         tl.col = "black", tl.srt = 45,# Rotate x-axis labels for readability
         title = "Correlation Matrix of Team Measures",
         mar = c(0,0,2,0)) 

## Plot Performance by Frustration for Individual Values by Scenario

suppressMessages(ggplot(tlx_df, aes(x = Performance, y = Frustration))) +
  geom_point() +
  geom_smooth(method = "lm", se=TRUE, linewidth = 1.0, color="red") +
  facet_wrap(~Scenario) +
  labs(title = "Performance by Frustration for Individual Values",
       x = "Performance",
       y = "Frustration")
## `geom_smooth()` using formula = 'y ~ x'

  #theme(legend.position = "none") +
  #scale_color_gradient(low="lightseagreen", high="red") +
  #guides(color=guide_legend(reverse = FALSE))

Plot Overall Performance by Team and Scenario

suppressMessages(ggplot(tlx_df, aes(x = Scenario, y = team_Performance, group = 1))) +
  geom_line(aes(color=Team), linewidth=1.0) +
  geom_point(aes(color=Team)) +
  geom_smooth(method = "lm", se=FALSE, linewidth = 1.0, color="black") +
  facet_wrap(~Team) +
  labs(title = "Team Performance by Scenario",
       x = "Scenario",
       y = "Performance") +
  theme(legend.position = "none") +
  scale_color_gradient(low="lightseagreen", high="red") +
  guides(color=guide_legend(reverse = FALSE))
## `geom_smooth()` using formula = 'y ~ x'

ggplot(tlx_df, aes(x = as.numeric(Scenario), y = team_Performance)) +
  geom_point(color = "darkblue") +  # Add points to the plot
  geom_smooth(method = "lm", se=TRUE, size =1.0, color="red") +
  xlab("Scenario") +  # Label x-axis
  ylab("Performance Mean")  # Label y-axis
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `geom_smooth()` using formula = 'y ~ x'

ggplot(tlx_df, aes(x = as.factor(Scenario), y = team_Performance)) +
  geom_boxplot(fill = "darkblue", color = "limegreen") +  # Add boxplot layer
  xlab("Scenario") +  # Label x-axis
  ylab("Performance Mean")  # Label y-axis 

Plot Frustration by Team and Scenario

ggplot(tlx_df, aes(x=Scenario, y=team_Frustration, group = 1)) +
  geom_line(aes(color=Team), size=1.0) +
  geom_point(aes(color=Team)) +
  geom_smooth(method = "lm", se=FALSE, linewidth = 1.0, color="black") +
  facet_wrap(~Team) +
  labs(title = "Team Frustration by Scenario",
       x = "Scenario",
       y = "Frustration")+
  theme(legend.position = "none") +
  scale_color_gradient(low="lightseagreen", high="red") +
  guides(color=guide_legend(reverse = FALSE))
## `geom_smooth()` using formula = 'y ~ x'

ggplot(tlx_df, aes(x = as.numeric(Scenario), y = team_Frustration)) +
  geom_point(color = "darkblue") +  # Add points to the plot
  geom_smooth(method = "lm", se=TRUE, size =1.0, color="red") +
  xlab("Scenario") +  # Label x-axis
  ylab("Frustration Mean")  # Label y-axis
## `geom_smooth()` using formula = 'y ~ x'

Plot Mental Demand by Team and Scenario

ggplot(tlx_df, aes(x=Scenario, y=team_MD, group = 1)) +
  geom_line(aes(color=Team), size=1.0) +
  geom_point(aes(color=Team)) +
  geom_smooth(method = "lm", se=FALSE, linewidth = 1.0, color="black") +
  facet_wrap(~Team) +
  labs(title = "Team Mental Demand by Scenario",
       x = "Scenario",
       y = "Mental Demand") +
  theme(legend.position = "none") +
  scale_color_gradient(low="lightseagreen", high="red") +
  guides(color=guide_legend(reverse = FALSE))
## `geom_smooth()` using formula = 'y ~ x'

ggplot(tlx_df, aes(x = as.numeric(Scenario), y = team_MD)) +
  geom_point(color = "darkblue") +  # Add points to the plot
  geom_smooth(method = "lm", se=TRUE, size =1.0, color="red") +
  xlab("Scenario") +  # Label x-axis
  ylab(" Mental Demand Mean")  # Label y-axis
## `geom_smooth()` using formula = 'y ~ x'

Regression Analysis Performance vs. Frustration

subset_team_2 <- tlx_df |> select(Team, Scenario, team_Performance, team_MD, team_Frustration) |>
  distinct() |> 
  ungroup()
#write_xlsx(subset_team_2, "team_test.xlsx")
reg_perf <- lm(team_Performance ~ team_Frustration + team_MD, data = subset_team_2)
summary(reg_perf)
## 
## Call:
## lm(formula = team_Performance ~ team_Frustration + team_MD, data = subset_team_2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.0916 -1.1020  0.0985  1.2518  3.8540 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      16.31263    1.01791  16.026  < 2e-16 ***
## team_Frustration -0.53056    0.08438  -6.288 2.53e-08 ***
## team_MD           0.06244    0.11231   0.556     0.58    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.683 on 69 degrees of freedom
## Multiple R-squared:  0.4564, Adjusted R-squared:  0.4406 
## F-statistic: 28.97 on 2 and 69 DF,  p-value: 7.363e-10
residuals <- resid(reg_perf)
plot(fitted(reg_perf), residuals, 
     xlab = "Fitted Values", ylab = "Residuals",
     main = "Residuals vs. Fitted Values")
abline(h = 0, col = "red", lty = 2) 

reg_perf_int <- lm(team_Performance ~ team_Frustration + team_MD + (team_Frustration * team_MD), data = subset_team_2)
summary(reg_perf_int)
## 
## Call:
## lm(formula = team_Performance ~ team_Frustration + team_MD + 
##     (team_Frustration * team_MD), data = subset_team_2)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -3.201 -1.170  0.093  1.090  3.664 
## 
## Coefficients:
##                          Estimate Std. Error t value Pr(>|t|)   
## (Intercept)              10.69517    3.15191   3.393  0.00116 **
## team_Frustration          0.03290    0.31107   0.106  0.91609   
## team_MD                   0.58150    0.29741   1.955  0.05467 . 
## team_Frustration:team_MD -0.05019    0.02671  -1.879  0.06449 . 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.653 on 68 degrees of freedom
## Multiple R-squared:  0.4832, Adjusted R-squared:  0.4604 
## F-statistic:  21.2 on 3 and 68 DF,  p-value: 8.381e-10
residuals <- resid(reg_perf_int)
plot(fitted(reg_perf_int), residuals, 
     xlab = "Fitted Values", ylab = "Residuals",
     main = "Residuals vs. Fitted Values")
abline(h = 0, col = "red", lty = 2)

reg_perf_s <- lm(team_Performance ~ team_Frustration + team_MD + Scenario, data = subset_team_2)
summary(reg_perf_s)
## 
## Call:
## lm(formula = team_Performance ~ team_Frustration + team_MD + 
##     Scenario, data = subset_team_2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.7575 -1.0023 -0.1337  1.2126  3.3518 
## 
## Coefficients:
##                  Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      14.74230    1.21311  12.152  < 2e-16 ***
## team_Frustration -0.52873    0.08371  -6.316  2.9e-08 ***
## team_MD           0.11375    0.11462   0.992   0.3248    
## Scenario2         0.89322    0.68077   1.312   0.1942    
## Scenario3         0.86404    0.68697   1.258   0.2130    
## Scenario4         1.04142    0.69060   1.508   0.1365    
## Scenario5         1.43708    0.68988   2.083   0.0412 *  
## Scenario6         1.58491    0.69807   2.270   0.0266 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.667 on 64 degrees of freedom
## Multiple R-squared:  0.5056, Adjusted R-squared:  0.4515 
## F-statistic:  9.35 on 7 and 64 DF,  p-value: 6.33e-08
residuals <- resid(reg_perf_s)
plot(fitted(reg_perf_s), residuals, 
     xlab = "Fitted Values", ylab = "Residuals",
     main = "Residuals vs. Fitted Values")
abline(h = 0, col = "red", lty = 2) 

reg_model_sug <- lm(team_Performance ~ team_Frustration + team_MD + (team_Frustration * team_MD) + Scenario, data = subset_team_2)
summary(reg_model_sug)
## 
## Call:
## lm(formula = team_Performance ~ team_Frustration + team_MD + 
##     (team_Frustration * team_MD) + Scenario, data = subset_team_2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.2996 -1.2304 -0.0847  1.2778  3.1302 
## 
## Coefficients:
##                          Estimate Std. Error t value Pr(>|t|)  
## (Intercept)               8.33009    3.29698   2.527   0.0140 *
## team_Frustration          0.09980    0.31251   0.319   0.7505  
## team_MD                   0.69692    0.30138   2.312   0.0240 *
## Scenario2                 0.99349    0.66541   1.493   0.1404  
## Scenario3                 1.15540    0.68415   1.689   0.0962 .
## Scenario4                 1.11136    0.67408   1.649   0.1042  
## Scenario5                 1.55168    0.67480   2.299   0.0248 *
## Scenario6                 1.65204    0.68130   2.425   0.0182 *
## team_Frustration:team_MD -0.05606    0.02691  -2.084   0.0413 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.625 on 63 degrees of freedom
## Multiple R-squared:  0.5375, Adjusted R-squared:  0.4787 
## F-statistic: 9.151 on 8 and 63 DF,  p-value: 2.982e-08
residuals <- resid(reg_model_sug)
plot(fitted(reg_model_sug), residuals, 
     xlab = "Fitted Values", ylab = "Residuals",
     main = "Residuals vs. Fitted Values")
abline(h = 0, col = "red", lty = 2) 

reg_model_square <- lm(team_Performance ~ team_Frustration + I(team_Frustration^2) + team_MD + I(team_MD^2) + (team_Frustration * team_MD) + Scenario, data = subset_team_2)
summary(reg_model_square)
## 
## Call:
## lm(formula = team_Performance ~ team_Frustration + I(team_Frustration^2) + 
##     team_MD + I(team_MD^2) + (team_Frustration * team_MD) + Scenario, 
##     data = subset_team_2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.2100 -1.0849 -0.0694  1.0702  3.3492 
## 
## Coefficients:
##                          Estimate Std. Error t value Pr(>|t|)  
## (Intercept)               5.29716    4.21014   1.258   0.2131  
## team_Frustration          0.17407    0.54072   0.322   0.7486  
## I(team_Frustration^2)    -0.04652    0.02880  -1.615   0.1114  
## team_MD                   1.23991    0.87299   1.420   0.1606  
## I(team_MD^2)             -0.05840    0.05015  -1.164   0.2488  
## Scenario2                 0.78417    0.66754   1.175   0.2447  
## Scenario3                 1.11165    0.67709   1.642   0.1058  
## Scenario4                 1.06260    0.67187   1.582   0.1189  
## Scenario5                 1.50117    0.67127   2.236   0.0290 *
## Scenario6                 1.69710    0.67375   2.519   0.0144 *
## team_Frustration:team_MD  0.02099    0.05028   0.418   0.6778  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.605 on 61 degrees of freedom
## Multiple R-squared:  0.5631, Adjusted R-squared:  0.4915 
## F-statistic: 7.862 on 10 and 61 DF,  p-value: 5.892e-08
residuals <- resid(reg_model_square)
plot(fitted(reg_model_sug), residuals, 
     xlab = "Fitted Values", ylab = "Residuals",
     main = "Residuals vs. Fitted Values")
abline(h = 0, col = "red", lty = 2) 

reg_model_square_f <- lm(team_Performance ~ team_Frustration + I(team_Frustration^2) + team_MD + I(team_MD^2) + (team_Frustration * team_MD), data = subset_team_2)
summary(reg_model_square_f)
## 
## Call:
## lm(formula = team_Performance ~ team_Frustration + I(team_Frustration^2) + 
##     team_MD + I(team_MD^2) + (team_Frustration * team_MD), data = subset_team_2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.2205 -1.1224 -0.0258  1.2126  3.7219 
## 
## Coefficients:
##                           Estimate Std. Error t value Pr(>|t|)  
## (Intercept)               7.270470   4.112268   1.768   0.0817 .
## team_Frustration          0.001063   0.541590   0.002   0.9984  
## I(team_Frustration^2)    -0.040665   0.028441  -1.430   0.1575  
## team_MD                   1.279746   0.866583   1.477   0.1445  
## I(team_MD^2)             -0.065029   0.050186  -1.296   0.1996  
## team_Frustration:team_MD  0.025924   0.050257   0.516   0.6077  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.637 on 66 degrees of freedom
## Multiple R-squared:  0.5079, Adjusted R-squared:  0.4706 
## F-statistic: 13.62 on 5 and 66 DF,  p-value: 3.929e-09
residuals <- resid(reg_model_square_f)
plot(fitted(reg_model_square_f), residuals, 
     xlab = "Fitted Values", ylab = "Residuals",
     main = "Residuals vs. Fitted Values")
abline(h = 0, col = "red", lty = 2)

min(tlx_df$team_Frustration)
## [1] 4
max(tlx_df$team_Frustration)
## [1] 16.2
min(tlx_df$team_MD)
## [1] 6.17
max(tlx_df$team_MD)
## [1] 16.5
reg_model_square_f <- lm(team_Performance ~ team_Frustration + I(team_Frustration^2) 
                           + team_MD + I(team_MD^2)
                           + (team_MD * team_Frustration), data = subset_team_2)
summary(reg_model_square_f)
## 
## Call:
## lm(formula = team_Performance ~ team_Frustration + I(team_Frustration^2) + 
##     team_MD + I(team_MD^2) + (team_MD * team_Frustration), data = subset_team_2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.2205 -1.1224 -0.0258  1.2126  3.7219 
## 
## Coefficients:
##                           Estimate Std. Error t value Pr(>|t|)  
## (Intercept)               7.270470   4.112268   1.768   0.0817 .
## team_Frustration          0.001063   0.541590   0.002   0.9984  
## I(team_Frustration^2)    -0.040665   0.028441  -1.430   0.1575  
## team_MD                   1.279746   0.866583   1.477   0.1445  
## I(team_MD^2)             -0.065029   0.050186  -1.296   0.1996  
## team_Frustration:team_MD  0.025924   0.050257   0.516   0.6077  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.637 on 66 degrees of freedom
## Multiple R-squared:  0.5079, Adjusted R-squared:  0.4706 
## F-statistic: 13.62 on 5 and 66 DF,  p-value: 3.929e-09
# Assuming reg_model_square_f is your fitted model object

# Extract residuals
model_residuals <- residuals(reg_model_square_f) 

# Create the residual plot
plot(fitted(reg_model_square_f), model_residuals,
     xlab = "Fitted Values", ylab = "Residuals",
     main = "Residuals vs. Fitted Values")

# Add the horizontal line
abline(h = 0, col = "red", lty = 2) 

min(tlx_df$team_Frustration)
## [1] 4
max(tlx_df$team_Frustration)
## [1] 16.2
min(tlx_df$team_MD)
## [1] 6.17
max(tlx_df$team_MD)
## [1] 16.5

Scatter Plots

ggplot(subset_team_2, aes(x= team_MD, y = team_Performance)) +
  geom_point() +
  geom_smooth(method = "lm") +
  labs(x = "Mental Demand", y = "Performance")
## `geom_smooth()` using formula = 'y ~ x'

ggplot(subset_team_2, aes(x= team_Frustration, y = team_Performance)) +
  geom_point() +
  geom_smooth(method = "lm") +
  labs(x = "Frustration", y = "Performance")
## `geom_smooth()` using formula = 'y ~ x'

ggplot(subset_team_2, aes(x= team_Frustration, y = team_MD)) +
  geom_point() +
  geom_smooth(method = "lm") +
  labs(x = "Frustration", y = "Mental Demand")
## `geom_smooth()` using formula = 'y ~ x'