Skip to content

Commit c9de2f7

Browse files
authored
Merge pull request #398 from PSIAIMS/sample_size
Sample size for NI - first commit
2 parents f53d2d2 + 9cbe1a3 commit c9de2f7

File tree

5 files changed

+133
-15
lines changed

5 files changed

+133
-15
lines changed

R/sample_s_superiority.qmd

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
title: "Sample size for superiority studies"
3+
---
4+
5+
### **Introduction about sample size calculations**
6+
7+
For determination of the sample size, in most cases, all of the below parameters will be required to perform the calculations:
8+
9+
- Power
10+
11+
- clinically relevant/significant difference
12+
13+
- alpha (α)
14+
15+
- beta (β)
16+
17+
- Effect size (Cohen's d) (required only in some R packages), can be defined as:
18+
19+
Difference between the means divided by the pooled standard deviation. In general, 0.2 can be considered a small effect, 0.5 a medium effect and 0.8 a large effect.
20+
21+
```{r}
22+
#| echo: false
23+
#| include: false
24+
library(samplesize)
25+
library(pwr)
26+
library(knitr)
27+
library(stats)
28+
29+
knitr::opts_chunk$set(echo = TRUE)
30+
31+
```
32+
33+
### Superiority studies {.unnumbered}
34+
35+
Superiority trials aim to prove that the investigated treatment is better than the comparator. The null hypothesis states that is no difference between the treatments and the alternative that there is some difference between the treatments (difference ≠ 0).
36+
37+
#### Calculations in R {.unnumbered}
38+
39+
Can be performed in 3 packages in R: **samplesize**, **stats** and **pwr**.
40+
41+
### Comparing means for parallel design (unpaired) {.unnumbered}
42+
43+
In the most common scenario SDs are known and the same. Otherwise Student t distribution is used instead of the normal distribution. Then approach between SAS and R is different - SAS follows only the Satterthwaite method, whilst in R both, Satterthwaiteand Welch one are available. The results differ slightly.
44+
45+
Primarily, we will consider the case with the same SDs.
46+
47+
#### Example {.unnumbered}
48+
49+
A client is interested in conducting a clinical trial to compare two cholesterol lowering agents for treatment of hypercholesterolemic patients. The primary efficacy parameter is a low-density lipidprotein cholesterol (LDL-C). Suppose that a difference of 8% in the percent change of LDL-C is considered a clinically meaningful difference and that the standard deviation is assumed to be 15%. What sample size is required for a two-sided false positive rate of 5% and a power of 80%?
50+
51+
```{r}
52+
# samplesize:
53+
n.ttest(power = 0.8, alpha = 0.05, mean.diff = 8, sd1 = 15,
54+
k = 1, design = "unpaired", fraction = "balanced", variance = "equal")
55+
56+
#stats:
57+
power.t.test(delta=8, sd=15, sig.level=0.05, power=0.8,
58+
type="two.sample", alternative="two.sided")
59+
60+
#pwr:
61+
pwr.t.test(d = 8/15, sig.level = 0.05, power = 0.80,
62+
type = "two.sample", alternative = "two.sided")
63+
64+
```
65+
66+
### Comparing means for crossover design (paired) {.unnumbered}
67+
68+
It is important to differenciate here between the within patient SD and the SD of the difference. We may need to recalculate one to the other, depending on the case.
69+
70+
Variance of the difference = 2x Variance within patient. $$Var_{diff} = 2 * Var_{patient}$$
71+
72+
#### Example
73+
74+
We wish to run an AB/BA single dose crossover to compare two brochodilators. The primary outcome is peak expiratory flow, and a clinically relevant difference of 30 l/min is sought with 80% power, the significance level is 5% and the best estimate of the within patient standard deviation is 32 l/min. What size of trial do we require?
75+
76+
(After recalculating: $$32 * \sqrt{2} = 45$$)
77+
78+
```{r}
79+
# samplesize:
80+
n.ttest(power = 0.8, alpha = 0.05, mean.diff = 30, sd1 = 45,
81+
k = 1, design = "paired", fraction = "balanced")
82+
83+
#stats:
84+
power.t.test(delta=30, sd=45, sig.level=0.05, power=0.8,
85+
type="one.sample", alternative="two.sided")
86+
87+
#pwr:
88+
pwr.t.test(d = 30/45, sig.level = 0.05, power = 0.80,
89+
type = "one.sample", alternative = "two.sided")
90+
91+
```
92+
93+
#### References {.unnumbered}
94+
95+
Majority of the examples are taken from: *Chow SC, Liu JP (1998). Design and analysis of clinical trials. Concepts and methodologies. Wiley, New York.*
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"hash": "b363a48d75978a2ab31683a8026349e7",
3+
"result": {
4+
"engine": "knitr",
5+
"markdown": "---\ntitle: \"Sample size for superiority studies\"\n---\n\n\n\n### **Introduction about sample size calculations**\n\nFor determination of the sample size, in most cases, all of the below parameters will be required to perform the calculations:\n\n- Power\n\n- clinically relevant/significant difference\n\n- alpha (α)\n\n- beta (β)\n\n- Effect size (Cohen's d) (required only in some R packages), can be defined as:\n\n Difference between the means divided by the pooled standard deviation. In general, 0.2 can be considered a small effect, 0.5 a medium effect and 0.8 a large effect.\n\n\n\n\n\n\n\n### Superiority studies {.unnumbered}\n\nSuperiority trials aim to prove that the investigated treatment is better than the comparator. The null hypothesis states that is no difference between the treatments and the alternative that there is some difference between the treatments (difference ≠ 0).\n\n#### Calculations in R {.unnumbered}\n\nCan be performed in 3 packages in R: **samplesize**, **stats** and **pwr**.\n\n### Comparing means for parallel design (unpaired) {.unnumbered}\n\nIn the most common scenario SDs are known and the same. Otherwise Student t distribution is used instead of the normal distribution. Then approach between SAS and R is different - SAS follows only the Satterthwaite method, whilst in R both, Satterthwaiteand Welch one are available. The results differ slightly.\n\nPrimarily, we will consider the case with the same SDs.\n\n#### Example {.unnumbered}\n\nA client is interested in conducting a clinical trial to compare two cholesterol lowering agents for treatment of hypercholesterolemic patients. The primary efficacy parameter is a low-density lipidprotein cholesterol (LDL-C). Suppose that a difference of 8% in the percent change of LDL-C is considered a clinically meaningful difference and that the standard deviation is assumed to be 15%. What sample size is required for a two-sided false positive rate of 5% and a power of 80%?\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# samplesize:\nn.ttest(power = 0.8, alpha = 0.05, mean.diff = 8, sd1 = 15,\n k = 1, design = \"unpaired\", fraction = \"balanced\", variance = \"equal\")\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n$`Total sample size`\n[1] 114\n\n$`Sample size group 1`\n[1] 57\n\n$`Sample size group 2`\n[1] 57\n```\n\n\n:::\n\n```{.r .cell-code}\n#stats:\npower.t.test(delta=8, sd=15, sig.level=0.05, power=0.8, \n type=\"two.sample\", alternative=\"two.sided\")\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n\n Two-sample t test power calculation \n\n n = 56.16413\n delta = 8\n sd = 15\n sig.level = 0.05\n power = 0.8\n alternative = two.sided\n\nNOTE: n is number in *each* group\n```\n\n\n:::\n\n```{.r .cell-code}\n#pwr:\npwr.t.test(d = 8/15, sig.level = 0.05, power = 0.80, \n type = \"two.sample\", alternative = \"two.sided\")\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n\n Two-sample t test power calculation \n\n n = 56.164\n d = 0.5333333\n sig.level = 0.05\n power = 0.8\n alternative = two.sided\n\nNOTE: n is number in *each* group\n```\n\n\n:::\n:::\n\n\n\n### Comparing means for crossover design (paired) {.unnumbered}\n\nIt is important to differenciate here between the within patient SD and the SD of the difference. We may need to recalculate one to the other, depending on the case.\n\nVariance of the difference = 2x Variance within patient. $$Var_{diff} = 2 * Var_{patient}$$\n\n#### Example\n\nWe wish to run an AB/BA single dose crossover to compare two brochodilators. The primary outcome is peak expiratory flow, and a clinically relevant difference of 30 l/min is sought with 80% power, the significance level is 5% and the best estimate of the within patient standard deviation is 32 l/min. What size of trial do we require?\n\n(After recalculating: $$32 * \\sqrt{2} = 45$$)\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# samplesize:\nn.ttest(power = 0.8, alpha = 0.05, mean.diff = 30, sd1 = 45,\n k = 1, design = \"paired\", fraction = \"balanced\")\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n$`Total sample size`\n[1] 20\n```\n\n\n:::\n\n```{.r .cell-code}\n#stats:\npower.t.test(delta=30, sd=45, sig.level=0.05, power=0.8, \n type=\"one.sample\", alternative=\"two.sided\")\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n\n One-sample t test power calculation \n\n n = 19.66697\n delta = 30\n sd = 45\n sig.level = 0.05\n power = 0.8\n alternative = two.sided\n```\n\n\n:::\n\n```{.r .cell-code}\n#pwr:\npwr.t.test(d = 30/45, sig.level = 0.05, power = 0.80, \n type = \"one.sample\", alternative = \"two.sided\")\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n\n One-sample t test power calculation \n\n n = 19.66695\n d = 0.6666667\n sig.level = 0.05\n power = 0.8\n alternative = two.sided\n```\n\n\n:::\n:::\n\n\n\n#### References {.unnumbered}\n\nMajority of the examples are taken from: *Chow SC, Liu JP (1998). Design and analysis of clinical trials. Concepts and methodologies. Wiley, New York.*\n",
6+
"supporting": [],
7+
"filters": [
8+
"rmarkdown/pagebreak.lua"
9+
],
10+
"includes": {},
11+
"engineDependencies": {},
12+
"preserve": {},
13+
"postProcess": true
14+
}
15+
}

_freeze/index/execute-results/html.json

Lines changed: 0 additions & 15 deletions
This file was deleted.

data/quarto_pkg_dependencies.csv

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,11 @@ R/rbmi_continuous_joint.qmd,tidyr,915fb7ce036c22a6a33b5a8adb712eb1
324324
R/rounding.qmd,dplyr,fedd9d00c2944ff00a0e2696ccf048ec
325325
R/rounding.qmd,janitor,5baae149f1082f466df9d1442ba7aa65
326326
R/rounding.qmd,rmarkdown,062470668513dcda416927085ee9bdc7
327+
R/sample_s_superiority.qmd,knitr,acf380f300c721da9fde7df115a5f86f
328+
R/sample_s_superiority.qmd,pwr,4.4.2
329+
R/sample_s_superiority.qmd,rmarkdown,062470668513dcda416927085ee9bdc7
330+
R/sample_s_superiority.qmd,samplesize,4.4.2
331+
R/sample_s_superiority.qmd,stats,4.4.2
327332
R/sample_size_average_bioequivalence.qmd,PowerTOST,8d3e612f2cb286a5d10044546220b92b
328333
R/sample_size_average_bioequivalence.qmd,data.table,fb24e05d4a91d8b1c7ff8e284bde834a
329334
R/sample_size_average_bioequivalence.qmd,knitr,acf380f300c721da9fde7df115a5f86f

renv.lock

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3547,6 +3547,17 @@
35473547
],
35483548
"Hash": "1cba04a4e9414bdefc9dcaa99649a8dc"
35493549
},
3550+
"pwr": {
3551+
"Package": "pwr",
3552+
"Version": "1.3-0",
3553+
"Source": "Repository",
3554+
"Repository": "CRAN",
3555+
"Requirements": [
3556+
"graphics",
3557+
"stats"
3558+
],
3559+
"Hash": "adfa41db3678b41bf9235c514c51799a"
3560+
},
35503561
"quadprog": {
35513562
"Package": "quadprog",
35523563
"Version": "1.5-8",
@@ -4018,6 +4029,13 @@
40184029
],
40194030
"Hash": "0bcf0c6f274e90ea314b812a6d19a519"
40204031
},
4032+
"samplesize": {
4033+
"Package": "samplesize",
4034+
"Version": "0.2-4",
4035+
"Source": "Repository",
4036+
"Repository": "CRAN",
4037+
"Hash": "37292a8728236c56fb0bd0c501281a87"
4038+
},
40214039
"sandwich": {
40224040
"Package": "sandwich",
40234041
"Version": "3.1-1",

0 commit comments

Comments
 (0)