## Settings for RMarkdown http://yihui.name/knitr/options#chunk_options
opts_chunk$set(comment = "", warning = FALSE, message = FALSE, tidy = FALSE,
echo = TRUE, fig.width = 7, fig.height = 7)
options(width = 116, scipen = 10)
setwd("~/statistics/bio201/")
library(ggplot2)
References
## 7.7
power.t.test(n = 100, delta = 0.1, sd = 0.54, type = "one.sample")
One-sample t test power calculation
n = 100
delta = 0.1
sd = 0.54
sig.level = 0.05
power = 0.4498
alternative = two.sided
## 7.8
power.t.test(n = 100, delta = 0.2, sd = 0.54, type = "one.sample")
One-sample t test power calculation
n = 100
delta = 0.2
sd = 0.54
sig.level = 0.05
power = 0.9561
alternative = two.sided
## 7.9
power.t.test(n = NULL, delta = 0.1, sd = 0.54, power = 0.8, type = "one.sample")
One-sample t test power calculation
n = 230.8
delta = 0.1
sd = 0.54
sig.level = 0.05
power = 0.8
alternative = two.sided
## 7.23
library(BSDA)
res.t <- tsum.test(mean.x = 175, s.x = 35, n.x = 24, mu = 230, var.equal = TRUE)
res.t$p.value
[1] 0.0000000824
## 7.24
dat.mean <- 175
dat.sd <- 35
dat.n <- 24
dat.se <- dat.sd / sqrt(dat.n)
dat.qt <- qt(p = c(0.025, 0.975), df = dat.n - 1)
dat.mean + dat.qt * dat.se
[1] 160.2 189.8
res.t
One-sample t-Test
data: Summarized x
t = -7.698, df = 23, p-value = 0.0000000824
alternative hypothesis: true mean is not equal to 230
95 percent confidence interval:
160.2 189.8
sample estimates:
mean of x
175
## 7.25: Not done
## 7.51: One sample t-test
## 7.52
tsum.test(mean.x = 2.65, s.x = 0.11 * sqrt(20), n.x = 20, mu = 2.88, var.equal = TRUE)
One-sample t-Test
data: Summarized x
t = -2.091, df = 19, p-value = 0.05021
alternative hypothesis: true mean is not equal to 2.88
95 percent confidence interval:
2.42 2.88
sample estimates:
mean of x
2.65
## 7.53
power.t.test(power = 0.8, delta = 0.2, sd = 0.11 * sqrt(20), type = "one")
One-sample t test power calculation
n = 49.44
delta = 0.2
sd = 0.4919
sig.level = 0.05
power = 0.8
alternative = two.sided
## 7.73
library(foreign)
bone <- read.dta("BONEDEN.DAT.dta")
t.test(with(bone, fn2 - fn1))
One Sample t-test
data: with(bone, fn2 - fn1)
t = -0.0503, df = 40, p-value = 0.9601
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
-0.03013 0.02866
sample estimates:
mean of x
-0.0007317
## 7.74
t.test(with(bone, fs2 - fs1))
One Sample t-test
data: with(bone, fs2 - fs1)
t = -1.701, df = 40, p-value = 0.09663
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
-0.066704 0.005728
sample estimates:
mean of x
-0.03049
iop <- read.table(header = TRUE, text = "
pt.num IOPab IOPc
1 18.0 14.5
2 16.0 18.0
3 17.0 11.5
4 18.0 18.0
5 20.0 21.0
6 19.0 22.0
7 19.0 24.0
8 12.0 14.0
9 17.0 16.0
10 21.5 19.0
")
iop
pt.num IOPab IOPc
1 1 18.0 14.5
2 2 16.0 18.0
3 3 17.0 11.5
4 4 18.0 18.0
5 5 20.0 21.0
6 6 19.0 22.0
7 7 19.0 24.0
8 8 12.0 14.0
9 9 17.0 16.0
10 10 21.5 19.0
## 7.93
## Paired t-test or one sample t-test for difference
## 7.94
## Paired t-test
with(iop, t.test(IOPab, IOPc, paired = TRUE))
Paired t-test
data: IOPab and IOPc
t = -0.0493, df = 9, p-value = 0.9618
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-2.346 2.246
sample estimates:
mean of the differences
-0.05
## One-sample t-test for IOPa+b - IOPc
with(iop, t.test(IOPab - IOPc, var.equal = T))
One Sample t-test
data: IOPab - IOPc
t = -0.0493, df = 9, p-value = 0.9618
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
-2.346 2.246
sample estimates:
mean of x
-0.05
## 7.95
## Not the same as accepting null. Decide on two-sided margins of equivalence and see if the confidence interval sits within the margins (difference -2 to +2 in this case).
## 7.96: The confidence interval is not contained in the -2 to +2 margins, thus equivalence is not shown.
with(iop, t.test(IOPab - IOPc, var.equal = T))$conf
[1] -2.346 2.246
attr(,"conf.level")
[1] 0.95