-
Notifications
You must be signed in to change notification settings - Fork 449
/
mcbs.Rmd
329 lines (233 loc) · 9.4 KB
/
mcbs.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# Medicare Current Beneficiary Survey (MCBS) {-}
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) <a href="https://github.com/asdfree/mcbs/actions"><img src="https://github.com/asdfree/mcbs/actions/workflows/r.yml/badge.svg" alt="Github Actions Badge"></a>
The monitoring system for Medicare enrollees in the United States on topics not available in the program's administrative data, such as out of pocket expenditure and beneficiary satisfaction.
* Survey and supplemental tables with one row per sampled individual, although downloadable datasets not linkable.
* A complex sample survey designed to generalize to all elderly and disabled individuals with at least one month of program enrollment during the calendar year.
* Released annually as a public use file since 2015.
* Conducted by the Office of Enterprise Data and Analytics (OEDA) of the Centers for Medicare & Medicaid Services (CMS) through a contract with NORC at the University of Chicago.
---
## Recommended Reading {-}
Four Example Strengths & Limitations:
✔️ [Respondents interviewed up to three times annually across four years](https://edit.cms.gov/Research-Statistics-Data-and-Systems/Research/MCBS/Downloads/MCBS_Tutorial.pdf#page=21)
✔️ [More than 1.2 million interviews since inception](https://mcbs-interactives.norc.org/about/mcbs/)
❌ [Some respondents designate a proxy to interview on their behalf](https://www.census.gov/fedcasic/fc2022/pdf/2C_carpenter.pdf)
❌ [Facility residents included, but not in public use file](https://www.cms.gov/files/document/mcbs-advanced-tutorial-using-community-and-facility-data.pdf#page=7)
<br>
Three Example Findings:
1. [Among all Medicare beneficiaries, 7 percent reported having problems paying a medical bill in 2021](https://www.medpac.gov/document/march-2024-report-to-the-congress-medicare-payment-policy/).
2. [Between 1999 and 2017, Medicare beneficiaries with diabetes faced higher out-of-pocket costs](https://doi.org/10.2337/dc20-2708).
3. [In 2020, healthcare expenditure for non-fatal falls was $80 billion, the majority paid by Medicare](https://doi.org/10.1136/ip-2023-045023).
<br>
Two Methodology Documents:
> [MCBS Methodology Report](https://data.cms.gov/sites/default/files/2024-10/SFPUF2022_DUG.pdf)
> [MCBS Advanced Tutorial on Weighting and Variance Estimation](https://www.cms.gov/files/document/mcbs-advanced-tutorial-weighting-and-variance-estimation.pdf)
<br>
One Haiku:
```{r}
# old, or disabled
# access to medical care,
# utilization
```
---
## Download, Import, Preparation {-}
```{r eval = FALSE , results = "hide" }
tf <- tempfile()
this_url <- "https://www.cms.gov/files/zip/cspuf2021.zip"
download.file( this_url , tf , mode = 'wb' )
unzipped_files <- unzip( tf , exdir = tempdir() )
mcbs_csv <- grep( '\\.csv$' , unzipped_files , value = TRUE )
mcbs_df <- read.csv( mcbs_csv )
names( mcbs_df ) <- tolower( names( mcbs_df ) )
```
### Save Locally \ {-}
Save the object at any point:
```{r eval = FALSE , results = "hide" }
# mcbs_fn <- file.path( path.expand( "~" ) , "MCBS" , "this_file.rds" )
# saveRDS( mcbs_df , file = mcbs_fn , compress = FALSE )
```
Load the same object:
```{r eval = FALSE , results = "hide" }
# mcbs_df <- readRDS( mcbs_fn )
```
### Survey Design Definition {-}
Construct a complex sample survey design:
```{r eval = FALSE , results = "hide" }
library(survey)
mcbs_design <-
svrepdesign(
weight = ~cspufwgt ,
repweights = 'cspuf[0-9]+' ,
mse = TRUE ,
type = 'Fay' ,
rho = 0.3 ,
data = mcbs_df
)
```
### Variable Recoding {-}
Add new columns to the data set:
```{r eval = FALSE , results = "hide" }
mcbs_design <-
update(
mcbs_design ,
one = 1 ,
csp_age =
factor(
csp_age ,
levels = 1:3 ,
labels =
c(
'01: younger than 65' ,
'02: 65 to 74' ,
'03: 75 or older'
)
) ,
two_or_more_chronic_conditions = as.numeric( csp_nchrncnd > 1 ) ,
csp_sex = factor( csp_sex , labels = c( 'male' , 'female' ) )
)
```
---
## Analysis Examples with the `survey` library \ {-}
### Unweighted Counts {-}
Count the unweighted number of records in the survey sample, overall and by groups:
```{r eval = FALSE , results = "hide" }
sum( weights( mcbs_design , "sampling" ) != 0 )
svyby( ~ one , ~ csp_age , mcbs_design , unwtd.count )
```
### Weighted Counts {-}
Count the weighted size of the generalizable population, overall and by groups:
```{r eval = FALSE , results = "hide" }
svytotal( ~ one , mcbs_design )
svyby( ~ one , ~ csp_age , mcbs_design , svytotal )
```
### Descriptive Statistics {-}
Calculate the mean (average) of a linear variable, overall and by groups:
```{r eval = FALSE , results = "hide" }
svymean( ~ pamtoop , mcbs_design )
svyby( ~ pamtoop , ~ csp_age , mcbs_design , svymean )
```
Calculate the distribution of a categorical variable, overall and by groups:
```{r eval = FALSE , results = "hide" }
svymean( ~ csp_sex , mcbs_design )
svyby( ~ csp_sex , ~ csp_age , mcbs_design , svymean )
```
Calculate the sum of a linear variable, overall and by groups:
```{r eval = FALSE , results = "hide" }
svytotal( ~ pamtoop , mcbs_design )
svyby( ~ pamtoop , ~ csp_age , mcbs_design , svytotal )
```
Calculate the weighted sum of a categorical variable, overall and by groups:
```{r eval = FALSE , results = "hide" }
svytotal( ~ csp_sex , mcbs_design )
svyby( ~ csp_sex , ~ csp_age , mcbs_design , svytotal )
```
Calculate the median (50th percentile) of a linear variable, overall and by groups:
```{r eval = FALSE , results = "hide" }
svyquantile( ~ pamtoop , mcbs_design , 0.5 )
svyby(
~ pamtoop ,
~ csp_age ,
mcbs_design ,
svyquantile ,
0.5 ,
ci = TRUE
)
```
Estimate a ratio:
```{r eval = FALSE , results = "hide" }
svyratio(
numerator = ~ pamtoop ,
denominator = ~ pamttot ,
mcbs_design
)
```
### Subsetting {-}
Restrict the survey design to household income below $25,000:
```{r eval = FALSE , results = "hide" }
sub_mcbs_design <- subset( mcbs_design , csp_income == 1 )
```
Calculate the mean (average) of this subset:
```{r eval = FALSE , results = "hide" }
svymean( ~ pamtoop , sub_mcbs_design )
```
### Measures of Uncertainty {-}
Extract the coefficient, standard error, confidence interval, and coefficient of variation from any descriptive statistics function result, overall and by groups:
```{r eval = FALSE , results = "hide" }
this_result <- svymean( ~ pamtoop , mcbs_design )
coef( this_result )
SE( this_result )
confint( this_result )
cv( this_result )
grouped_result <-
svyby(
~ pamtoop ,
~ csp_age ,
mcbs_design ,
svymean
)
coef( grouped_result )
SE( grouped_result )
confint( grouped_result )
cv( grouped_result )
```
Calculate the degrees of freedom of any survey design object:
```{r eval = FALSE , results = "hide" }
degf( mcbs_design )
```
Calculate the complex sample survey-adjusted variance of any statistic:
```{r eval = FALSE , results = "hide" }
svyvar( ~ pamtoop , mcbs_design )
```
Include the complex sample design effect in the result for a specific statistic:
```{r eval = FALSE , results = "hide" }
# SRS without replacement
svymean( ~ pamtoop , mcbs_design , deff = TRUE )
# SRS with replacement
svymean( ~ pamtoop , mcbs_design , deff = "replace" )
```
Compute confidence intervals for proportions using methods that may be more accurate near 0 and 1. See `?svyciprop` for alternatives:
```{r eval = FALSE , results = "hide" }
svyciprop( ~ two_or_more_chronic_conditions , mcbs_design ,
method = "likelihood" )
```
### Regression Models and Tests of Association {-}
Perform a design-based t-test:
```{r eval = FALSE , results = "hide" }
svyttest( pamtoop ~ two_or_more_chronic_conditions , mcbs_design )
```
Perform a chi-squared test of association for survey data:
```{r eval = FALSE , results = "hide" }
svychisq(
~ two_or_more_chronic_conditions + csp_sex ,
mcbs_design
)
```
Perform a survey-weighted generalized linear model:
```{r eval = FALSE , results = "hide" }
glm_result <-
svyglm(
pamtoop ~ two_or_more_chronic_conditions + csp_sex ,
mcbs_design
)
summary( glm_result )
```
---
## Replication Example {-}
This example matches the weighted total from the [2021 Data User's Guide: Cost Supplement File Public Use File](https://www.cms.gov/files/document/2021mcbsdatausersguidecsfilepuf.pdf):
```{r eval = FALSE , results = "hide" }
stopifnot( round( coef( svytotal( ~ one , mcbs_design ) ) , 0 ) == 59040948 )
```
---
## Analysis Examples with `srvyr` \ {-}
The R `srvyr` library calculates summary statistics from survey data, such as the mean, total or quantile using [dplyr](https://github.com/tidyverse/dplyr/)-like syntax. [srvyr](https://github.com/gergness/srvyr) allows for the use of many verbs, such as `summarize`, `group_by`, and `mutate`, the convenience of pipe-able functions, the `tidyverse` style of non-standard evaluation and more consistent return types than the `survey` package. [This vignette](https://cran.r-project.org/web/packages/srvyr/vignettes/srvyr-vs-survey.html) details the available features. As a starting point for MCBS users, this code replicates previously-presented examples:
```{r eval = FALSE , results = "hide" }
library(srvyr)
mcbs_srvyr_design <- as_survey( mcbs_design )
```
Calculate the mean (average) of a linear variable, overall and by groups:
```{r eval = FALSE , results = "hide" }
mcbs_srvyr_design %>%
summarize( mean = survey_mean( pamtoop ) )
mcbs_srvyr_design %>%
group_by( csp_age ) %>%
summarize( mean = survey_mean( pamtoop ) )
```