Skip to content

Commit d4f2b8e

Browse files
committed
example1
1 parent f8ad00a commit d4f2b8e

File tree

8 files changed

+377
-225
lines changed

8 files changed

+377
-225
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
^doc$
55
^Meta$
66
^readme\.html$
7+
^\.github$

.Rhistory

Lines changed: 224 additions & 224 deletions
Large diffs are not rendered by default.

.github/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.html

.github/workflows/R-CMD-check.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
2+
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
8+
name: R-CMD-check.yaml
9+
10+
permissions: read-all
11+
12+
jobs:
13+
R-CMD-check:
14+
runs-on: ${{ matrix.config.os }}
15+
16+
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
17+
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
config:
22+
- {os: macos-latest, r: 'release'}
23+
- {os: windows-latest, r: 'release'}
24+
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
25+
- {os: ubuntu-latest, r: 'release'}
26+
- {os: ubuntu-latest, r: 'oldrel-1'}
27+
28+
env:
29+
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
30+
R_KEEP_PKG_SOURCE: yes
31+
32+
steps:
33+
- uses: actions/checkout@v4
34+
35+
- uses: r-lib/actions/setup-pandoc@v2
36+
37+
- uses: r-lib/actions/setup-r@v2
38+
with:
39+
r-version: ${{ matrix.config.r }}
40+
http-user-agent: ${{ matrix.config.http-user-agent }}
41+
use-public-rspm: true
42+
43+
- uses: r-lib/actions/setup-r-dependencies@v2
44+
with:
45+
extra-packages: any::rcmdcheck
46+
needs: check
47+
48+
- uses: r-lib/actions/check-r-package@v2
49+
with:
50+
upload-snapshots: true
51+
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'

R/svytable1.R

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,54 @@
4242
#' @import stats
4343
#'
4444
#' @export
45+
#'
46+
#' @examples
47+
#' # Ensure required packages are loaded
48+
#' if (requireNamespace("survey", quietly = TRUE) &&
49+
#' requireNamespace("NHANES", quietly = TRUE) &&
50+
#' requireNamespace("dplyr", quietly = TRUE)) {
51+
#'
52+
#' # 1. Prepare Data using NHANES
53+
#' data(NHANESraw, package = "NHANES")
54+
#' nhanes_adults_with_na <- NHANESraw %>%
55+
#' dplyr::filter(Age >= 20) %>%
56+
#' dplyr::mutate(
57+
#' ObeseStatus = factor(ifelse(BMI >= 30, "Obese", "Not Obese"),
58+
#' levels = c("Not Obese", "Obese"))
59+
#' )
60+
#'
61+
#' adult_design_with_na <- survey::svydesign(
62+
#' id = ~SDMVPSU,
63+
#' strata = ~SDMVSTRA,
64+
#' weights = ~WTMEC2YR,
65+
#' nest = TRUE,
66+
#' data = nhanes_adults_with_na
67+
#' )
68+
#'
69+
#' # 2. Basic Example: Create a simple Table 1
70+
#' vars_to_summarize <- c("Age", "Gender", "Race1", "Education")
71+
#' table1 <- svytable1(
72+
#' design = adult_design_with_na,
73+
#' strata_var = "ObeseStatus",
74+
#' table_vars = vars_to_summarize
75+
#' )
76+
#' print(table1)
77+
#'
78+
#' # 3. Advanced Example: Use reliability checks and get detailed metrics
79+
#' results <- svytable1(
80+
#' design = adult_design_with_na,
81+
#' strata_var = "ObeseStatus",
82+
#' table_vars = vars_to_summarize,
83+
#' reliability_checks = TRUE,
84+
#' return_metrics = TRUE
85+
#' )
86+
#'
87+
#' # View the table with unreliable estimates suppressed (*)
88+
#' print(results$formatted_table)
89+
#'
90+
#' # View the detailed report card of reliability checks
91+
#' print(results$reliability_metrics)
92+
#' }
4593
svytable1 <- function(design, strata_var, table_vars,
4694
mode = "mixed", commas = TRUE,
4795
reliability_checks = FALSE, return_metrics = FALSE) {

man/svytable1.Rd

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/references.bib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ @misc{nhanes_reliability_estimates
1010
author = {Centers for Disease Control and Prevention},
1111
title = {NHANES Tutorials: Reliability of Estimates Module},
1212
organization = {National Center for Health Statistics},
13-
year = {n.d.},
13+
year = {2005},
1414
url = {https://wwwn.cdc.gov/nchs/nhanes/tutorials/reliabilityofestimates.aspx},
1515
note = {Accessed: October 12, 2025}
1616
}

vignettes/using-svyTable1.Rmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,6 @@ The output from `svyglmdiag()` provides a clear, term-by-term *report card* for
284284
---
285285

286286
Overall, `svyglmdiag()` complements traditional regression output by making it easier to identify which predictors are both statistically meaningful and statistically stable under complex survey design.
287+
288+
289+
## References

0 commit comments

Comments
 (0)