1 Unpaired t-test

path_data <- "~/OneDrive - University of Saskatchewan/teaching/stat245_1909/rdemo/data"
addpath <- function (x) file.path(path_data,x)
survey <-  read.csv (addpath("survey.csv"))

t.test (survey$Age, mu = 23, altern = "less") 
## 
##  One Sample t-test
## 
## data:  survey$Age
## t = -6.2429, df = 236, p-value =
## 9.885e-10
## alternative hypothesis: true mean is less than 23
## 95 percent confidence interval:
##      -Inf 21.06899
## sample estimates:
## mean of x 
##  20.37451

2 Paired t-test

mental <- read.csv (addpath("mental.csv") )

sub <- mental$Treat=="025-050R"

scatterplot

matplot(mental[sub,1:2], pch=c(1,2), xlab = "Patient Index")

Unpaired t-test

t.test(mental[sub,1], mental[sub,2], alternative = "greater")
## 
##  Welch Two Sample t-test
## 
## data:  mental[sub, 1] and mental[sub, 2]
## t = 0.18497, df = 34.912, p-value =
## 0.4272
## alternative hypothesis: true difference in means is greater than 0
## 95 percent confidence interval:
##  -6.850349       Inf
## sample estimates:
## mean of x mean of y 
##  52.26316  51.42105

Paired t-test

t.test(mental[sub,1], mental[sub,2], alternative = "greater", paired = TRUE)
## 
##  Paired t-test
## 
## data:  mental[sub, 1] and mental[sub, 2]
## t = 0.61153, df = 18, p-value = 0.2742
## alternative hypothesis: true mean difference is greater than 0
## 95 percent confidence interval:
##  -1.545793       Inf
## sample estimates:
## mean difference 
##       0.8421053
sub <- mental$Treat=="075-125R"

scatterplot

matplot(mental[sub,1:2], pch=c(1,2), xlab = "Patient Index")

Unpaired t-test

t.test(mental[sub,1], mental[sub,2], alternative = "greater")
## 
##  Welch Two Sample t-test
## 
## data:  mental[sub, 1] and mental[sub, 2]
## t = 2.0165, df = 33.357, p-value =
## 0.02593
## alternative hypothesis: true difference in means is greater than 0
## 95 percent confidence interval:
##  1.341712      Inf
## sample estimates:
## mean of x mean of y 
##  46.61111  38.27778

Paired t-test

t.test(mental[sub,1], mental[sub,2], alternative = "greater", paired = TRUE)
## 
##  Paired t-test
## 
## data:  mental[sub, 1] and mental[sub, 2]
## t = 5.233, df = 17, p-value = 3.375e-05
## alternative hypothesis: true mean difference is greater than 0
## 95 percent confidence interval:
##  5.563069      Inf
## sample estimates:
## mean difference 
##        8.333333
sub <- mental$Treat=="125-250R"

scatterplot

matplot(mental[sub,1:2], pch=c(1,2), xlab = "Patient Index")

Unpaired t-test

t.test(mental[sub,1], mental[sub,2], alternative = "greater")
## 
##  Welch Two Sample t-test
## 
## data:  mental[sub, 1] and mental[sub, 2]
## t = 3.6578, df = 41.987, p-value =
## 0.0003517
## alternative hypothesis: true difference in means is greater than 0
## 95 percent confidence interval:
##  8.51998     Inf
## sample estimates:
## mean of x mean of y 
##  51.36364  35.59091

Paired t-test

t.test(mental[sub,1], mental[sub,2], alternative = "greater", paired = TRUE)
## 
##  Paired t-test
## 
## data:  mental[sub, 1] and mental[sub, 2]
## t = 15.844, df = 21, p-value = 1.864e-13
## alternative hypothesis: true mean difference is greater than 0
## 95 percent confidence interval:
##  14.0597     Inf
## sample estimates:
## mean difference 
##        15.77273