-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSample size.Rmd
168 lines (136 loc) · 4.14 KB
/
Sample size.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
---
title: "Sample_size"
author: "Tada"
date: "May 5, 2017"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Sample size for tilapia challenge with francisella
Assumptions
```{r, eval=T}
# No of treatment groups: 2 live mutants + 6 recombinant mutants + 1 E. coli + 1 adjuvant
tx <- 10
# No replica per treatment: challenged
repli.ch <- 4
## No replica per treatment: not challenged
repli.uch <- 4
# Fish per replica
nfish <- 20
# Mortality (probability) control
p1 <- 0.9
q1 <- 1-p1
# Mortality (probability) vaccinated
p2 <- 0.3
q2 <- 1-p2
# Common prob
p <- mean(c(p1, p2))
q <- 1-p
```
Confidence and power required
```{r, eval=T}
# alpha (probability of type I error)
alpha <- 0.05
confidence <- 1-alpha/2
# beta (probability of type II error)
beta <- 0.2
# Power (1 - beta)
pow <- 1 - beta
# Standard normal of alpha
za <- qnorm(confidence, 0, 1)
# Standard normal of power
zb <- qnorm(pow, 0, 1, lower.tail=F)
```
Sample size per group, without accounting for clustering within tanks
```{r, eval=T}
n <- (za*sqrt(2*p*q) - zb*sqrt(p1*q1 + p2*q2)) / (p1 - p2)^2
```
Sample size accounting for clustering within tanks, with three levels of intra-class correlation (ICC): 0.3, 0.5, 0.7, 0.9
```{r, eval=T}
# ICC of 0.3, 0.5, 0.7, 0.9
rho1 <- 0.3
rho2 <- 0.5
rho3 <- 0.78
rho4 <- 0.9
# Sample size for each ICC
nprime_0.3 <- n*(1+rho1*(nfish-1))
nprime_0.5 <- n*(1+rho2*(nfish-1))
nprime_0.7 <- n*(1+rho3*(nfish-1))
nprime_0.9 <- n*(1+rho4*(nfish-1))
# Number of tanks (rounding up) required for each ICC, stocking 20 fish per tank
ntanks <- ceiling(c(nprime_0.3, nprime_0.5, nprime_0.7, nprime_0.9)/nfish)
# Making a table from this
ICC <- c(rho1, rho2, rho3, rho4)
nprime <- ceiling(c(nprime_0.3, nprime_0.5, nprime_0.7, nprime_0.9))
samples <- data.frame(ICC, nprime, ntanks)
colnames(samples) <- c("ICC", "No of fish per group", "No tanks per group")
```
###Sample size for different levels of ICC: challenge trial
``` {r, eval=T, echo=F}
samples
```
# Sample size for estimating expression of cytokines (Ct values)
Assumptions
```{r, eval=T}
# No of treatment groups: best oral + best immersion + 1 E. coli + 1 adjuvant
tx <- 4
# No replica per treatment: challenged
repli.ch <- 4
# Fish per replica
nfish <- 5
# Range of Ct values
Ctmin <- 20
Ctmax <- 40
rangect <- Ctmax - Ctmin
# Approximation of variance of Ct values
sigma <- rangect/4
sigma2 <- sigma^2
# Delta Ct (difference between Ct values)
delta <- 5
```
###Sample size per group, without accounting for clustering within tanks
```{r, eval=T}
n <- 2*(((za-zb)^2)*sigma2/delta^2)
ceiling(n)
```
Sample size accounting for clustering within tanks, with three levels of intra-class correlation (ICC): 0.3, 0.5, 0.7, 0.9
```{r, eval=T}
# Sample size for each ICC
nprime_0.3 <- n*(1+rho1*(nfish-1))
nprime_0.5 <- n*(1+rho2*(nfish-1))
nprime_0.7 <- n*(1+rho3*(nfish-1))
nprime_0.9 <- n*(1+rho4*(nfish-1))
# Number of tanks (rounding up) required for each ICC, stocking 20 fish per tank
ntanks <- ceiling(c(nprime_0.3, nprime_0.5, nprime_0.7, nprime_0.9)/nfish)
# Making a table from this
ICC <- c(rho1, rho2, rho3, rho4)
nprime <- ceiling(c(nprime_0.3, nprime_0.5, nprime_0.7, nprime_0.9))
samples <- data.frame(ICC, nprime, ntanks)
colnames(samples) <- c("ICC", "No of fish per group", "No tanks per group")
```
### Sample size for different levels of ICC: gene expression trial
```{r, eval=T, echo=F}
samples
```
Now assuming 20 fish per tank
```{r, eval=T}
# No fish per tank
nfish <- 20
# Sample size for each ICC
nprime_0.3 <- n*(1+rho1*(nfish-1))
nprime_0.5 <- n*(1+rho2*(nfish-1))
nprime_0.7 <- n*(1+rho3*(nfish-1))
nprime_0.9 <- n*(1+rho4*(nfish-1))
# Number of tanks (rounding up) required for each ICC, stocking 20 fish per tank
ntanks <- ceiling(c(nprime_0.3, nprime_0.5, nprime_0.7, nprime_0.9)/nfish)
# Making a table from this
ICC <- c(rho1, rho2, rho3, rho4)
nprime <- ceiling(c(nprime_0.3, nprime_0.5, nprime_0.7, nprime_0.9))
samples <- data.frame(ICC, nprime, ntanks)
colnames(samples) <- c("ICC", "No of fish per group", "No tanks per group")
```
### Sample size for different levels of ICC: gene expression trial with tanks of 20 fish each
```{r, eval=T, echo=F}
samples
```