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

How to remove the "No"/"0" factor row? #12

Closed
tylcole opened this Issue Jan 18, 2019 · 3 comments

Comments

Projects
None yet
2 participants
@tylcole
Copy link

tylcole commented Jan 18, 2019

Hello,

Thanks for the great package!

Is there an option remove the "0" row or the "No" row via the finalfit function? I use a lot of binary variables, and it would be nice just to show the row for the "1" or "Yes".

image

For example, in the picture above, having "Female" "1" "12888 (41.3)" "972 (44.7)" "1.15 (1.05-1.25, p=0.002" "1.15 (1.05-1.25, p=0.002" all in the same row with no row with "0" or "-".

@tylcole

This comment has been minimized.

Copy link
Author

tylcole commented Jan 18, 2019

As a temporary workaround, I wrote the function collapseBinary() which takes as input a finalfit output dataframe

In:
image

Out:
image

Function:
collapseBinary = function(.data) {
emptyRows = which(.data[,2] == "0")
.data[emptyRows, 2:6] = .data[(emptyRows + 1), 2:6]
.data = .data[-(emptyRows + 1),]
replaceWithBlank = which(.data[,2] == "1")
.data[replaceWithBlank, 2] = ""
return(.data)
}

Use:
collapsedTable = tableToCollapse %>% collapseBinary()

You may have to change whatever your binary labels are, like "No" and "Yes" instead of "0" and "1"

Hope it helps until there's something more general incorporated in the function! This would also be great for the OR plots

@ewenharrison

This comment has been minimized.

Copy link
Owner

ewenharrison commented Jan 19, 2019

Hi,
Many thanks for you interest and work on this. One of the advantages of the finalfit dataframe is that it can be edited on the fly. So rather than adding extra options to the original functions, I've added a quick helper function ff_remove_ref which will remove the rows for you. It should work with all flavors of regression and factor levels.

You can install the github version of finalfit to access this.

Example:

explanatory = c("age.factor", "age", "sex.factor", "nodes", "obstruct.factor", "perfor.factor")
dependent = 'mort_5yr'
colon_s %>%
	finalfit(dependent, explanatory, add_dependent_label = FALSE) %>% 
	ff_remove_ref() %>% 
	dependent_label(colon_s, dependent)

Altering the OR plot can be done in a similar manner. This isn't as straightfoward and some examples will be added to future vignettes. A new "factorlist" object is created only containing the levels of interest, which is then passed to or_plot().

Example:

colon_s %>% 
	summary_factorlist(dependent, explanatory, total_col = TRUE, fit_id=TRUE) %>% 
	ff_merge(
		glmuni(colon_s, dependent, explanatory) %>% 
			fit2df()) %>% 
	ff_remove_ref() %>% 
	select(-`OR`) -> factorlist_plot

colon_s %>% 
	or_plot(dependent, explanatory, factorlist = factorlist_plot)

ff_merge() is very flexible, and multiple columns can be added to a regression table using it. I'll pop a comment on your other post about that. Thanks again. Let me know if anything doesn't work.

@tylcole

This comment has been minimized.

Copy link
Author

tylcole commented Jan 24, 2019

That's great, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment