1 Assignment on Non-Parametric Hypothesis test

1.1 Question 1

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)

1.2 Question 1.a

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.

  • \(H_{0}: \mu_{1} = \mu_{2}\)
  • \(H_{a}: \mu_{1} \neq \mu_{2}\)

1.3 Question 1.b

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.6

1.4 Question 1.c

let 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
  • Final Comments:
    • Both drugs data shows Normality and Equal variance (Assumption check passed)
    • P-value (Paired t-test) = 0.005121 > 0.05 ; We failed to reject the Null Hypothesis.
    • P-value (Unpaired t-test) = 0.3401 >>0.05; again we failed to reject the null hypothesis. Mean of Aspirin A = 19.2 and mean of Aspirin B = 15.6

1.5 Question 2

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.

  • \(H_{0}: \mu_{1} = \mu_{2}\)
  • \(H_{a}: \mu_{1} < \mu_{2}\)

##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
  • Comment: No enough observations to justify Normality, also, the variance is not equal between the data.
    • Correlation between the data is about 88%.
    • Thus, Proceeding for Non-Parametric testing (Mann-Whitney-U Test)

##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
  • Comment: P-value=0.08523 >>0.05; we failed to reject the null hypothesis. -Thus, Mean time taken will be equal (No Significant change found with Active Exerciser)

2 Complete R Code

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")