Skip to content

Commit

Permalink
uplevel header
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightbridge-KS committed Oct 19, 2024
1 parent 89ac5b9 commit b84cf90
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
8 changes: 5 additions & 3 deletions _freeze/contents/desc-proportion/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"hash": "39af5c57db1221fd1132cd7abd8211aa",
"hash": "c4c069eb7767721df499b41fe68948d3",
"result": {
"engine": "knitr",
"markdown": "---\ntitle: \"Descriptive\"\n---\n\n\n\n\n\n\n\n\n\n\n## Population Proportion\n\n### Concept\n\nCochran's sample size calculation is a **design tool** for determining the appropriate sample size to estimate a population proportion. As such, it does not directly test a hypothesis like a statistical test (e.g., t-test or ANOVA). However, the underlying **null and alternative hypotheses** behind Cochran’s sample size calculation are implicitly related to ensuring a certain **level of precision** (margin of error) for estimating proportions.\n\nBelow are the conceptual **null and alternative hypotheses** for both **infinite population** and **finite population adjustments**.\n\n\n**1. Hypotheses for Infinite Population Proportion Sample Size Calculation**\n\n- **Goal:** Determine the minimum sample size needed to estimate a proportion ($p$) within a specified **margin of error (e)** and **confidence level (Z)** for a large population (assumed infinite).\n\n- **Null Hypothesis ($H_0$)**: The estimated proportion ($\\hat{p}$) **is not** within the desired margin of error ($e$) of the true population proportion ($p$) with the specified confidence level.\n\n- **Alternative Hypothesis ($H_1$)**: The estimated proportion ($\\hat{p}$) **is** within the desired margin of error ($e$) of the true population proportion ($p$) with the specified confidence level.\n\n\n**2. Hypotheses for Finite Population Adjustment**\n\nWhen calculating the sample size for a **finite population** size ($N$), we adjust the required sample size to account for the fact that the population is not infinitely large. This adjustment ensures efficiency (i.e., fewer participants required) without sacrificing precision.\n\n- **Null Hypothesis ($H_0$)**: The estimated proportion ($\\hat{p}$) **is not** within the desired margin of error ($e$) when adjusting for finite population size ($N$).\n\n- **Alternative Hypothesis ($H_1$)**: The estimated proportion ($\\hat{p}$) **is** within the desired margin of error ($e$) even with the adjustment for finite population size ($N$).\n\n\n### Cochran’s Sample Size for Infinite Proportion\n\nTo estimate the sample size for an **infinite population**, we use **Cochran’s sample size formula for proportions**:\n\n\n$$\nn_0 = \\frac{Z^2 \\cdot p \\cdot (1 - p)}{e^2}\n$$\n\n\n**Where:**\n\n- $n_0$: Initial sample size (assuming an infinite population)\n- $Z$: Z-value\n- $p$: Expected proportion of the population with the attribute (use 0.5 for maximum variability)\n- $e$: Margin of error ($e$ = 0.05)\n\n\nThe following R function implements Cochran’s formula:\n\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\ncochran_sample_size <- function(p, e, conf_level = 0.95) {\n \n Z <- qnorm(1 - (1 - conf_level) / 2) # Z-value for confidence level\n n0 <- (Z^2 * p * (1 - p)) / (e^2) # Cochran's formula\n ceiling(n0)\n \n}\n```\n:::\n\n\n\n\n\n\n#### Example\n\nLet’s say you want to calculate the required sample size to estimate a population proportion with: \n\n- **95% confidence level**\n- **Estimated proportion (p) = 0.5** (maximum variability)\n- **Margin of error (e) = 0.05**\n\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nn0 <- cochran_sample_size(\n p = 0.5, # Expected proportion (for maximum variability)\n e = 0.05, # Margin of error\n conf_level = 0.95 # 95% confidence level\n )\n\nn0\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] 385\n```\n\n\n:::\n:::\n\n\n\n\n\n### Finite Population Correction\n\nSince our study population is **finite**, we adjust the initial sample size using the **finite population correction formula**:\n\n$$\nn = \\frac{n_0}{1 + \\frac{n_0 - 1}{N}}\n$$\n\n**Where:**\n\n- $n$: Adjusted sample size\n- $N$: Total population size (total number of residents)\n\n\nR function to apply this correction:\n\n\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nfinite_pop_adj <- function(n0, N) {\n n <- n0 / (1 + (n0 - 1) / N)\n ceiling(n) \n}\n```\n:::\n\n\n\n\n\n#### Example\n\nFor a population of 1000, the required sample size is:\n\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nfinite_pop_adj(n0 = n0, N = 1000)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] 279\n```\n\n\n:::\n:::\n\n\n\n\n\nThis approach helps you compute the sample size needed to accurately estimate a population proportion with a given confidence and margin of error.\n\n",
"supporting": [],
"markdown": "---\ntitle: \"Population Proportion\"\n---\n\n\n\n\n\n\n\n## Concept\n\nCochran's sample size calculation is a **design tool** for determining the appropriate sample size to estimate a population proportion. As such, it does not directly test a hypothesis like a statistical test (e.g., t-test or ANOVA). However, the underlying **null and alternative hypotheses** behind Cochran’s sample size calculation are implicitly related to ensuring a certain **level of precision** (margin of error) for estimating proportions.\n\nBelow are the conceptual **null and alternative hypotheses** for both **infinite population** and **finite population adjustments**.\n\n\n**1. Hypotheses for Infinite Population Proportion Sample Size Calculation**\n\n- **Goal:** Determine the minimum sample size needed to estimate a proportion ($p$) within a specified **margin of error (e)** and **confidence level (Z)** for a large population (assumed infinite).\n\n- **Null Hypothesis ($H_0$)**: The estimated proportion ($\\hat{p}$) **is not** within the desired margin of error ($e$) of the true population proportion ($p$) with the specified confidence level.\n\n- **Alternative Hypothesis ($H_1$)**: The estimated proportion ($\\hat{p}$) **is** within the desired margin of error ($e$) of the true population proportion ($p$) with the specified confidence level.\n\n\n**2. Hypotheses for Finite Population Adjustment**\n\nWhen calculating the sample size for a **finite population** size ($N$), we adjust the required sample size to account for the fact that the population is not infinitely large. This adjustment ensures efficiency (i.e., fewer participants required) without sacrificing precision.\n\n- **Null Hypothesis ($H_0$)**: The estimated proportion ($\\hat{p}$) **is not** within the desired margin of error ($e$) when adjusting for finite population size ($N$).\n\n- **Alternative Hypothesis ($H_1$)**: The estimated proportion ($\\hat{p}$) **is** within the desired margin of error ($e$) even with the adjustment for finite population size ($N$).\n\n\n## Cochran’s Sample Size for Infinite Proportion\n\nTo estimate the sample size for an **infinite population**, we use **Cochran’s sample size formula for proportions**:\n\n\n$$\nn_0 = \\frac{Z^2 \\cdot p \\cdot (1 - p)}{e^2}\n$$\n\n\n**Where:**\n\n- $n_0$: Initial sample size (assuming an infinite population)\n- $Z$: Z-value\n- $p$: Expected proportion of the population with the attribute (use 0.5 for maximum variability)\n- $e$: Margin of error ($e$ = 0.05)\n\n\nThe following R function implements Cochran’s formula:\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\ncochran_sample_size <- function(p, e, conf_level = 0.95) {\n \n Z <- qnorm(1 - (1 - conf_level) / 2) # Z-value for confidence level\n n0 <- (Z^2 * p * (1 - p)) / (e^2) # Cochran's formula\n ceiling(n0)\n \n}\n```\n:::\n\n\n\n\n\n### Example\n\nLet’s say you want to calculate the required sample size to estimate a population proportion with: \n\n- **95% confidence level**\n- **Estimated proportion (p) = 0.5** (maximum variability)\n- **Margin of error (e) = 0.05**\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nn0 <- cochran_sample_size(\n p = 0.5, # Expected proportion (for maximum variability)\n e = 0.05, # Margin of error\n conf_level = 0.95 # 95% confidence level\n )\n\nn0\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] 385\n```\n\n\n:::\n:::\n\n\n\n\n## Finite Population Correction\n\nSince our study population is **finite**, we adjust the initial sample size using the **finite population correction formula**:\n\n$$\nn = \\frac{n_0}{1 + \\frac{n_0 - 1}{N}}\n$$\n\n**Where:**\n\n- $n$: Adjusted sample size\n- $N$: Total population size (total number of residents)\n\n\nR function to apply this correction:\n\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nfinite_pop_adj <- function(n0, N) {\n n <- n0 / (1 + (n0 - 1) / N)\n ceiling(n) \n}\n```\n:::\n\n\n\n\n### Example\n\nFor a population of 1000, the required sample size is:\n\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nfinite_pop_adj(n0 = n0, N = 1000)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] 279\n```\n\n\n:::\n:::\n\n\n\n\nThis approach helps you compute the sample size needed to accurately estimate a population proportion with a given confidence and margin of error.\n\n",
"supporting": [
"desc-proportion_files"
],
"filters": [
"rmarkdown/pagebreak.lua"
],
Expand Down
16 changes: 6 additions & 10 deletions contents/desc-proportion.qmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Descriptive"
title: "Population Proportion"
---


Expand All @@ -11,11 +11,7 @@ library(here)
```




## Population Proportion

### Concept
## Concept

Cochran's sample size calculation is a **design tool** for determining the appropriate sample size to estimate a population proportion. As such, it does not directly test a hypothesis like a statistical test (e.g., t-test or ANOVA). However, the underlying **null and alternative hypotheses** behind Cochran’s sample size calculation are implicitly related to ensuring a certain **level of precision** (margin of error) for estimating proportions.

Expand All @@ -40,7 +36,7 @@ When calculating the sample size for a **finite population** size ($N$), we adju
- **Alternative Hypothesis ($H_1$)**: The estimated proportion ($\hat{p}$) **is** within the desired margin of error ($e$) even with the adjustment for finite population size ($N$).


### Cochran’s Sample Size for Infinite Proportion
## Cochran’s Sample Size for Infinite Proportion

To estimate the sample size for an **infinite population**, we use **Cochran’s sample size formula for proportions**:

Expand Down Expand Up @@ -71,7 +67,7 @@ cochran_sample_size <- function(p, e, conf_level = 0.95) {
```


#### Example
### Example

Let’s say you want to calculate the required sample size to estimate a population proportion with:

Expand All @@ -89,7 +85,7 @@ n0 <- cochran_sample_size(
n0
```

### Finite Population Correction
## Finite Population Correction

Since our study population is **finite**, we adjust the initial sample size using the **finite population correction formula**:

Expand All @@ -113,7 +109,7 @@ finite_pop_adj <- function(n0, N) {
}
```

#### Example
### Example

For a population of 1000, the required sample size is:

Expand Down

0 comments on commit b84cf90

Please sign in to comment.