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

small issue: prettify digits problem in CI upper #40

Closed
likelet opened this issue Oct 19, 2018 · 4 comments
Closed

small issue: prettify digits problem in CI upper #40

likelet opened this issue Oct 19, 2018 · 4 comments

Comments

@likelet
Copy link

likelet commented Oct 19, 2018

cox regression model, using digits=3, CI (upper) show only 2 digits
my code
prettify(summary(mcox.fit1.train),digits = 3)
my result

               coef Hazard Ratio CI (lower) CI (upper) se(coef)      z Pr(>|z|)    
1     cpscore  0.80653        2.240      1.793       2.80   0.1137  7.096   <0.001 ***
2      sex: M -0.09104        0.913      0.654       1.27   0.1699 -0.536    0.592    
3 location: R  0.44916        1.567      1.099       2.23   0.1809  2.483    0.013   *
@likelet likelet changed the title Bug: prettify digits problem in CI upper small issue: prettify digits problem in CI upper Oct 19, 2018
@hofnerb
Copy link
Owner

hofnerb commented Nov 15, 2018

First of all sorry that I didn't reply earlier. I didn't receive any notification.

Unfortunatley, I cannot check your example as there is no (reproducible) code. Could you please provide a minimal working example which displays the behavior? Thx.

@likelet
Copy link
Author

likelet commented Nov 21, 2018

       # Load data set ovarian
        data(ovarian, package = "survival")

        ## fit a Cox model
        mod5 <- coxph(Surv(futime, fustat) ~ age, data=ovarian)
        summary(mod5)
        ## Make pretty summary
        prettify(summary(mod5),digit=3)
          coef    Hazard Ratio CI (lower) CI (upper) se(coef)    z Pr(>|z|)    
1 age 0.162         1.18         1.07        **1.3**   0.0497 3.25    0.001  **

you can find CI(upper) has less digits

@hofnerb
Copy link
Owner

hofnerb commented Jan 2, 2019

There is some strange behavior of format, which is (at least part of) the underlying problem.

Using

format(exp(confint(mod5)), digits = 3)

returns the correct results:

##     2.5 %  97.5 %
## age "1.07" "1.30"

Yet, if one runs

debugonce("prettifyPValue")
prettify(summary(mod5), digits=3)
format(object, digits = 3)

one gets

       coef Hazard Ratio CI (lower) CI (upper) se(coef)    z Pr(>|z|)
1 age 0.162         1.18       1.07        1.3   0.0497 3.25  0.00116

i.e. the 0 is again removed in CI (upper).

The reason is that format.data.frame applies format by columns. I need to check how to fix this.

@hofnerb
Copy link
Owner

hofnerb commented Jan 3, 2019

So in short, the real issue is that trailing zeros are droped despite not requested to do this:

format(1.299, digits = 3, drop0trailing = FALSE)

The option is simply ignored.

@hofnerb hofnerb closed this as completed in d472cf0 Jan 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants