Skip to content

Commit

Permalink
update continuous outcome
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightbridge-KS committed Dec 17, 2023
1 parent f4ab694 commit 544a006
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 4 deletions.
4 changes: 2 additions & 2 deletions _freeze/contents/continuous/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"hash": "83bbfa63a075da4b5221db21df39f85d",
"hash": "6938aeac9b8f05812baedcbe9fec89a9",
"result": {
"markdown": "---\ntitle: \"Continuous Outcome\"\n---\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(pwr)\n```\n:::\n\n\n![R Packages and functions for sample size calculation [@sample_size_calc_clinical_R]](/pic/sample-size-pkg.png)\n\n## Comparing 2 groups\n\n### Overview\n\n`pwr.t.test()` function\n\n- One-sample t test (`type` = “one.sample”)\n- Two-sample t test (`type` = “two.sample”)\n- Paired t test (`type` = “paired”)\n\n**Cohen’s d** is used as the effect size\n\n- Very small (d = 0.01)\n- Small (d = 0.2)\n- Medium (d = 0.5)\n- Large (d = 0.8)\n- Very large (d = 1.2)\n- Huge (d = 2)\n\nIn the example below, I will be used these setting for default values:\n\n- Medium effect size\n- A two-tailed test\n- A significance of **0.05** and a power of **80%**\n\n\n### One-sample t-test \n\nCohen's d:\n\n$$\nd = \\frac{\\mu_1 - \\mu_0}{SD}\n$$\n\nWhere:\n\n- $\\mu_0$ = mean under $H_0$\n- $\\mu_1$ = mean under $H_1$\n- $SD$ = SD under $H_0$\n\n#### Ex 1: New dietary supplement\n\nDoes the introduction of a new dietary supplement reduce systolic blood pressure in patients with stage 1 hypertension more effectively than the currently recommended lifestyle modifications alone?\n\nThe primary outcome is the mean change in systolic blood pressure (mmHg) after a 12-week supplementation period.\n\nLet's assume a **medium** effect size ($d = 0.5$)\n\n\n::: {.cell}\n\n```{.r .cell-code}\ncohen.ES(test = \"t\", size = \"medium\")\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n\n Conventional effect size from Cohen (1982) \n\n test = t\n size = medium\n effect.size = 0.5\n```\n:::\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\npwr.t.test(d = 0.5, \n 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 One-sample t test power calculation \n\n n = 33.36713\n d = 0.5\n sig.level = 0.05\n power = 0.8\n alternative = two.sided\n```\n:::\n:::\n\n\n**N = 34** (If dropout rate of 20%, a total of 43 samples are required) \n\n\n#### Ex 2: New DM Drug\n\nLet’s propose a study of a new drug to reduce hemoglobin A1c in type 2 diabetes over a 1 year study period. You estimate that your recruited participants will have a mean baseline A1c of 9.0, which will be unchanged by your placebo, but reduced (on average) to 7.0 by the study drug.\n\nlet’s say 5.0 and 17.0 for min and max of Hgb A1c\n\n\n::: {.cell}\n\n```{.r .cell-code}\nsd_approx <- (17 - 5)/4\nd1 <- (9 - 7) / sd_approx # delta / sd\n\npwr.t.test(\n n = NULL,\n sig.level = 0.05,\n type = \"two.sample\",\n alternative = \"two.sided\",\n power = 0.80,\n d = d1\n)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n\n Two-sample t test power calculation \n\n n = 36.30569\n d = 0.6666667\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 = 37** in each group (Assuming a 20% dropout rate in each arm, would require 37*5/4 subjects per arm)\n\n\nIf study on 50 participants, what would the power be?\n\n\n::: {.cell}\n\n```{.r .cell-code}\npwr.t.test(\n n = 25, # note that n is per arm\n sig.level = 0.05,\n type = \"two.sample\",\n alternative = \"two.sided\",\n power = NULL, # ?\n d = 0.66\n)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n\n Two-sample t test power calculation \n\n n = 25\n d = 0.66\n sig.level = 0.05\n power = 0.6280322\n alternative = two.sided\n\nNOTE: n is number in *each* group\n```\n:::\n:::\n",
"markdown": "---\ntitle: \"Continuous Outcome\"\n---\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(pwr)\n```\n:::\n\n\n![R Packages and functions for sample size calculation, from [@sample_size_calc_clinical_R]](/pic/sample-size-pkg.png)\n\n## Comparing 2 groups\n\n### Overview\n\n`pwr.t.test()` function\n\n- One-sample t test (`type` = “one.sample”)\n- Two-sample t test (`type` = “two.sample”)\n- Paired t test (`type` = “paired”)\n\n**Cohen’s d** is used as the effect size\n\n- Very small (d = 0.01)\n- Small (d = 0.2)\n- Medium (d = 0.5)\n- Large (d = 0.8)\n- Very large (d = 1.2)\n- Huge (d = 2)\n\nIn the example below, I will be used these setting for default values:\n\n- Medium effect size\n- A two-tailed test\n- A significance of **0.05** and a power of **80%**\n\n\n### One-sample t-test \n\nCohen's d:\n\n$$\nd = \\frac{\\mu_1 - \\mu_0}{SD}\n$$\n\nWhere:\n\n- $\\mu_0$ = mean under $H_0$\n- $\\mu_1$ = mean under $H_1$\n- $SD$ = SD under $H_0$\n\n#### Ex 1: New dietary supplement\n\nDoes the introduction of a new dietary supplement reduce systolic blood pressure in patients with stage 1 hypertension more effectively than the currently recommended lifestyle modifications alone?\n\nThe primary outcome is the mean change in systolic blood pressure (mmHg) after a 12-week supplementation period.\n\nLet's assume a **medium** effect size ($d = 0.5$)\n\n\n::: {.cell}\n\n```{.r .cell-code}\ncohen.ES(test = \"t\", size = \"medium\")\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n\n Conventional effect size from Cohen (1982) \n\n test = t\n size = medium\n effect.size = 0.5\n```\n:::\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\npwr.t.test(d = 0.5, \n 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 One-sample t test power calculation \n\n n = 33.36713\n d = 0.5\n sig.level = 0.05\n power = 0.8\n alternative = two.sided\n```\n:::\n:::\n\n\n- **N = 34** \n- If dropout rate of 20%, a **total of 43 samples** are required\n\nFor non-parametric test: adding 15% gives a total of 65.\n\n\n#### Ex 2: New DM Drug\n\nLet’s propose a study of a new drug to reduce hemoglobin A1c in type 2 diabetes over a 1 year study period. You estimate that your recruited participants will have a mean baseline A1c of 9.0, which will be unchanged by your placebo, but reduced (on average) to 7.0 by the study drug.\n\nlet’s say 5.0 and 17.0 for min and max of Hgb A1c\n\n\n::: {.cell}\n\n```{.r .cell-code}\nsd_approx <- (17 - 5)/4\nd1 <- (9 - 7) / sd_approx # delta / sd\n\npwr.t.test(\n n = NULL,\n sig.level = 0.05,\n type = \"two.sample\",\n alternative = \"two.sided\",\n power = 0.80,\n d = d1\n)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n\n Two-sample t test power calculation \n\n n = 36.30569\n d = 0.6666667\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 = 37** in each group (Assuming a 20% dropout rate in each arm, would require 37*5/4 subjects per arm)\n\n\nIf study on 50 participants, what would the power be?\n\n\n::: {.cell}\n\n```{.r .cell-code}\npwr.t.test(\n n = 25, # note that n is per arm\n sig.level = 0.05,\n type = \"two.sample\",\n alternative = \"two.sided\",\n power = NULL, # ?\n d = 0.66\n)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n\n Two-sample t test power calculation \n\n n = 25\n d = 0.66\n sig.level = 0.05\n power = 0.6280322\n alternative = two.sided\n\nNOTE: n is number in *each* group\n```\n:::\n:::\n\n\n\n\n### Two-sample t-test\n\nCohen's d for Welch:\n\n$$\nd = \\frac{ \\mu_1 - \\mu_2 }{SD_{pool}} \n$$\n\nWhere\n\n$$\nSD_{pool} = \\sqrt{ (SD_1^2 + SD_2^2)/2 }\n$$\n\n\n::: {.cell}\n\n```{.r .cell-code}\npwr.t.test(d = 0.5, sig.level = 0.05, power = 0.8, \n type = \"two.sample\",\n alternative = \"two.sided\")\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n\n Two-sample t test power calculation \n\n n = 63.76561\n d = 0.5\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\nAssuming a p-value of 0.05 and a power of 80% in a two-tailed test, when the effect size d = 0.5\n\n- **N = 64 x 2** \n\n- If dropout rate of 20%, **Total = 160**\n\n\n**Mann-Whitney U test:**\n\n- For non-parametric test add an additional 15% for each group would give a total of 240 people.\n\n\n### Paired t-test\n\n\n::: {.cell}\n\n```{.r .cell-code}\npwr.t.test(d = 0.5, sig.level = 0.05, power = 0.8, \n type = \"paired\",\n alternative = \"two.sided\")\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n\n Paired t test power calculation \n\n n = 33.36713\n d = 0.5\n sig.level = 0.05\n power = 0.8\n alternative = two.sided\n\nNOTE: n is number of *pairs*\n```\n:::\n:::\n\n\nAssuming a p-value of 0.05 and a power of 80% in a two-tailed test, the minimum number of pairs required to demonstrate statistical significance is 34 when the effect size d = 0.5. \n\nConsidering the dropout rate of 20%, a total of **43 pairs** are required.\n\n**Paired Wilcoxon test**\n\n- For non-parametric test, add an additional 15%, the total 65 pairs are required\n\n## Comparing ≥3 groups\n\n\n### ANOVA (Parametric)\n\nStudies that compare averages of three or more groups. \n\n- `k`: number of comparison groups\n- `f`: means the effect size (Cohen's $f$)\n\n$$\nf = \\sqrt{ \\frac{ \\sum_{i=1}^{k} p_i \\times (\\mu_i - \\mu)^2 }{\\sigma^2} }\n$$\n\n\n**Effect Size (f-values)**\n\n- Small = 0.1\n- Medium = 0.25\n- Large = 0.4\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\ncohen.ES(test = \"anov\", size = \"medium\")\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n\n Conventional effect size from Cohen (1982) \n\n test = anov\n size = medium\n effect.size = 0.25\n```\n:::\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\npwr.anova.test (k = 3 , f = 0.25, sig.level = 0.05, power = 0.8)\n```\n\n::: {.cell-output .cell-output-stdout}\n```\n\n Balanced one-way analysis of variance power calculation \n\n k = 3\n n = 52.3966\n f = 0.25\n sig.level = 0.05\n power = 0.8\n\nNOTE: n is number in each group\n```\n:::\n:::\n\n\nAssume that the p-value is 0.05, the power is 80%, and the two-tailed test is performed. When the total comparison group was three groups and the effect size value was 0.25, the number of subjects calculated was **53** in each group. \n\nConsidering a dropout rate of 20%, a **total of 198 samples** are required, which is calculated as 66 per group.\n\n### Kruskal-Wallis test (Non-parametric)\n\n\nFor non-parametric test, add an additional 15% of each group\n",
"supporting": [],
"filters": [
"rmarkdown/pagebreak.lua"
Expand Down
94 changes: 92 additions & 2 deletions contents/continuous.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ library(here)
library(pwr)
```

![R Packages and functions for sample size calculation [@sample_size_calc_clinical_R]](/pic/sample-size-pkg.png)
![R Packages and functions for sample size calculation, from [@sample_size_calc_clinical_R]](/pic/sample-size-pkg.png)

## Comparing 2 groups

Expand Down Expand Up @@ -74,7 +74,10 @@ pwr.t.test(d = 0.5,
type = "one.sample", alternative = "two.sided")
```

**N = 34** (If dropout rate of 20%, a total of 43 samples are required)
- **N = 34**
- If dropout rate of 20%, a **total of 43 samples** are required

For non-parametric test: adding 15% gives a total of 65.


#### Ex 2: New DM Drug
Expand Down Expand Up @@ -115,3 +118,90 @@ pwr.t.test(



### Two-sample t-test

Cohen's d for Welch:

$$
d = \frac{ \mu_1 - \mu_2 }{SD_{pool}}
$$

Where

$$
SD_{pool} = \sqrt{ (SD_1^2 + SD_2^2)/2 }
$$

```{r}
pwr.t.test(d = 0.5, sig.level = 0.05, power = 0.8,
type = "two.sample",
alternative = "two.sided")
```

Assuming a p-value of 0.05 and a power of 80% in a two-tailed test, when the effect size d = 0.5

- **N = 64 x 2**

- If dropout rate of 20%, **Total = 160**


**Mann-Whitney U test:**

- For non-parametric test add an additional 15% for each group would give a total of 240 people.


### Paired t-test

```{r}
pwr.t.test(d = 0.5, sig.level = 0.05, power = 0.8,
type = "paired",
alternative = "two.sided")
```

Assuming a p-value of 0.05 and a power of 80% in a two-tailed test, the minimum number of pairs required to demonstrate statistical significance is 34 when the effect size d = 0.5.

Considering the dropout rate of 20%, a total of **43 pairs** are required.

**Paired Wilcoxon test**

- For non-parametric test, add an additional 15%, the total 65 pairs are required

## Comparing ≥3 groups


### ANOVA (Parametric)

Studies that compare averages of three or more groups.

- `k`: number of comparison groups
- `f`: means the effect size (Cohen's $f$)

$$
f = \sqrt{ \frac{ \sum_{i=1}^{k} p_i \times (\mu_i - \mu)^2 }{\sigma^2} }
$$


**Effect Size (f-values)**

- Small = 0.1
- Medium = 0.25
- Large = 0.4


```{r}
cohen.ES(test = "anov", size = "medium")
```


```{r}
pwr.anova.test (k = 3 , f = 0.25, sig.level = 0.05, power = 0.8)
```

Assume that the p-value is 0.05, the power is 80%, and the two-tailed test is performed. When the total comparison group was three groups and the effect size value was 0.25, the number of subjects calculated was **53** in each group.

Considering a dropout rate of 20%, a **total of 198 samples** are required, which is calculated as 66 per group.

### Kruskal-Wallis test (Non-parametric)


For non-parametric test, add an additional 15% of each group

0 comments on commit 544a006

Please sign in to comment.