Setup Libraries

# Setup and Preallocation
# setup Libraries
library(dplyr)
library(knitr)
library(lawstat)
library(BSDA)

Setup Data Frame

# DataFrame for Problem 1
asprinUrine <- data.frame(
        persons = c(1:10),
        AsprinA = c(12,26,13,28,17,20,7,36,12,18),
        AsprinB = c(13,20,10,21,17,22,5,30,7,11))

# DataFrame for Problem 2

babyWalkers <- data.frame(
        activeExercise = c(9.5,10,9.75,9.75,9,13),
        noExercise     = c(11.5,12,13.25,11.5,13,9))

Problem 1

  1. 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.
  2. Test the hypothesis using a paired t-test, report the p-value and state your conclusion (alpha = 0.05)
  3. 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?

Part A

These are our following two hypothesis,

  • \(H_0: u_1 - u_2 = 0\)
  • \(H_1: u_1 - u_2 \neq 0\)

Part B

cor(asprinUrine$AsprinA,asprinUrine$AsprinB)
## [1] 0.9240307
t.test(asprinUrine$AsprinA,asprinUrine$AsprinB,paired = TRUE)
## 
##  Paired t-test
## 
## data:  asprinUrine$AsprinA and asprinUrine$AsprinB
## t = 3.0684, df = 9, p-value = 0.01339
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  0.8670853 5.7329147
## sample estimates:
## mean of the differences 
##                     3.3
  • \(\alpha = 0.05\)
  • \(p = 0.01339 < 0.05\)

Part C

t.test(asprinUrine$AsprinA,asprinUrine$AsprinB,var.equal = TRUE)
## 
##  Two Sample t-test
## 
## data:  asprinUrine$AsprinA and asprinUrine$AsprinB
## t = 0.88644, df = 18, p-value = 0.3871
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
##  -4.521214 11.121214
## sample estimates:
## mean of x mean of y 
##      18.9      15.6

These are our folloing two hypothesis,

  • \(H_0: u_1 - u_2 = 0\)
  • \(H_1: u_1 - u_2 \neq 0\)
  • \(\alpha = 0.05\)
  • \(p = 0.3871 > 0.05\)
  • Fail to reject Null.

Problem 2

  1. State the null and alternative hypothesis
  2. Why might you want to use a non-parametric method for analyzing this data?
  3. Analyze using the Mann-Whitney-U test using R with alpha=0.05

Part A

These are our folloing two hypothesis,

  • \(H_0: u_1 - u_2 = 0\)
  • \(H_1: u_1 - u_2 \neq 0\)

Part B

  We want to use a non-parametric method such as Mann-Whitney-U test, because the sample size per group is only six children.

Part C

qqnorm(c(babyWalkers$activeExercise,babyWalkers$noExercise))

wilcox.test(babyWalkers$activeExercise,babyWalkers$noExercise)
## 
##  Wilcoxon rank sum test with continuity correction
## 
## data:  babyWalkers$activeExercise and babyWalkers$noExercise
## W = 9, p-value = 0.1705
## alternative hypothesis: true location shift is not equal to 0
  • \(\alpha = 0.05\)
  • \(p = 0.1705 > 0.05\)
  Reject null, because \(p > 0.05\). This means there is a signification difference in means between the two groups of children.

Source Code

# setup Libraries
library(dplyr)
library(knitr)
library(lawstat)
library(BSDA)

# 1

# a)    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.  
# b)    Test the hypothesis using a paired t-test, report the p-value and state your conclusion (alpha = 0.05) 
# c)    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?  
        
asprinUrine <- data.frame(
        persons = c(1:10),
        AsprinA = c(12,26,13,28,17,20,7,36,12,18),
        AsprinB = c(13,20,10,21,17,22,5,30,7,11))

cor(asprinUrine$AsprinA,asprinUrine$AsprinB)

# a
# write stuff here

# b
t.test(asprinUrine$AsprinA,asprinUrine$AsprinB,paired = TRUE)

# u1 - u2 = 0
# p = 0.01339 > 0.005
# reject null

# c
t.test(asprinUrine$AsprinA,asprinUrine$AsprinB,var.equal = TRUE)

# u1 - u2 = 0
# p = 0.3871 > 0.005
# reject null again.
# make sure we do var.equal = TRUE

# 2
# a)    State the null and alternative hypothesis
# b)    Why might you want to use a non-parametric method for analyzing this data?
# c)    Analyze using the Mann-Whitney-U test using R with alpha=0.05

babyWalkers <- data.frame(
        activeExercise = c(9.5,10,9.75,9.75,9,13),
        noExercise     = c(11.5,12,13.25,11.5,13,9))

qqnorm(babyWalkers$activeExercise)
qqnorm(babyWalkers$noExercise)
qqnorm(c(babyWalkers$activeExercise,babyWalkers$noExercise))

# c
wilcox.test(babyWalkers$activeExercise,babyWalkers$noExercise)
# u1 - u2 = 0
# p = 0.1705 > 0.005
# reject null

Raw Data

kable(asprinUrine,caption = "Asprin Data")
Asprin Data
persons AsprinA AsprinB
1 12 13
2 26 20
3 13 10
4 28 21
5 17 17
6 20 22
7 7 5
8 36 30
9 12 7
10 18 11
kable(babyWalkers,caption = "Baby Walking Data")
Baby Walking Data
activeExercise noExercise
9.50 11.50
10.00 12.00
9.75 13.25
9.75 11.50
9.00 13.00
13.00 9.00