NikNakk / forestmodel

42 stars 13 forks source link

Hide panels #1

Closed arazraw closed 9 years ago

arazraw commented 9 years ago

Absolutely lovely package - saves huge amounts of time.

As you surely know it is common to perform regression with sequential adjusting (e.g models 1 to 3), and therefore it would be great if one could display several forest plots side by side, and that is doable in current format by (for example) using gridExtra to place the plots next to each other. However, it is desirable to be able to remove some panels from selected plots in order to not repeat variable names. Is it possible to remove that panel, i.e the variable name panel and thus only display "N", "Hazard Ratio", and "P"?

Best regards

NikNakk commented 9 years ago

Thanks for your compliments!

I designed the package to be pretty flexible, so you can do this without any changes to the code. The panels that get plotted are completely configurable. The default includes the variable name as the second member of the list and the factor levels as the third. So, an easy way of doing this would be:

library("survival")
library("dplyr")
pretty_lung <- lung %>%
    transmute(time,
              status,
              Age = age,
              Sex = factor(sex, labels = c("Male", "Female")),
              ECOG = factor(lung$ph.ecog),
              `Meal Cal` = meal.cal)
my_model <- coxph(Surv(time, status) ~ ., pretty_lung)
forest_model(my_model, default_forest_panels(my_model)[-(2:3)])

If you look at the output of default_forest_panels(my_model) you can see the general structure of the panels object a bit better.

NikNakk commented 9 years ago

Please let me know if that resolves the question you had and I'll close the issue.

arazraw commented 9 years ago

Many thanks Dr Kennedy, problem solved.

If You are planning future versions of this package, it would be great if there were columns for number of events, person years and event rates, whenever applicable (coxph). Thats just a proposition, however, I'm very satisfied with the package in current format.

Cheers

NikNakk commented 9 years ago

Great!

For your other point, I'm not clear on how you'd want to include number of events, etc. since they apply to the whole model, not to each separate covariate. They're also not part of the standard output from broom::tidy, although the number of events is a member of the model and of the output of broom::glance.

arazraw commented 9 years ago

Perhaps it was a bad idea, but I'll try to clarify. Suppose you examine the association between treatment groups and mortality. Using Your package it is easy to present a plot of the association, particularly with "covariates=c()" argument which filters out unwanted predictors. The plot displays number of individuals in each treatment group, along with hazard ratios and p values. But it does not present number of events in both groups, nor event rates (the former would be the most important from an epidemiological perspective). However, it is not a difficult task to code this separately and display it in a separate table but I'm thinking it could be valuable to see directly in the forest plot. I will have a go at trying to code it myself but it won't be of the same quality as your work.

NikNakk commented 9 years ago

I understand now. I’ve created new variables for the number of events and the person-time (which would be person-years if the time is measured in years).

It’s currently on its own branch at https://github.com/NikNakk/forestmodel/tree/newcoxphvars and issue #2.

I’ve added an example which uses custom panels with these new variables.

From: arazraw [mailto:notifications@github.com] Sent: 25 November 2015 12:07 To: NikNakk/forestmodel forestmodel@noreply.github.com Cc: NikNakk nick@nick-kennedy.com Subject: Re: [forestmodel] Hide panels (#1)

Perhaps it was a bad idea, but I'll try to clarify. Suppose you examine the association between treatment groups and mortality. Using Your package it is easy to present a plot of the association, particularly with "covariates=c()" argument which filters out unwanted predictors. The plot displays number of individuals in each treatment group, along with hazard ratios and p values. But it does not present number of events in both groups, nor event rates (the former would be the most important from an epidemiological perspective). However, it is not a difficult task to code this separately and display it in a separate table but I'm thinking it could be valuable to see directly in the forest plot. I will have a go at trying to code it myself but it won't be of the same quality as your work.

— Reply to this email directly or view it on GitHub https://github.com/NikNakk/forestmodel/issues/1#issuecomment-159589636 . https://github.com/notifications/beacon/ACEx_8DOv5D6QvP1i0oKbB7ueo2uUoGBks5pJZvjgaJpZM4Gm5CQ.gif