install.packages("ggbeeswarm", repos = "https://cloud.r-project.org/")
## 
## The downloaded binary packages are in
##  /var/folders/3g/ln4t2cvs3250dv7p12p13c_c0000gn/T//RtmpG4lyPZ/downloaded_packages
library(ggbeeswarm)
## Loading required package: ggplot2
library(ggplot2)
library(gridExtra)

motivatie$RowID <- as.factor(seq_len(nrow(motivatie)))
motivatie$relevance_coschap <- as.factor(motivatie$relevance_coschap)
motivatie$relevance_career <- as.factor(motivatie$relevance_career)

# Bee swarm plot for AM_KNO with relevance_coschap
p1 <- ggplot(data = motivatie, aes(x = AM_KNO, y = Level_Completed, color = RowID)) +
  geom_quasirandom(width = 0.2) +
  labs(
    title = "Effect of AM KNO \non Engagement",
    x = "Autonomous Motivation for KNO",
    y = "Level Completed",
    color = "User ID"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) 

# Bee swarm plot for CM_KNO with relevance_coschap
p2 <- ggplot(data = motivatie, aes(x = CM_KNO, y = Level_Completed, color = RowID)) +
  geom_quasirandom(width = 0.2) +
  labs(
    title = "Effect of CM KNO \non Engagement",
    x = "Controlled Motivation for KNO",
    y = "Level Completed",
    color = "User ID"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) 

# Display plots side by side
grid.arrange(p1, p2, ncol = 2)

# Bee swarm plot for AM_KNO with relevance_career
p3 <- ggplot(data = motivatie, aes(x = AM_KNO, y = Questions_Attemped, color = RowID)) +
  geom_quasirandom(width = 0.2) +
  labs(
    title = "Effect AM KNO \non Engagement",
    x = "Autonomous Motivation for KNO",
    y = "Questions Attempted",
    color = "User ID"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) 

# Bee swarm plot for CM_KNO with relevance_career
p4 <- ggplot(data = motivatie, aes(x = CM_KNO, y = Questions_Attemped, color = RowID)) +
  geom_quasirandom(width = 0.2) +
  labs(
    title = "Effect of CM KNO \non Engagement",
    x = "Controlled Motivatiin for KNO",
    y = "Questions Attempted",
    color = "User ID"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) 

# Display plots side by side
grid.arrange(p3, p4, ncol = 2)

motivatie$RowID <- as.factor(seq_len(nrow(motivatie)))
motivatie$relevance_coschap <- as.factor(motivatie$relevance_coschap)
motivatie$relevance_career <- as.factor(motivatie$relevance_career)

# Bee swarm plot for AM_KNO with relevance_coschap
p1 <- ggplot(data = motivatie, aes(x = Amotivation_KNO, y = Level_Completed, color = RowID)) +
  geom_quasirandom(width = 0.2) +
  labs(
    x = "Amotivation for KNO",
    y = "Level Completed",
    color = "User ID"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) 

# Bee swarm plot for CM_KNO with relevance_coschap
p2 <- ggplot(data = motivatie, aes(x = Amotivation_KNO, y = Questions_Attemped, color = RowID)) +
  geom_quasirandom(width = 0.2) +
  labs(
    x = "Amotivation for KNO",
    y = "Questions Attempted",
    color = "User ID"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) 

# Display plots side by side
grid.arrange(p1, p2, ncol = 2, top="Effect of Amotivation for KNO on Engagement")

# Load the necessary libraries
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following object is masked from 'package:gridExtra':
## 
##     combine
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(forcats)

motivation_eng <- na.omit(motivatie[, c("relevance_coschap", "RAM_Med", "RAM_KNO", "relevance_career","Questions_Attemped", "Level_Completed")])

# Simplify categorical variables if necessary
motivation_eng <- motivation_eng %>%
  mutate(relevance_coschap = fct_collapse(relevance_coschap,
                                          "No" = c("Niet", "Waarschijnlijk niet"),
                                          "Yes" = c("Waarschijnlijk wel", "Zeker wel")),
         relevance_career = fct_collapse(relevance_career,
                                         "No" = c("Niet", "Waarschijnlijk niet"),
                                         "Yes" = c("Waarschijnlijk wel", "Zeker wel")))

# Check the distribution after combining
table(motivation_eng$relevance_coschap)
## 
## Geen idee/neutraal                 No                Yes 
##                  1                  4                  3
table(motivation_eng$relevance_career)
## 
## Geen idee/neutraal                 No                Yes 
##                  2                  3                  3
# Simplified regression model for Level_Completed
model_level <- lm(Level_Completed ~ RAM_Med + RAM_KNO + relevance_coschap + relevance_career, data = motivation_eng)
summary(model_level)
## 
## Call:
## lm(formula = Level_Completed ~ RAM_Med + RAM_KNO + relevance_coschap + 
##     relevance_career, data = motivation_eng)
## 
## Residuals:
##          1          2          3          4          5          6          7 
## -1.693e+00  3.142e-01 -3.814e-01 -1.693e+00  2.074e+00  9.098e-16  1.693e+00 
##          8 
## -3.142e-01 
## 
## Coefficients:
##                      Estimate Std. Error t value Pr(>|t|)
## (Intercept)          -13.3765    12.4328  -1.076    0.477
## RAM_Med                0.2073     0.7577   0.274    0.830
## RAM_KNO                0.1021     0.6222   0.164    0.896
## relevance_coschapNo   11.6411     5.3429   2.179    0.274
## relevance_coschapYes   3.0943     5.2648   0.588    0.662
## relevance_careerNo    11.9838     7.2776   1.647    0.347
## relevance_careerYes    7.6167     5.7163   1.332    0.410
## 
## Residual standard error: 3.639 on 1 degrees of freedom
## Multiple R-squared:  0.9047, Adjusted R-squared:  0.3327 
## F-statistic: 1.582 on 6 and 1 DF,  p-value: 0.5432
model_questions <- lm(Questions_Attemped ~ RAM_Med + RAM_KNO + relevance_coschap + relevance_career, data = motivation_eng)
summary(model_questions)
## 
## Call:
## lm(formula = Questions_Attemped ~ RAM_Med + RAM_KNO + relevance_coschap + 
##     relevance_career, data = motivation_eng)
## 
## Residuals:
##          1          2          3          4          5          6          7 
## -2.407e+01  4.469e+00 -5.425e+00 -2.407e+01  2.950e+01  1.563e-14  2.407e+01 
##          8 
## -4.469e+00 
## 
## Coefficients:
##                      Estimate Std. Error t value Pr(>|t|)
## (Intercept)          -242.992    176.826  -1.374    0.400
## RAM_Med                 4.623     10.776   0.429    0.742
## RAM_KNO                 4.160      8.849   0.470    0.720
## relevance_coschapNo   198.735     75.990   2.615    0.233
## relevance_coschapYes   57.339     74.878   0.766    0.584
## relevance_careerNo    216.824    103.506   2.095    0.284
## relevance_careerYes   123.119     81.301   1.514    0.372
## 
## Residual standard error: 51.75 on 1 degrees of freedom
## Multiple R-squared:  0.9315, Adjusted R-squared:  0.5206 
## F-statistic: 2.267 on 6 and 1 DF,  p-value: 0.4687
# Bee swarm plot for AM_KNO with relevance_coschap
p1 <- ggplot(data = motivatie, aes(x = RAM_KNO, y = Level_Completed, color = RowID)) +
  geom_quasirandom(width = 0.2) +
  labs(
    x = "RAM for KNO",
    y = "Level Completed",
    color = "User ID"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) 

# Bee swarm plot for CM_KNO with relevance_coschap
p2 <- ggplot(data = motivatie, aes(x = RAM_KNO, y = Questions_Attemped, color = RowID)) +
  geom_quasirandom(width = 0.2) +
  labs(
    x = "RAM for KNO",
    y = "Questions Attempted",
    color = "User ID"
  ) +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) 

# Display plots side by side
grid.arrange(p1, p2, ncol = 2, top="Effect of RAM for KNO on Engagement")