Module # 8 Assignment
Issaiah Jennings
Module # 8 Assignment
Your assignment:
A researcher is interested in the effects of drug against stress reaction. She gives a reaction time test to three different groups of subjects: one group that is under a great deal of stress, one group under a moderate amount of stress, and a third group that is under almost no stress. The subjects of the study were instructed to take the drug test during their next stress episode and to report their stress on a scale of 1 to 10 (10 being most pain).
Report on drug and stress level by using R. Provide a full summary report on the result of ANOVA testing and what does it mean. More specifically, report using the following R functions: Df, Sum, Sq Mean, Sq, F value, Pr(>F)
> # Create a dataframe with stress levels and corresponding pain levels > stress_data <- data.frame( + stress_level = factor(rep(c("High", "Moderate", "Low"), each = 6)), + pain_level = c(10, 9, 8, 9, 10, 8, 8, 10, 6, 7, 8, 8, 4, 6, 6, 4, 2, 2) + ) > > # Display the data > print(stress_data) stress_level pain_level 1 High 10 2 High 9 3 High 8 4 High 9 5 High 10 6 High 8 7 Moderate 8 8 Moderate 10 9 Moderate 6 10 Moderate 7 11 Moderate 8 12 Moderate 8 13 Low 4 14 Low 6 15 Low 6 16 Low 4 17 Low 2 18 Low 2 >
>
> # Perform ANOVA test
> anova_stress <- aov(PainLevel ~ StressLevel, data = stress_data)
>
> # Get the summary of the ANOVA test
> summary(anova_stress)
Df Sum Sq Mean Sq F value Pr(>F)
StressLevel 2 82.11 41.06 21.36 4.08e-05 ***
Residuals 15 28.83 1.92
---
Pr(>F): 4.08e-05 (the p-value indicating that the differences between groups are statistically significant at the 0.05 significance level. Since the p-value is much less than 0.05, we reject the null hypothesis, which means there are significant differences in pain levels between the stress groups).
------------
2. From our Textbook:Introductory Statistics with R. Chapter 7. 7.6 Exercises #7.1 pp. 143.
The zelazo data (taken from textbook's R package called ISwR) are in the form of a list of vectors, one for each of the four groups. Convert the data to a form suitable for the user of lm, and calculate the relevant test. Consider t tests comparing selected subgroups or obtained by combing groups.
> # Load the dataset
> data("zelazo")
>
> # Convert the list into a data frame
> df <- data.frame(
+ Group = rep(c("active", "passive", "none", "Ctr.8w"), times = sapply(zelazo, length)),
+ Value = unlist(zelazo)
+ )
>
> # Print the data frame to verify
> print(df)
Group Value
active1 active 9.00
active2 active 9.50
active3 active 9.75
active4 active 10.00
active5 active 13.00
active6 active 9.50
passive1 passive 11.00
passive2 passive 10.00
passive3 passive 10.00
passive4 passive 11.75
passive5 passive 10.50
passive6 passive 15.00
none1 none 11.50
none2 none 12.00
none3 none 9.00
none4 none 11.50
none5 none 13.25
none6 none 13.00
ctr.8w1 Ctr.8w 13.25
ctr.8w2 Ctr.8w 11.50
ctr.8w3 Ctr.8w 12.00
ctr.8w4 Ctr.8w 13.50
ctr.8w5 Ctr.8w 11.50
>
> # Compare Active vs Passive
> t_test_active_passive <- t.test(Value ~ Group, data = df[df$Group %in% c("active", "passive"),])
> print(t_test_active_passive)
data: Value by Group
t = -1.2839, df = 9.3497, p-value = 0.2301
alternative hypothesis: true difference in means between group active and group passive is not equal to 0
95 percent confidence interval:
-3.4399668 0.9399668
sample estimates:
mean in group active mean in group passive
10.125 11.375
>
> # Compare None vs Ctr.8w
> t_test_none_ctr8w <- t.test(Value ~ Group, data = df[df$Group %in% c("none", "Ctr.8w"),])
> print(t_test_none_ctr8w)
data: Value by Group
t = 0.84986, df = 8.5046, p-value = 0.4187
alternative hypothesis: true difference in means between group Ctr.8w and group none is not equal to 0
95 percent confidence interval:
-1.081614 2.364947
sample estimates:
mean in group Ctr.8w mean in group none
12.35000 11.70833
-------------
2.1 Consider ANOVA test (one way or two-way) for this dataset (zelazo)
>
> # Perform the ANOVA using lm and aov
> anova_result <- aov(value ~ group, data = df)
>
> # Display the ANOVA summary
> summary(anova_result)
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
>
Comments
Post a Comment