Summary and Data Input

We are looking at the bioavailability of two types of aspirin, type A and type B. We will compare the concentrations of the two types of aspirin in urine specimens taken from the same person 1 hour after they have taken the drug. The two samples of aspirin will be administered one week apart.

We begin this study by inputting the dataset that we will analyze.

#Input data using data.frame
#Concentration data for the aspirin samples, type A and type B.
dat<-data.frame(
  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)
)

Paired T-Test

If we want to test the hypothesis that the mean concentrations of the two drugs are the same in urine specimens, then the hypothesis will be:

Null Hypothesis: \[H_0:\mu_{D} = 0\] Where mu_D is the mean of the paired differences: Type A - Type B.

Alternative Hypothesis: \[H_a:\mu_{D}\ne0\]

First we can test our hypothesis using a paired t-test.

t.test(dat$Aspirin_A,dat$Aspirin_B, paired=TRUE,conf.level = .95)
## 
##  Paired t-test
## 
## data:  dat$Aspirin_A and dat$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

Running the paired t-test with an alpha=0.05, we find a p-value of 0.005121. From this we can conclude that since \[p<\alpha\]we shall reject the null hypothesis. It appears that the mean 1-hour urine concentrations of Aspirin A and Aspirin B are different.

Two Sample T-Test

Lets look at what a two-sample t-test would yield for this.

t.test(dat$Aspirin_A,dat$Aspirin_B, paired=FALSE, conf.level = .95)
## 
##  Welch Two Sample t-test
## 
## data:  dat$Aspirin_A and dat$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

If we were to use the two-sample t-test, we would fail to reject the null hypothesis and incorrectly conclude that there is no significant difference in Aspirin A to Aspirin B.

Study #2

We now take a look at a second study. This study researchers are asking “Can exercise shorten the time that it takes and infant to learn how to walk alone?”. Let’s intake the collected data.

#Input data using data.frame
dat2<-data.frame(
  ActiveExercise = c(9.50,10.00,9.75,9.75,9.00,13.00),
  NoExercise = c(11.50,12.00,13.25,11.50,13.00,9.00)
)

Our null hypothesis for this study will be that there is no difference in the time to walk between the two groups.

Null Hypothesis: \[H_0:{Median}_{Active} = {Median}_{No Exercise}\] Alternative Hypothesis: \[H_a:{Median}_{Active}<{Median}_{No Exercise}\]

A non-parametric method may be chosen for this study due to the small sample size, 6 per group, and the data may not follow a normal distribution or may not be symmetrical.

Mann-Whitney-U Test

We will conduct a Mann-whitney-U (wilcox.test) test using an alpha of 0.05.

#Use a wilcox.test with a confidence of .95 and alternative="less" since we expect Active<No Exercise
wilcox.test(dat2$ActiveExercise,dat2$NoExercise,conf.level = .95, alternative = "less")
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  dat2$ActiveExercise and dat2$NoExercise
## W = 9, p-value = 0.08523
## alternative hypothesis: true location shift is less than 0

Looking at the output of the test, we see that the p-value is greater than an alpha of .05, therefore we fail to reject the null hypothesis. This suggests that there is sufficient evidence that exercise will decrease the time to walk.

All Code

knitr::opts_chunk$set(echo=TRUE, warning=FALSE, message=FALSE)
#Input data using data.frame
#Concentration data for the aspirin samples, type A and type B.
dat<-data.frame(
  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)
)
t.test(dat$Aspirin_A,dat$Aspirin_B, paired=TRUE,conf.level = .95)
t.test(dat$Aspirin_A,dat$Aspirin_B, paired=FALSE, conf.level = .95)
#Input data using data.frame
dat2<-data.frame(
  ActiveExercise = c(9.50,10.00,9.75,9.75,9.00,13.00),
  NoExercise = c(11.50,12.00,13.25,11.50,13.00,9.00)
)

#Use a wilcox.test with a confidence of .95 and alternative="less" since we expect Active<No Exercise
wilcox.test(dat2$ActiveExercise,dat2$NoExercise,conf.level = .95, alternative = "less")