Description Usage Arguments Value Examples
This function allows you to calculate mean and sd of a numeric variable by grouping and all subgroup variables of interest (ie. mean age of those belonging to subgroup 1 or 2 by levels of grouping variable, mean BMI of of those belonging to subgroup 1 or 2 by levels of grouping variable, etc.)
1 2 3 |
df |
Dataset containing covariates of interest |
subgroups_m |
Vector of subgroup variables of interest (must be factors) |
mean_vars |
Vector of numeric variables from which to calculate mean and sd (must match vector position of corresponding subgroup variable) |
num_display |
How should results be displayed? ('PM' for mean +- sd, 'PRS' for mean (sd)) |
subgroups_c |
Subgroup variable of interest (must be factor) |
count_vars |
Factor variable from which to calculate counts and proportions |
count_display |
How to display results: 'CP' = counts and proportions, 'C' = counts, 'P' = proportions (defaults to 'CP') |
grouping_var |
Variable to group by (will be columns of table) |
show_pval |
Logical. Should the p-value results be displayed? |
digits |
Number of digits to round decimals |
A data frame summarizing mean and sd/count and proportion of a variable by grouping and all subgroup variables of interest
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | ## Not run:
# First create vectors of subgroups and calculation variables, positions must match
(ie. mean BMI of levels of Edu_4cat, mean age of levels of sub_senior, etc.)
subgroups_m <- c('Edu_4cat_m', 'sub_senior_m', 'female_m', 'race_black_m')
mean_vars <- c('BMI', 'age', 'sbp', 'BMI')
subgroups_c <- c('female_c', 'sub_senior_c')
count_vars <- c('depress', 'race_black')
# Then run function
summarize_all_subgroups(df = obpv_baseline, subgroups_m = subgroups_m, mean_vars = mean_vars,
num_display = 'PM', subgroups_c = subgroups_c, count_vars = count_vars, count_display = 'CP',
grouping_var = obpv_quintile, digits = 2)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.