One method for assessing the bio-availability 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 table.
person<-c(1,2,3,4,5,6,7,8,9,10)
aspirina<-c(15,26,13,28,17,20,7,36,12,18)
aspirinb<-c(13,20,10,21,17,22,5,30,7,11)
dat1<-data.frame(person,aspirina,aspirinb)
colnames(dat1)[1:3]<-c("Person","Aspirin A","Aspirin B")
dat1
## 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
Suppose we want to test the hypothesis that the mean concentrations of the two drugs are the same in urine specimens. State the appropriate hypothesis.
Null Hypothesis \[H_{0}:\mu _{1}= \mu_{2}\]
Alternative Hypothesis \[H_{0}:\mu _{1}\neq\mu_{2}\]
Where: \[\mu_{1}=mean\ concentration\ of\ Aspirin\ A\] \[\mu_{2}=mean\ concentration\ of\ Aspirin\ B \]
Test the hypothesis using a paired t-test, report the p-value and state your conclusion (alpha = 0.05)
Before determining which T test method will be utilized to test the hypothesis, the data will be analyzed to determine if it is normally distributed and if the variance is equal across the two data sets, Aspirin A and Aspirin B.
qqnorm(aspirina, main = "Aspirin A Q-Q Plot", ylab = "mg%")
qqline(aspirina)
qqnorm(aspirinb, main = "Aspirin B Q-Q Plot", ylab = "mg%")
qqline(aspirinb)
The data appears to be normally distributed for both Aspirin A and Aspirin B. All data points appear to follow a linear trend; therefore, it can be assumed that the data is normally distributed.
boxplot(aspirina,aspirinb,
names = c("Aspirin A","Aspirin B"),
main = "Box Plot - Aspirin A vs. Aspirin B",
ylab = "1-Hour Concentration (mg%)",
col = c("red","blue"))
Looking at the inner quartile range of the two box plots, it is evident that Aspirin A is larger than Aspirin B. It can be assumed based on these results that the variance is not constant across the two samples.
Because the data is normally distributed and the variance is not equal, the Welch’s T Test will be utilized to test the null and alternative hypothesis. For this t test, paired = TRUE since the participants of the experiment took both Aspirin samples in random order. Var.equal = FALSE was utilized since the variance is not equal and the Welch’s T Test will be used.
t.test(aspirina, aspirinb, alternative = "two.sided",
paired = TRUE, var.equal = FALSE, conf.level = 0.95)
##
## Paired t-test
##
## data: aspirina and aspirinb
## 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
The T Test P value = 0.005121 is less than the significance level of 0.05; therefore, there is overwhelming evidence that the null hypothesis can be rejected and that the mean mg% of the two Aspirin types is different.
Suppose that you tested this hypothesis using a two-sample t-test (instead of a paired t-test). What would the p-value of your test have been?
t.test(aspirina,aspirinb, alternative = "two.sided",
paired = FALSE, var.equal = FALSE, conf.level = 0.95)
##
## Welch Two Sample t-test
##
## data: aspirina and aspirinb
## 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
The p-value of this two sample t test = 0.3401 which is higher than alpha of 0.05. This indicates that we do not have sufficient evidence to reject the null hypothesis that the mean concentrations of the two aspirins differ.
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?
active<-c(9.50,10.00,9.75,9.75,9.00,13.00)
normal<-c(11.50,12.00,13.25,11.50,13.00,9.00)
dat2<-data.frame(active,normal)
colnames(dat2)[1:2]<-c("Active Exercise","No Exercise")
dat2
## 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
State the null and alternative hypothesis
Null Hypothesis \[H_{0}:\mu _{1}= \mu_{2}\]
Alternative Hypothesis \[H_{0}:\mu _{1}< \mu_{2}\]
Where:
\[\mu_{1}= mean\ of\ active\ exercise\ samples \] \[\mu_{2}=mean\ of\ no\ exercise\ samples \]
Why might you want to use a non-parametric method for analyzing this data?
Due to the size of the two data sets, six samples each, the Non-Parametric Method is preferred. With these small sample sizes, it is impossible to determine if the data is normally distributed and normality cannot be assumed in this case.
Analyze using the Mann-Whitney-U test using R with alpha=0.05
wilcox.test(active, normal, alternative = "less",
mu = 0, paired = FALSE, conf.level = 0.95)
##
## Wilcoxon rank sum exact test
##
## data: active and normal
## W = 9, p-value = 0.09524
## alternative hypothesis: true location shift is less than 0
The P-value from this Mann-Whitney test equals 0.09524 which is greater than the level of significance of 0.05. Based on these results there is not overwhelming evidence to reject the null hypothesis. Therefore we cannot conclude that there is a mean difference in the time to walking in infants that participate in active exercise versus those that do not.
It is a good idea to include this at the end of every RMarkdown document
# Question #1
# Experiment Data
person<-c(1,2,3,4,5,6,7,8,9,10)
aspirina<-c(15,26,13,28,17,20,7,36,12,18)
aspirinb<-c(13,20,10,21,17,22,5,30,7,11)
dat1<-data.frame(person,aspirina,aspirinb)
colnames(dat1)[1:3]<-c("Person","Aspirin A","Aspirin B")
dat1
# Check for normality
qqnorm(aspirina, main = "Aspirin A Q-Q Plot", ylab = "mg%")
qqline(aspirina)
qqnorm(aspirinb, main = "Aspirin B Q-Q Plot", ylab = "mg%")
qqline(aspirinb)
# check for constant variance
boxplot(aspirina,aspirinb,
names = c("Aspirin A","Aspirin B"),
main = "Box Plot - Aspirin A vs. Aspirin B",
ylab = "1-Hour Concentration (mg%)",
col = c("red","blue"))
# Paired t test
t.test(aspirina, aspirinb, alternative = "two.sided",
paired = TRUE, var.equal = FALSE, conf.level = 0.95)
# two sample t test
t.test(aspirina,aspirinb, alternative = "two.sided",
paired = FALSE, var.equal = FALSE, conf.level = 0.95)
# Question #2
# Experiment Data
active<-c(9.50,10.00,9.75,9.75,9.00,13.00)
normal<-c(11.50,12.00,13.25,11.50,13.00,9.00)
dat2<-data.frame(active,normal)
colnames(dat2)[1:2]<-c("Active Exercise","No Exercise")
dat2
# Mann-Whitney U test (non parametric test)
wilcox.test(active, normal, alternative = "less",
mu = 0, paired = FALSE, conf.level = 0.95)