Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to present logicals / dummies with percent instead of n for both levels #25

Closed
owasow opened this issue Oct 1, 2019 · 2 comments

Comments

@owasow
Copy link

owasow commented Oct 1, 2019

I've been using finalfit to create a summary stats table (i.e., table 1) and it's great. I've been looking through the very helpful online vignettes for an option to report summary stats for dummies / logicals with a percent rather than n, however, and haven't been able to find anything. For example, rather than reporting both male and female levels, just one row with percent female would suffice and, in many cases, be more easily interpreted by the reader. Did I miss something or perhaps this could be added in the future?

@ewenharrison
Copy link
Owner

ewenharrison commented Oct 1, 2019

Thanks Omar, it's a good idea. Appreciate your thoughts on this.

There's the ff_remove_ref() function for regression tables, but nothing that will currently work after summary_factorlist().

This should work for all instances. Looks awful of course but if useful could be wrapped up into a nicer function.

Let me know what you think.

explanatory = c("age", "nodes", "age.factor", "sex.factor", "obstruct.factor", "perfor.factor")
dependent = 'mort_5yr'

colon_s %>%
	summary_factorlist(dependent, explanatory, column = TRUE) %>% 
	dplyr::mutate(label = ifelse(label == "", NA, label)) %>% 
	tidyr::fill(label) %>%
	dplyr::group_by(label) %>% 
	dplyr::filter(levels %in% c("Mean (SD)", "Median (IQR)") | row_number() != 1) %>% 
	dplyr::ungroup() %>% 
	dplyr::mutate_at(-c(1, 2), ~ stringr::str_extract(., "(?<=\\().+?(?=\\))")) %>% 
	rm_duplicate_labels() %>% 
	data.frame()

ewenharrison added a commit that referenced this issue Oct 24, 2019
@ewenharrison
Copy link
Owner

This is done.

explanatory = c("age", "age.factor", "sex.factor", "obstruct.factor", "perfor.factor")
dependent = 'mort_5yr'
colon_s %>%
	summary_factorlist(dependent, explanatory)
         label      levels       Alive        Died
1  Age (years)   Mean (SD) 59.8 (11.4) 59.9 (12.5)
2          Age   <40 years    31 (6.1)    36 (8.9)
3              40-59 years  208 (40.7)  131 (32.4)
4                60+ years  272 (53.2)  237 (58.7)
9          Sex      Female  243 (47.6)  194 (48.0)
10                    Male  268 (52.4)  210 (52.0)
5  Obstruction          No  408 (82.1)  312 (78.6)
6                      Yes   89 (17.9)   85 (21.4)
7  Perforation          No  497 (97.3)  391 (96.8)
8                      Yes    14 (2.7)    13 (3.2)

colon_s %>%
	summary_factorlist(dependent, explanatory) %>% 
	ff_remove_ref() %>% 
	ff_percent_only()

        label      levels       Alive        Died
1 Age (years)   Mean (SD) 59.8 (11.4) 59.9 (12.5)
2         Age   <40 years         6.1         8.9
3             40-59 years        40.7        32.4
4               60+ years        53.2        58.7
5         Sex        Male        52.4        52.0
6 Obstruction         Yes        17.9        21.4
7 Perforation         Yes         2.7         3.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants