Let us take the data of Aspirin A as “A” and Aspirin B as “B”
# Let Aspirin data be stored in "A" and Aspirin B data stored in "B"
A<- c(15, 26, 13, 28, 17, 20, 7, 36, 12, 18)
B<- c(13, 20, 10,21,17,22,5,30, 7, 11)
Let us state the Hypothesis for the t-test. Assume the means for Aspirin A and Aspirin B be \(\mu_{1}\) and \(\mu_{2}\) respectively. Now consider the Null and Alternative hypotheses as shown below for performing the t-test.
Let us check for Normality and Variance equality Assumptions to perform a t-test
Normal Probability Plot
#Assumption check
qqnorm (A)
qqline (A)
qqnorm (B)
qqline(B)
Box plot for Aspirin A and B
boxplot(A,B, names = c("Asp A", "Asp B"), main = "Boxplot to compare variance of Asprin A and B")
Comments: observing the NPP, the curves show the normality of both Aspirin data. Then, observing the Boxplot, looks variance equality between the two Drugs.
Paired t-test
# Hypothesis testing using t.test (Paired)
t.test(A,B,var.equal = TRUE,paired = TRUE)
##
## Paired t-test
##
## data: A and 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.6let us compare the p value of both drugs with two sample t-test.
t.test (A,B)
##
## Welch Two Sample t-test
##
## data: A and 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
Let us take the data of Active Exercise as “AE” and No Exercise as “NE”.
#Q2: Let Active exercise data= "AE" and No Excersise date = "NE"
AE<- c(9.50, 10.00, 9.75, 9.75, 9.00, 13.0)
NE<- c(11.50, 12.00,13.25,11.50,13.00, 9.00)
##Question 2. a Let us state the Hypothesis. Assume the means for Active Exercise and No Exercise be \(\mu_{1}\) and \(\mu_{2}\) respectively. Now consider the Null and Alternative hypotheses as shown below for performing the t-test.
##Question 2. b: Check for Normality and Variance.
#Q2.b: Check for assumptions of Two sample t test
qqnorm (AE)
qqline (AE)
qqnorm (NE)
qqline (NE)
boxplot(AE, NE, names = c("Active Exercise", "No Exercise"), main = "Boxplot to check variance between the Active excersise and No Excersise")
cor(NE, AE)
## [1] -0.8882438
##Quetion 2.c Performing the Mann-Whitney-U test.
# Q1.c: Mann-Whitney test
?wilcox.test
wilcox.test(AE,NE,alternative = "less")
##
## Wilcoxon rank sum test with continuity correction
##
## data: AE and NE
## W = 9, p-value = 0.08523
## alternative hypothesis: true location shift is less than 0
It is a good idea to include this at the end of every RMarkdown document
# Let Aspirin data be stored in "A" and Aspirin B data stored in "B"
A<- c(15, 26, 13, 28, 17, 20, 7, 36, 12, 18)
B<- c(13, 20, 10,21,17,22,5,30, 7, 11)
# Q1.b
#Assumption check
qqnorm (A)
qqline (A)
qqnorm (B)
qqline(B)
boxplot(A,B, names = c("Asp A", "Asp B"), main = "Boxplot to compare variance of Asprin A and B")
# Hypothesis testing using t.test (Paired)
t.test(A,B,var.equal = TRUE,paired = TRUE)
#Q1.c Two sample t test
t.test (A,B)
#Q2: Let Active exercise data= "AE" and No Excersise date = "NE"
AE<- c(9.50, 10.00, 9.75, 9.75, 9.00, 13.0)
NE<- c(11.50, 12.00,13.25,11.50,13.00, 9.00)
#Q2.b: Check for assumptions of Two sample t test
qqnorm (AE)
qqline (AE)
qqnorm (NE)
qqline (NE)
boxplot(AE, NE, names = c("Active Exercise", "No Exercise"), main = "Boxplot to check variance between the Active excersise and No Excersise")
cor(NE, AE)
# Q1.c: Mann-Whitney test
?wilcox.test
wilcox.test(AE,NE,alternative = "less")