Module #8 Assignment
#1
> # Data for each group
> high_stress <- c(10, 9, 8, 9, 10, 8)
> moderate_stress <- c(8, 10, 6, 7, 8, 8)
> low_stress <- c(4, 6, 6, 4, 2, 2)
>
> # Combine data into a data frame
> reaction_time <- c(high_stress, moderate_stress, low_stress)
> stress_level <- factor(rep(c("High_Stress", "Moderate_Stress", "Low_Stress"), each=6))
>
> # Create a data frame
> data <- data.frame(Stress_Level = stress_level, Reaction_Time = reaction_time)
>
> # Perform ANOVA
> anova_model <- aov(Reaction_Time ~ Stress_Level, data=data)
>
> # Summary of ANOVA
> summary(anova_model)
Df Sum Sq Mean Sq F value Pr(>F)
Stress_Level 2 82.11 41.06 21.36 4.08e-05
Residuals 15 28.83 1.92
Stress_Level ***
Residuals
---
Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
>
> # Detailed ANOVA table
> anova_table <- summary(anova_model)- The degrees of freedom for the stress levels are 2 (since there are 3 groups – High, Moderate, Low, so 3 - 1 = 2).
- The residual degrees of freedom are 15 (since there are 18 observations and 18 - 3 = 15). Sum of Squares (Sum Sq):
- The sum of squares for stress levels is 82.11, which measures the variability between the different stress level groups.
- The residual sum of squares is 28.83, which measures the group variability.
- The mean square for stress levels is 41.06, calculated as Sum Sq / Df.
- The mean square for the residuals is 1.92.
- The F value is 21.36, which indicates the variance ratio between the groups to the variance within the groups.
- The p-value is 0.000041, which is much smaller than 0.05. This indicates a statistically significant difference between the reaction times of the different stress levels.
#2
> # Data from Zelazo study > active <- c(9.00, 9.50, 9.75, 10.00, 13.00, 9.50) > passive <- c(11.00, 10.00, 10.00, 11.75, 10.50, 15.00) > none <- c(11.50, 12.00, 9.00, 11.50, 13.25, 13.00) > ctr_8w <- c(13.25, 11.50, 12.00, 13.50, 11.50) > > # Combine the data into a data frame > score <- c(active, passive, none, ctr_8w) > group <- factor(rep(c("active", "passive", "none", "ctr_8w"), times = c(6, 6, 6, 5))) > > # Create a data frame > zelazo_df <- data.frame(Group = group, Score = score) > > # Perform one-way ANOVA > zelazo_aov <- aov(Score ~ Group, data = zelazo_df) > > # Summary of the ANOVA > summary(zelazo_aov) Df Sum Sq Mean Sq F value Pr(>F) Group 3 14.78 4.926 2.142 0.129 Residuals 19 43.69 2.299 > > # t-test between 'active' and 'passive' > t.test(subset(zelazo_df, Group == "active")$Score, + subset(zelazo_df, Group == "passive")$Score) Welch Two Sample t-test data: subset(zelazo_df, Group == "active")$Score and subset(zelazo_df, Group == "passive")$Score t = -1.2839, df = 9.3497, p-value = 0.2301 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -3.4399668 0.9399668 sample estimates: mean of x mean of y 10.125 11.375 > # t-test between 'none' and 'ctr_8w' > t.test(subset(zelazo_df, Group == "none")$Score, + subset(zelazo_df, Group == "ctr_8w")$Score) Welch Two Sample t-test data: subset(zelazo_df, Group == "none")$Score and subset(zelazo_df, Group == "ctr_8w")$Score t = -0.84986, df = 8.5046, p-value = 0.4187 alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -2.364947 1.081614 sample estimates: mean of x mean of y 11.70833 12.35000
Comments
Post a Comment