LSYS / forestplot

A Python package to make publication-ready but customizable coefficient plots.
http://forestplot.rtfd.io
MIT License
110 stars 10 forks source link

"ValueError: 'xerr' must not contain negative values." #109

Closed Aleksandra130501 closed 4 weeks ago

Aleksandra130501 commented 7 months ago

Hello!

Thank you for creating the package. It has been very helpful for my ongoing project. I've been using it for the last few months and and it was working consistently. However, I've been having a few problems which I don't know how to solve and I was hoping to get some help.

First, when attempting to include confidence intervals (ll and hl), I am facing the error "ValueError: 'xerr' must not contain negative values." The presence of negative values in these intervals appears to be the culprit. It's worth noting that the code was working flawlessly in the past when run on the same data. So, I am confused by this unexpected behavior.

Second, despite setting color_alt_rows=True, the alternate row colors are not being applied as expected. This feature has worked consistently in the past, and I'm curious if there are any recent changes or considerations that might be causing this behavior.

LSYS commented 6 months ago

@Aleksandra130501 do you have minimal code and data example i can use to reproduce your error?

jdoiii commented 4 months ago

Re: "ValueError: 'xerr' must not contain negative values."

I just experienced this when my ll and hl were reversed. So you might check that.

liberaliscomputing commented 2 months ago

Okay, it looks like this error was reported a while ago but hasn't been addressed yet. I am encountering the same issue, and here is my data to reproduce the error:

Feature 2.5% 97.5% Hazard Ratio P-Value
A -0.04648966464888837 0.0 -0.04648966464888837 0.3350452166432467
B -0.8005247375433439 0.5701691566719239 -0.38434257677120126 0.006641928833643199
C -0.33113731133310487 0.44139267172092117 -0.31872569342925067 2.190067566321477e-11
D -1.1880290522910695 0.0 -1.1880290522910695 0.1400575074820416
E -2.8947220058702707 0.0 -2.8947220058702707 9.727875422296087e-26
F 0.0 0.42644904860853605 0.42644904860853605 7.67960958911707e-12
G 0.0 0.5733555387058998 0.5733555387058998 0.05833119779119948
H -0.10147319767844853 0.4652267607167055 -0.1902549025737849 0.004463957869426125
I -0.2798907958523989 0.5057675784701245 -0.30153798443035834 0.005622582125245007
J -0.17460690918051475 0.04782450978582678 -0.04795539250903285 0.807628734304761
K -0.1476066210644793 0.02061662829224276 -0.04448952374821284 0.0095816270092731
L -0.0816839667613319 0.08091723921613089 0.03629314588938769 0.41419942550589406
M -0.0008517369643846185 0.0010696352038619054 -0.00048626534176460614 0.8575576462554562
N -0.06718350141640646 0.05908972206597604 -0.03010969140184373 0.24036296811563654
O -0.03992798162342058 0.06166542353256832 0.027742311864226682 0.3465652654453217
P -0.014570568896721085 0.011389074369654193 -0.007022462662996824 0.6138101825035815

Here is my code:

import forestplot as fp

# "forest" below is the above data frame.

fp.forestplot(
    forest,
    estimate="Hazard Ratio",
    ll="2.5%",
    hl="97.5%",
    varlabel="Feature",
    sort=True,
    pval="P-Value",
    annote=["est_ci"],
    annoteheaders=["Hazard Ratio (95% Conf. Int.)"],
    rightannote=["formatted_pval"],
    right_annoteheaders=["P-Value"],
    xlabel="Hazard Ratio",
    table=True,
)

Here is the error message:

ValueError: 'xerr' must not contain negative values
jdoiii commented 2 months ago

In Feature A, D, E, "Hazard Ratio" and "2.5%" look to be identical, and in Feature F and G, "Hazard Ratio" and "97.5%" are identical. What happens if you remove those and rerun the data?

If that fixes the problem, then you may need to fudge the 2.5% values or 97.5% values to make the lower limits slightly lower than the Hazard Ratios or the higher limits slightly higher.

LSYS commented 2 months ago

@jdoiii good catch. @liberaliscomputing Please try that. I had a similar issue when the estimate was (erroneously) higher/lower than the upper/lower confidence limits.

github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 4 weeks ago

This issue was closed because it has been inactive.