One method for assessing the bioavailability of a drug is to note its concentration in blood and/or urine samples at certain periods of time after the drug is given. Suppose we want to compare the concentrations of two types of aspirin (types A and B) in urine specimens taken from the same person 1 hour after he or she has taken the drug. Hence, a specific dosage of either type A or type B aspirin is given at one time and the 1-hour urine concentration is measured.
One week later, after the first aspirin has presumably been cleared from the system, the same dosage of the other aspirin is given to the same person and the 1-hour urine concentration is noted. Because the order of giving the drugs may affect the results, a table of random numbers is used to decide which of the two types of aspirin to give first. This experiment is performed on 10 people; the results are given in the following data frame.
dat<-data.frame(
Subject = c(1,2,3,4,5,6,7,8,9,10),
Aspirin_type_A = c(15,26,13,28,17,20,7,36,12,18),
Aspirin_type_B = c(13,20,10,21,17,22,5,30,7,11))
qqnorm(dat$Aspirin_type_A, xlab = "Type A Samples ", main = "Normal Probability Type A")
qqline(dat$Aspirin_type_A, col = "yellow", lwd = 2)
qqnorm(dat$Aspirin_type_B, xlab = "Type B Samples ", main = "Normal Probability Type B")
qqline(dat$Aspirin_type_B, col = "orange", lwd = 2)
From the NPP graphs we can observe that both samples can be considered as a Normal Distribution.
Our null and alternate hypothesis is:
\[\begin{array}{l} {H_0}:{\mu _a} = {\mu _b}\\ {H_a}:{\mu _a} \neq {\mu _b} \end{array}\]
Where \[{\mu _a}\] is the mean for the Aspirin A and \[{\mu _b}\] is the mean for the Aspirin B.
t.test(dat$Aspirin_type_A,dat$Aspirin_type_B, paired=TRUE,conf.level = .95)
##
## Paired t-test
##
## data: dat$Aspirin_type_A and dat$Aspirin_type_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
From the paired t-test will obtain a p value of 0.005121. This value is much less than the confidence test level of 0.05. From this p-value we would fail to accept the null hypothesis and conclude their is very strong evidence that the two types of aspirin have different urine concentrations.
t.test(dat$Aspirin_type_A,dat$Aspirin_type_B, paired=FALSE, conf.level = .95)
##
## Welch Two Sample t-test
##
## data: dat$Aspirin_type_A and dat$Aspirin_type_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
From the two sample 2 test, we obtain a p-value of 0.3401 which is significantly greater than 0.05, so we would fail to reject the null hypothesis using the 2 sample t test. This show the danger coming to an incorrect conclusion when used truly paired data as 2 sample data.
Can active exercise shorten the time that it takes an infant to learn how to walk alone? Researchers randomly allocated 12 one-week old male infants from white, middle class families to one of two treatment groups. The active exercise group received stimulation of the walking reflexes for four 3-minute sessions each day from the beginning of the second week through the end of the eighth week. Those in the other group received no such stimulation. Is there sufficient evidence to conclude that the mean time to walk is less for children who receive Active Exercise versus No Exercise?
#Input data using data.frame
data_exercise<-data.frame(
active_exercise = c(9.50,10.00,9.75,9.75,9.00,13.00),
no_exercise = c(11.50,12.00,13.25,11.50,13.00,9.00)
)
Since we have a small sample size we will use a non-parametric method will be used in the analysis, the Wilcoxon rank and sum test. Our Null hypothesis will be that mean time to walk with exercise and the mean time to walk without exercise are equal. The alternate hypothesis will be that the mean times with exercise is less than the mean time without exercise.
#Use a wilcox.test we expect Active < No Exercise
wilcox.test(data_exercise$active_exercise,data_exercise$no_exercise,conf.level = .95, alternative = "less")
##
## Wilcoxon rank sum test with continuity correction
##
## data: data_exercise$active_exercise and data_exercise$no_exercise
## W = 9, p-value = 0.08523
## alternative hypothesis: true location shift is less than 0
The p-value result for the test is 0.08523 which exceeds 0.05, so we would fail to reject the null hypothesis. So there is evidence that exercise does assists in helping to learn to walk earlier than no exercise.Since 0.08523 is approximately 70% greater than 0.05, so this is a strong result.
Here is the source code for this assignment:
knitr::opts_chunk$set(echo = TRUE,warning=FALSE, message=FALSE)
dat<-data.frame(
Subject = c(1,2,3,4,5,6,7,8,9,10),
Aspirin_type_A = c(15,26,13,28,17,20,7,36,12,18),
Aspirin_type_B = c(13,20,10,21,17,22,5,30,7,11)
qqnorm(dat$Aspirin_type_A, xlab = "Type A Samples ", main = "Normal Probability Type A")
qqline(dat$Aspirin_type_A, col = "yellow", lwd = 2)
qqnorm(dat$Aspirin_type_B, xlab = "Type B Samples ", main = "Normal Probability Type B")
qqline(dat$Aspirin_type_B, col = "orange", lwd = 2)
t.test(dat$Aspirin_type_A,dat$Aspirin_type_B, paired=TRUE,conf.level = .95)
t.test(dat$Aspirin_type_A,dat$Aspirin_type_B, paired=FALSE, conf.level = .95)
#Input data using data.frame
data_exercise<-data.frame(
active_exercise = c(9.50,10.00,9.75,9.75,9.00,13.00),
no_exercise = c(11.50,12.00,13.25,11.50,13.00,9.00)
#Use a wilcox.test we expect Active < No Exercise
wilcox.test(data_exercise$active_exercise,data_exercise$no_exercise,conf.level = .95, alternative = "less")
)