For this assignment, I used R to perform Anova tests. The first test looked at stress levels, and the second test I analyzed a dataset to see if there were significant differences between the groups.
For the first part, there were three groups: high stress, moderate stress, and low stress. I entered the scores into R and used a one-way ANOVA to compare the groups.
##Add high, moderate and low vectors
high <- c(10, 9, 8, 9, 10, 8)
moderate <- c(8, 10, 6, 7, 8, 8)
low <- c(4, 6, 6, 4, 2, 2)
##Combine the stress scores
stress <- c(high, moderate, low)
##Create group variable
group <- factor(c(
rep(“High”, 6),
rep(“Moderate”, 6),
rep(“Low”, 6)
))
##Create data frame
data <- data.frame(stress, group)
##Create linear model
model <- lm(stress ~ group, data = data)
##Run anova
anova(model)
##Output
##Response: stress
##Df Sum Sq Mean Sq F value Pr(>F)
##group 2 82.111 41.056 21.358 4.082e-05 ***
##Residuals 15 28.833 1.922
The ANOVA test was used to see if there was a difference in stress scores between the three groups. The F value was 21.358, and the p-value was 4.082e-05. Since the p-value is less than 0.05, the results are statistically significant. This means we reject the null hypothesis and can say that there is a significant difference in stress scores between the groups.
For the second part, I used a dataset that contains four groups: active, passive, none, and ctr.8w
install.packages(“ISwR”)
##Load the ISwR package
library(ISwR)
##Load dataset
data(“zelazo”)
##Display dataset
zelazo
##output
##$active
##[1] 9.00 9.50 9.75 10.00 13.00 9.50
##$passive
##[1] 11.00 10.00 10.00 11.75 10.50 15.00
##$none
##[1] 11.50 12.00 9.00 11.50 13.25 13.00
##$ctr.8w
##[1] 13.25 11.50 12.00 13.50 11.50
##Combine scores from all four groups
score <- c(
zelazo$active,
zelazo$passive,
zelazo$none,
zelazo$ctr.8w
)
##Create the group variable
group <- factor(c(
rep(“active”, 6),
rep(“passive”, 6),
rep(“none”, 6),
rep(“ctr.8w”, 5)
))
##Create the data frame
zelazo_data <- data.frame(score, group)
##Display the data
zelazo_data
##output
##score group
##1 9.00 active
##2 9.50 active
##3 9.75 active
##4 10.00 active
##5 13.00 active
##6 9.50 active
##7 11.00 passive
##8 10.00 passive
##9 10.00 passive
##10 11.75 passive
##11 10.50 passive
##12 15.00 passive
##13 11.50 none
##14 12.00 none
##15 9.00 none
##16 11.50 none
##17 13.25 none
##18 13.00 none
##19 13.25 ctr.8w
##20 11.50 ctr.8w
##21 12.00 ctr.8w
##22 13.50 ctr.8w
##23 11.50 ctr.8w
##Create the linear model
model <- lm(score ~ group, data = zelazo_data)
##Run anova
anova(model)
##output
##Analysis of Variance Table
##Response: score
## Df Sum Sq Mean Sq F value Pr(>F)
##group 3 14.778 4.9259 2.1422 0.1285
##Residuals 19 43.690 2.2995
The anova test was used to see if there was a significant difference in scores between the four groups in the Zelazo data. The F value was 2.1422, and the p-value was 0.1285. Since the p-value is greater than 0.05, the results are not statistically significant. So, we do not reject the null hypothesis. This means there is not enough evidence to say that the four groups have significantly different mean scores.
Leave a Reply