Closed mabilang closed 4 years ago
Use tidy_override
or tidy_replace
to pre-exponentiate your data; or
just do
huxreg('Age model' = cox.age, ci_level = 0.95, bold_signif = 0.05, error_pos = 'same', error_format = c('p={p.value}, HR: {exp(as.numeric(gsub(" .*", "", estimate)))}, CI: ({exp(conf.low)},{exp(conf.high)})'))
The former seems a better idea, since there's little reason to put the
estimate
in the error cell.
That said, I think this is a legitimate bug since it violates expectations
that you can use the raw estimate
column from tidy(mod)
in
error_format
. Please try the latest github master to see if it works for
you.
Hi David,
Thank you so much, the latest github master works. I use huxreg to output cox model tables into Word frequently, so being able to exponentiate estimates to see the HR is very helpful (and I couldn't figure out how to do it without using error_format()). One minor effect of the update I noticed is that variables in the huxtable but absent in the cox model now have a cell value of "NA". I think before the update it was blank or a dash (I could be wrong, but I'm fairly certain it wasn't NA). Here's example code and a screenshot:
data("lung") #NCCTG Lung Cancer Data from survival package
str(lung) cox.age <- coxph(Surv(time, status) ~ age, data=lung) cox.meal <- coxph(Surv(time, status) ~ meal.cal, data=lung) cox.agemealwt <- coxph(Surv(time, status) ~ age + meal.cal + wt.loss, data=lung) huxreg('Age ' = cox.age, 'Meal' = cox.meal, 'Multivariate' = cox.agemealwt, ci_level = 0.95, bold_signif = 0.05, error_pos = 'same', error_format = c('p={p.value}, HR: {exp(estimate)}, CI: ({exp(conf.low)},{exp(conf.high)})')) -> test test
[image: image.png]
It's not a big deal, but thought I should let you know. Thanks again for your help (and your great work on huxtable)
Best,
Curtis
On Tue, Jun 30, 2020 at 1:42 AM David Hugh-Jones notifications@github.com wrote:
That said, I think this is a legitimate bug since it violates expectations that you can use the raw
estimate
column fromtidy(mod)
inerror_format
. Please try the latest github master to see if it works for you.— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/hughjonesd/huxtable/issues/163#issuecomment-651611474, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJ2CCLIJU37IEN2BFFYCGLRZGJNVANCNFSM4OLVHNTQ .
Describe the bug When using huxreg to report Cox Regression model output, it is useful to exponentiate the model coefficients to report the HR and 95% CI. This is done using the error_format() argument. However, the "estimate" is not able to be parsed correctly and returns errors. First, it will return a "non-numeric argument to mathematical function" error when attempting to include {exp(estimate)} in the error_format() argument. When I attempt to coerce the"estimate" to numeric, it then returns NA introduced by coercion because it cannot parse the character string (I believe this is due to statistically significant estimates being reported with an asterisk at the end e.g. "0.019 *", where as non-significant estimates are able to be parsed due to the absence of the asterisk symbol e.g. "0.019".
Note that {exp(conf.low)} and {exp(conf.high)} both work correctly.
Minimal Reproducible Example
Expected behavior I expected that the argument error_format = c('{exp(estimate)}, CI: ({exp(conf.low)},{exp(conf.high)})') would be able to produce the HR and 95% CI in the output.
System details Please report the output of
packageVersion("huxtable")
, as well as your R version and Rstudio version if applicable. huxtable: v5.0.0 R: v3.6.3 RStudio: v1.2.5019NOTE I initially posted on stackoverflow for help thinking I was doing something wrong, but I've posted here as well thinking it may be a bug. Thank you for your time.