Module 8 Assignment
Part 1
- Using R we have been asked to report on the drug and stress levels in the provided data set, to begin with we must create the vectors for each group.
# Create vectors 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)
- Following that, the vectors must be combined into one data frame, stress_data.
# Combine the vectors into a dataframe
stress_data <- data.frame(
stress_level = factor(rep(c("High", "Moderate", "Low"), each = 6)),
score = c(high_stress, moderate_stress, low_stress)
)
- An ANOVA test is performed to determine whether there is a significant difference between the groups
# Perform the ANOVA test
anova_result <- aov(score ~ stress_level, data = stress_data)
# Print the summary of the ANOVA test
summary(anova_result)
- This creates the following output:
Part 2
- To perform an ANOVA test on the zelazo dataset using R we must first load the ISwR package and the zelazo data
# Load the ISwR package and the zelazo data
library(ISwR)
data("zelazo")
- After that, the list data has to be converted to a data frame suitable for lm()
# Convert the list to a dataframe suitable for lm()
zelazo_data <- stack(zelazo)
- Next, finally perform the ANOVA test
# Perform the ANOVA test
anova_result_zelazo <- aov(values ~ ind, data = zelazo_data)
# Print the summary of the ANOVA test
summary(anova_result_zelazo)
- The output looks as such:
Comments
Post a Comment