draw_mcc | R Documentation |
Draw a (matched) case-control (CC) sample from a cohort (or cross-sectional data)
draw_mcc( cohort, y_name, n_cases = NULL, n_per_case, match_var_names = NULL, weight_name = "ip_weight" )
cohort |
Cohort (or cross-sectional) data. A |
y_name |
Name of the outcome variable in |
n_cases |
Number of cases to draw. Default is |
n_per_case |
Number of controls to draw for each case. |
match_var_names |
Name(s) of the match variable(s) in |
weight_name |
Name to assign to the column for the inverse probability
weight, which will be created as the last column in the (matched) CC
data returned. Default is |
Returns a data.frame
of the (matched) CC sample, with an
additional column for the inverse probability weight for each subject, i.e.,
1 for cases and the inverse probability of the sampling fraction for each
control.
Yilin Ning, Anastasia Lam, Marie Reilly
library(SamplingDesignTools) # Load cohort data data("cohort_2") # Ignoring that we have the event time in this simulated cohort head(cohort_2) # Draw simple 1:2 case-control sample (i.e., with randomly selected controls): dat_scc <- draw_mcc(cohort = cohort_2, y_name = "y", n_per_case = 2) head(dat_scc) # Draw simple 1:2 case-control sample, matched on age group and gender: dat_mcc <- draw_mcc(cohort = cohort_2, y_name = "y", n_per_case = 2, match_var_names = c("age_cat", "gender"), weight_name = ".w") head(dat_mcc)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.