Skip to content

Commit

Permalink
RCC SU 2018
Browse files Browse the repository at this point in the history
  • Loading branch information
astra-cdc committed Jul 16, 2024
1 parent a5615c8 commit 8adf941
Show file tree
Hide file tree
Showing 54 changed files with 655 additions and 346 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
^pkgdown$
^cran-comments\.md$
^CRAN-SUBMISSION$
^data-raw$
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# surveytable (development version)

* `rccsu2018`

# surveytable 0.9.4

* Optionally adjust p-values for multiple comparisons (`p_adjust` argument)
Expand Down
10 changes: 10 additions & 0 deletions R/z_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,13 @@
#' United States as of July 1, 2019. Used for calculating rates. For usage
#' examples, see the `*_rate` functions.
"uspop2019"

#' National Study of Long-Term Care Providers (NSLTCP) Residential Care Community (RCC) Services User (SU) 2018 Public Use File (PUF)
#'
#' A data system of RCC residents.
#'
#' @source
#' * SAS data: <https://ftp.cdc.gov/pub/Health_Statistics/NCHS/Datasets/NPALS/final2018rcc_su_puf.sas7bdat>
#' * Documentation: <https://www.cdc.gov/nchs/npals/RCCresident-readme03152021vr.pdf>
#' * Codebook: <https://www.cdc.gov/nchs/data/npals/final2018rcc_su_puf_codebook.pdf>
"rccsu2018"
46 changes: 42 additions & 4 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,26 @@ knitr::opts_chunk$set(
<!-- badges: start -->
<!-- badges: end -->

The `surveytable` package provides short and understandable commands that generate tabulated, formatted, and rounded survey estimates. One useful function, which operates on categorical and logical variables, tabulates estimated counts and percentages with their standard errors and confidence intervals. Other functions estimate the total population, tabulate survey subsets and variable interactions, tabulate numeric variables, perform hypothesis tests, tabulate rates, modify survey variables, and save the output. All of the tabulation functions identify low-precision estimates using algorithms developed at the National Center for Health Statistics (NCHS). If the `surveytable` code is called from an R Markdown notebook, it automatically generates HTML or LaTeX tables, as appropriate. The package reduces the number of commands that users need to execute, which is especially helpful for users new to R or to programming.
`surveytable` is an R package for conveniently tabulating estimates from **complex surveys**.

* If you deal with survey objects in R (created with `survey::svydesign()`), then this package is for you.
* Works with **complex surveys** (data systems that involve survey design variables, like weights and strata).
* Works with **unweighted** data as well.

* The `surveytable` package provides short and understandable commands that generate tabulated, formatted, and rounded survey estimates.
* With `surveytable`, you can
* tabulate estimated counts and percentages, with their standard errors and confidence intervals,
* estimate the total population,
* tabulate survey subsets and variable interactions,
* tabulate numeric variables,
* perform hypothesis tests,
* tabulate rates,
* modify survey variables, and
* save the output.

* All of the tabulation functions identify low-precision estimates using National Center for Health Statistics (NCHS) algorithms.
* If the `surveytable` code is called from an R Markdown notebook or a Quarto document, it automatically generates HTML or LaTeX tables, as appropriate.
* The package reduces the number of commands that users need to execute, which is especially helpful for users new to R or to programming.


## Installation
Expand All @@ -28,7 +47,7 @@ Install from CRAN:
``` r
install.packages("surveytable")
```
or get a development version from GitHub:
or get the development version from GitHub:

``` r
install.packages(c("remotes", "git2r"))
Expand All @@ -39,20 +58,39 @@ remotes::install_github("CDCgov/surveytable", upgrade = "never")

Find the documentation for `surveytable` here: https://cdcgov.github.io/surveytable/


## Example

Here is a basic example, to get you started.

```{r, results=FALSE, message=FALSE, warning=FALSE}
1. Load the package:

```{r, message=FALSE}
library(surveytable)
```

2. Specify the survey that you wish you analyze. `surveytable` comes with a survey called `namcs2019sv`, for use in examples.

```{r, results='asis'}
set_survey(namcs2019sv)
```

3. Specify the variable to analyze. In NAMCS, `AGER` is the age category variable:

```{r, results='asis'}
tab("AGER")
```

The table shows:

* Descriptive variable name
* Survey name
* For each level of the variable:
* Number of observations
* Estimated count with its SE and 95% CI
* Estimated percentage with its SE and 95% CI
* Sample size
* Whether any low-precision estimates were found

<!-- CDC standard text -->
## Public Domain Standard Notice
This repository constitutes a work of the United States Government and is not
Expand Down
79 changes: 60 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,41 @@
<!-- badges: start -->
<!-- badges: end -->

The `surveytable` package provides short and understandable commands
that generate tabulated, formatted, and rounded survey estimates. One
useful function, which operates on categorical and logical variables,
tabulates estimated counts and percentages with their standard errors
and confidence intervals. Other functions estimate the total population,
tabulate survey subsets and variable interactions, tabulate numeric
variables, perform hypothesis tests, tabulate rates, modify survey
variables, and save the output. All of the tabulation functions identify
low-precision estimates using algorithms developed at the National
Center for Health Statistics (NCHS). If the `surveytable` code is called
from an R Markdown notebook, it automatically generates HTML or LaTeX
tables, as appropriate. The package reduces the number of commands that
users need to execute, which is especially helpful for users new to R or
to programming.
`surveytable` is an R package for conveniently tabulating estimates from
**complex surveys**.

- If you deal with survey objects in R (created with
`survey::svydesign()`), then this package is for you.

- Works with **complex surveys** (data systems that involve survey
design variables, like weights and strata).

- Works with **unweighted** data as well.

- The `surveytable` package provides short and understandable commands
that generate tabulated, formatted, and rounded survey estimates.

- With `surveytable`, you can

- tabulate estimated counts and percentages, with their standard
errors and confidence intervals,
- estimate the total population,
- tabulate survey subsets and variable interactions,
- tabulate numeric variables,
- perform hypothesis tests,
- tabulate rates,
- modify survey variables, and
- save the output.

- All of the tabulation functions identify low-precision estimates using
National Center for Health Statistics (NCHS) algorithms.

- If the `surveytable` code is called from an R Markdown notebook or a
Quarto document, it automatically generates HTML or LaTeX tables, as
appropriate.

- The package reduces the number of commands that users need to execute,
which is especially helpful for users new to R or to programming.

## Installation

Expand All @@ -29,7 +50,7 @@ Install from CRAN:
install.packages("surveytable")
```

or get a development version from GitHub:
or get the development version from GitHub:

``` r
install.packages(c("remotes", "git2r"))
Expand All @@ -45,17 +66,22 @@ Find the documentation for `surveytable` here:

Here is a basic example, to get you started.

1. Load the package:

``` r
library(surveytable)
```

2. Specify the survey that you wish you analyze. `surveytable` comes
with a survey called `namcs2019sv`, for use in examples.

``` r
set_survey(namcs2019sv)
```

<table class="huxtable" data-quarto-disable-processing="true" style="border-collapse: collapse; border: 0px; margin-bottom: 2em; margin-top: 2em; ; margin-left: auto; margin-right: auto; ">
<caption style="caption-side: top; text-align: center;">
Survey info {NAMCS 2019 PUF}
Survey info {namcs2019sv}
</caption>
<col>
<col>
Expand All @@ -80,19 +106,22 @@ Design
</td>
<td style="vertical-align: top; text-align: left; white-space: normal; border-style: solid solid solid solid; border-width: 0.4pt 0.4pt 0.4pt 0.4pt; padding: 6pt 6pt 6pt 6pt; font-weight: normal;">
Stratified 1 - level Cluster Sampling design (with replacement)<br>With
(398) clusters.<br>survey::svydesign(ids = ~CPSUM, strata = ~CSTRATM,
weights = ~PATWT, <br> data = namcs2019sv_df)
(398) clusters.<br>namcs2019sv = survey::svydesign(ids = ~CPSUM, strata
= ~CSTRATM, weights = ~PATWT, data = namcs2019sv_df)
</td>
</tr>
</table>

3. Specify the variable to analyze. In NAMCS, `AGER` is the age
category variable:

``` r
tab("AGER")
```

<table class="huxtable" data-quarto-disable-processing="true" style="border-collapse: collapse; border: 0px; margin-bottom: 2em; margin-top: 2em; ; margin-left: auto; margin-right: auto; ">
<caption style="caption-side: top; text-align: center;">
Patient age recode {NAMCS 2019 PUF}
Patient age recode {namcs2019sv}
</caption>
<col>
<col>
Expand Down Expand Up @@ -334,6 +363,18 @@ N = 8250. Checked NCHS presentation standards. Nothing to report.
</td>
</tr>
</table>

The table shows:

- Descriptive variable name
- Survey name
- For each level of the variable:
- Number of observations
- Estimated count with its SE and 95% CI
- Estimated percentage with its SE and 95% CI
- Sample size
- Whether any low-precision estimates were found

<!-- CDC standard text -->

## Public Domain Standard Notice
Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ reference:
contents:
- namcs2019sv
- uspop2019
- rccsu2018
- title: "Other"
contents:
- set_output
Expand Down
29 changes: 29 additions & 0 deletions data-raw/namcs2019sv.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
library(nchsdata)
library(magrittr)

vrs = c("CPSUM", "CSTRATM", "PATWT" # survey design
, "MDDO", "SPECCAT", "MSA" # Table 1
, "AGER", "SEX", "AGE" # Table 3
, "NOPAY", "PAYPRIV", "PAYMCARE", "PAYMCAID", "PAYWKCMP"
, "PAYOTH", "PAYDK", "PAYSELF", "PAYNOCHG" # Table 5
, "PRIMCARE", "REFER", "SENBEFOR" # Table 6
, "MAJOR" # Table 11
, "NUMMED" # numeric variable
, "ANYIMAGE", "BONEDENS", "CATSCAN", "ECHOCARD", "OTHULTRA"
, "MAMMO", "MRI", "XRAY", "OTHIMAGE" # imaging
) %>% unique

namcs2019sv_df = namcs2019$variables[,vrs]

vr = "SPECCAT.bad"
namcs2019sv_df[,vr] = namcs2019sv_df$SPECCAT
set.seed(42)
nr = nrow(namcs2019sv_df)
idx = sample.int(n = nr, size = round(0.2 * nr))
namcs2019sv_df[idx, vr] = NA
attr(namcs2019sv_df[,vr], "label") = "Type of specialty (BAD - do not use)"

namcs2019sv = survey::svydesign(ids = ~CPSUM, strata = ~CSTRATM, weights = ~PATWT, data = namcs2019sv_df)

usethis::use_data(namcs2019sv, overwrite = TRUE)
usethis::use_data(namcs2019sv_df, overwrite = TRUE)
2 changes: 2 additions & 0 deletions data-raw/rccsu2018.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
library(nchsdata)
usethis::use_data(rccsu2018, overwrite = TRUE)
Binary file modified data/namcs2019sv.rda
Binary file not shown.
Binary file modified data/namcs2019sv_df.rda
Binary file not shown.
Binary file added data/rccsu2018.rda
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/LICENSE.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8adf941

Please sign in to comment.