#R Markdown Assignment 6

#Question1a

# data
person <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
aspirin_A <- c(15, 26, 13, 28, 17, 20, 7, 36, 12, 18)
aspirin_B <- c(13, 20, 10, 21, 17, 22, 5, 30, 7, 11)

#data frame
aspirin_data <- data.frame(person, aspirin_A, aspirin_B)
aspirin_data
##    person aspirin_A aspirin_B
## 1       1        15        13
## 2       2        26        20
## 3       3        13        10
## 4       4        28        21
## 5       5        17        17
## 6       6        20        22
## 7       7         7         5
## 8       8        36        30
## 9       9        12         7
## 10     10        18        11

Null Hypothesis (H₀): The mean concentrations of the two drugs are the same in urine specimens

Alternative Hypothesis (H₁): The mean concentrations of the two drugs are not the same in urine specimens

\(H_0: \mu_A = \mu_B\) and \(H_1: \mu_A \neq \mu_B\)

#Question1b

#performing paired t-test
paired_test <- t.test(aspirin_A, aspirin_B, paired = TRUE)
paired_test
## 
##  Paired t-test
## 
## data:  aspirin_A and aspirin_B
## t = 3.6742, df = 9, p-value = 0.005121
## alternative hypothesis: true mean difference is not equal to 0
## 95 percent confidence interval:
##  1.383548 5.816452
## sample estimates:
## mean difference 
##             3.6
#extracting the p-value
p_value_paired <- paired_test$p.value
p_value_paired
## [1] 0.005121073

The p-value from the paired t-test is 0.0051

With α = 0.05, since the p-value is 0.0051, we reject the null hypothesis

#Conclusion: There is a significant difference between the mean concentrations of the two aspirin types

#Question1c

#performing the two-sample t-test for comparison
two_sample_test <- t.test(aspirin_A, aspirin_B, paired = FALSE)
two_sample_test
## 
##  Welch Two Sample t-test
## 
## data:  aspirin_A and aspirin_B
## t = 0.9802, df = 17.811, p-value = 0.3401
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -4.12199 11.32199
## sample estimates:
## mean of x mean of y 
##      19.2      15.6
#extracting the p-value
p_value_two_sample <- two_sample_test$p.value
p_value_two_sample
## [1] 0.3401157

#comparing the p-value: The p-value from the two-sample t-test would have been 0.3401

#Comparison: The two-sample t-test gives a larger p-value (0.3401) compared to the paired t-test (0.0051)

#Question2a

#data
active_exercise <- c(9.50, 10.00, 9.75, 9.75, 9.00, 13.0)
no_exercise <- c(11.50, 12.00, 13.25, 11.50, 13.00, 9.00)

#data frame
walking_data <- data.frame(active_exercise = c(active_exercise, rep(NA, length(no_exercise)-length(active_exercise))), no_exercise = no_exercise)
walking_data
##   active_exercise no_exercise
## 1            9.50       11.50
## 2           10.00       12.00
## 3            9.75       13.25
## 4            9.75       11.50
## 5            9.00       13.00
## 6           13.00        9.00

Null Hypothesis (H₀): The mean time to walk is the same for children who receive active exercise versus no exercise

Alternative Hypothesis (H₁): The mean time to walk is less for children who receive active exercise versus no exercise

\(H_0: \mu_{Active} = \mu_{No}\) and \(H_1: \mu_{Active} < \mu_{No}\)

#Question 2b We might want to use a non-parametric method because we have a small sample size (only 6 infants per group) which may not meet the normality assumptions required for t-tests. Non-parametric tests like the mann-whitney u test are more robust to outliers and non-normal distributions since they don’t assume the data follows a normal distribution

#Question 2c

#performing the mann-whitney u test using the wilcox test function 
mann_whitney_test <- wilcox.test(active_exercise, no_exercise,alternative = "less",exact = FALSE)
mann_whitney_test
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  active_exercise and no_exercise
## W = 9, p-value = 0.08523
## alternative hypothesis: true location shift is less than 0
#extracting the p-value
p_value_mann_whitney <- mann_whitney_test$p.value
p_value_mann_whitney
## [1] 0.08523293

#comparing the p-value: The p-value from the mann-whitney u test is 0.0852

With α = 0.05, since the p-value is 0.0852, we fail to reject the null hypothesis

Conclusion: There is not a sufficient amount evidence to conclude that active exercise reduces the mean time to walk