Skip to content

std_residual_ subtraction computation creates NaN when residuals are 0 #639

@danielfong-act

Description

@danielfong-act

Are you on the latest chainladder version?

  • Yes, this bug occurs on the latest version.

Describe the bug in words

The standardized residual triangle computed here is missing the last value of origin year 1981. I think this is a floating point error caused by residual computation subtracting two numbers that are very close. This can happen at either end of the latest valuation of the triangle. Edit: This doesn't always happen when subtracting two very close numbers, and I'm not sure what causes the subtraction issue exactly.

I noticed similar behavior in BarnettZehnwirth's computatino of standardized residuals, but didn't note down the steps to replicate it. Replacing regular subtraction operations with np.subtract seems to rectify this problem.

Subtraction is a pretty common operation and I'm not sure if/how commonly this creates a problem elsewhere. I suspect it does, so I'll amend this issue if someone finds something else.

How can the bug be reproduced?

From the development section of the user guide

import chainladder as cl
raa = cl.load_sample('raa')
model = cl.Development().fit(raa)
model.std_residuals_

setting a breakpoint within development.py where resid is computed makes the problem more obvious

What is the expected behavior?

That NaN should be 0.0 instead

Metadata

Metadata

Assignees

No one assigned

    Labels

    Triage Pending ⚠️New issues that haven't yet been reviewed or categorized.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions