cl.Triangle legitimate zeros converted to NaN
Legitimate zero entries in triangle data (e.g. an origin period had zero loss experience ) are converted to NaN, these entries should remain as zeros, as a zero is distinct & different from missing.
This conversion to NaN causes subsequent issues (see below) as well as others e.g. application of Chainladder projection method results in a NaN ultimate rather than 'zero' for that origin period.
import chainladder as cl
raa = cl.load_sample('raa')
df = raa.dev_to_val().to_frame(keepdims=True)
# set 1988 origin period to zero, e.g. a volatile class with zero loss experience in that year
df.loc[df['origin']=='1988-01-01', 'values'] = 0
raa_adj =cl.Triangle(data=df, origin='origin', development='valuation', columns='values', cumulative=True)
Results in following, would expect to see '0' in the first three entries of 1988 origin period
raa_adj
12 24 36 48 60 72 84 96 108 120
1981 5012.0 8269.0 10907.0 11805.0 13539.0 16181.0 18009.0 18608.0 18662.0 18834.0
1982 106.0 4285.0 5396.0 10666.0 13782.0 15599.0 15496.0 16169.0 16704.0 NaN
1983 3410.0 8992.0 13873.0 16141.0 18735.0 22214.0 22863.0 23466.0 NaN NaN
1984 5655.0 11555.0 15766.0 21266.0 23425.0 26083.0 27067.0 NaN NaN NaN
1985 1092.0 9565.0 15836.0 22169.0 25955.0 26180.0 NaN NaN NaN NaN
1986 1513.0 6445.0 11702.0 12935.0 15852.0 NaN NaN NaN NaN NaN
1987 557.0 4020.0 10946.0 12314.0 NaN NaN NaN NaN NaN NaN
1988 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
1989 3133.0 5395.0 NaN NaN NaN NaN NaN NaN NaN NaN
1990 2063.0 NaN NaN NaN NaN NaN NaN NaN NaN NaN
The 1988 entries are removed from the triangle data:
df_adj = raa_adj.to_frame(keepdims=True)
df_adj.loc[df_adj['origin']=='1988-01-01']
Empty DataFrame
Columns: [origin, development, values]
Index: []
You are correct in recognizing that within the library 0 and nan are treated the same - specifically that all zeros are coerced to nan. You're also correct that in general 0 and nan are not the same thing and under certain situations having a 0 distinct from nan actually matters.
However, those situations (at least in my experience) are rarer than the benefit of having the two coerced to a common value. Take for instance a larger triangle. When I say larger, I'm refering to a triangle with a high cardinality in its index or values:
import chainladder as cl
prism = cl.load_sample('prism')
prism.values

Such a triangle is inherently sparse. This one in particular is at a claim level and for any single claim will only have values for one origin period. Using a sparse array behind the scenes allows us to cram this triangle, equivalent of 130K+ unique triangles, into a memory footprint of 4.6Mb. Pretty amazing! Unfortunately, all sparse representations of data allow for one and only one fill_value, so my choices are:
- Support both
nanand0which will severly impede the memory benefits obtainable on sparse large triangles - Coerce them to be a common value - in this case
nanto support substantially larger throughput of data throughchainladder.
This is not to dismiss your suggestion because I think you are correct in your assertion. But there is a trade-off in doing so, and it is one that I think would relegate the library to being useful on small/toy datasets only.
@jbogaardt, whether this situation is rare depends very much on what type of risk you are analyzing. For those working with aggregated triangles on excess lines / volatile lines this is not an unusual feature of the dataset, and certainly one would hope valid data is not discarded / overwritten.
Also, do not think it needs to be, isn't an additional choice to:
3. Add an argument to the Triangle class to permit the user to specify whether zeros left of the diagonal (i.e. before the valuation date) should be overwritten with NaN. Right of the diagonal, the current NaN would be maintained as is current.
Wouldn't this address the issue, whilst not limiting the performance of the package for large (but sparse) datasets?
In regards to "Such a triangle is inherently sparse", isn't this only because each claim is 'broadcast' to a shape that is consistent across the dataset? I'm guessing this is core to the package, but why is it necessary to do this? If a particular claim has an origin of 2010 why is it necessary to add empty origins after this?
To an end-user, all this can be abstracted away in the simple way you're describing. Easier said than done. The code base is built on the assumption that zeros are coerced to nans. This assumption is relied on throughout the code base. The same is true for the assumption of a common grain. So the amount of rewrite and testing that would need to go into this would need a lot of time/energy. Maybe that's worth it if there are major obstacles, but I'm not seeing it yet. Help me understand the case you're running into where coercing 0 to nan causes a real problem and not just a theoretical one.
The real, practical problem is that when multiple triangles are loaded into a triangle class, the end user has no way of telling from the cl.Triangle class:
- when a particular triangle started (or potentially finished)
- whether a given year had zero loss or whether it is missing
- whether valuation stops or the loss reduced to zero
This is because both the shape of the original data is standardized AND zeros are coerced to np.nan in the triangle class. Combined this manipulation results in loss of information.
An alternative is to create separate triangle classes for each original triangle, but initializing separate triangle classes is quite a lot slower, and other issues persist e.g. tri.loc['b'].to_frame(keepdims=True) the nan cells are not returned (so original data cannot not be extracted / reconstituted)
Example loss of info below:
import chainladder as cl
import pandas as pd
raa = cl.load_sample('raa')
# create lob a
df_a = raa.dev_to_val().to_frame(keepdims=True).reset_index()
df_a['Total'] = 'a'
# create lob b
df_b = df_a.copy()
df_b['Total'] = 'b'
# say, lob B started in 1984
df_b = df_b.loc[df_b['origin'] > '1984-01-01']
# lob b is volatile line with some loss free years, particularly at start owing to lower volume
zero_years = df_b['origin'].isin(['1985-01-01','1986-01-01','1989-01-01'])
df_b.loc[zero_years,'values'] = 0
#combine a & b
df = pd.concat([df_a, df_b])
tri= cl.Triangle(data=df, origin='origin', development='valuation', columns='values', index='Total', cumulative=True)
# cannot tell when this LOB started, or that first two years were loss free
tri.loc['b']
Thank you. This is an extremely clear example and it is evident that you're getting knowledgeable of the library nuances. But is this something that really needs a change in the code base or is it just part of the actuary's workflow?
In terms of estimating unpaid claims, the projections would be unaffected. Under a Chainladder approach, the ultimate_ for those claim free years wil be nan which can be considered 0. If you are going to apply an expected loss method like BonhuetterFerguson or CapeCod, you will have an exposure vector that would tell you that those loss free years have some exposure and your ultimate_ would be non-zero.
Alternatively, If you really want to hack things, you can just replace the zeros in your data with some value that is effectively zero. For example:
df_b.loc[zero_years,'values'] = 1e-100
Doing this will restore the "lost" information, while being no less accurate than the floating point precision errors inherent in python in general. This hack can probably be added to the Triangle constructor as an extra option, maybe with coerce_zero_to_nan=False argument. It would then not need a wholesale rewrite of the library.
Could you point me to the code base where this becomes a problem? I'm struggling to understand why 0.0 should be problematic vs any other float. Is it div zero style problems?
Picking up on some points: "is this something that really needs a change in the code base or is it just part of the actuary's workflow?" it certainly causes workflow issues, but in itself, this is a data handling problem.
" for those claim free years will be nan which can be considered 0"
this is the whole issue / aim of the example, in some cases it is not possible to know which years are loss free and which ones are missing. As you point out this is true for Chainladder, I've also come across this when extracting the data from the triangle class using .to_frame the original triangle is lost, latest_diagonal also becomes ambiguous.
"Doing this will restore the "lost" information" Strictly, it introduces false information as well as new issues, for one age_to_age factors blow up....
The main issue is the sparse support I mention in my first comment. Anywhere in the code base you see num_to_nan or nan_to_num, we're invoking the assumption that nan == 0. Its everywhere, and there is 0 chance...wait, there is nan chance (see what I did there 😄) that I will personally prioritize this issue. There are so many ways the library functionality can be expanded for the better, but this one gives a very low return on time investment. Again, you're right in your assessment of the issue, but I just value my time too much to do anything about it, let alone continue arguing about it. All this to say - you are welcome to make a PR to get the functionality you want without creating issues elsewhere. If you have no intention of making a PR, then I will close this issue as out of scope.
I see what has been done, the great excel tradition of confusing zero's and nans has persevered :persevere:
Appreciate the degree to which this matters to you is dependent on your use case, its just unfortunate that this is imbedded in the core data structure.
Please keep open for a while, I'll see if I can take a look.
We are running into the same problem here, and have been using the df_b.loc[zero_years,'values'] = 1e-100 alternative for now. This fixes the issue for chainladder, but now results in very large (close to infinite) Mack Chainladder variances as the parameter error divides by 1e-100. @goduckie have you done any further work on a workaround for the NaN vs 0 issue?
I believe there's interest in taking this on (bringing in @kennethshsu and @henrydingliu for their opinions). At least from a reinsurance perspective, we have the opposite data issue, we only get a handful of triangles per submission, and thus have a low need for memory optimization, with lots of NaNs vs. zeroes due to the focus on pricing specific layers, long-tail lines, and due to data acquisition challenges from cedents.
Furthermore, I think NaN arithmetic and boolean logic should be consistent with general computing tools, and that we should minimize the number of gotchas - i.e., "this package does certain things differently from all the other packages and here's a big list of them." Achieving this synchronization will improve the adoption of the package with the general public.
To respect how big of an undertaking this would be, I need to understand whether this is a fundamental limitation of sparse, or if it's because a large amount of code is built with the assumption that NaN == 0, or both, or if there are other reasons involved, which is something I'm struggling with. If it's moreso the 2nd issue, our ability to break down large tasks and assign them across members of the working group has improved in recent months, and we may be able to pull it off. It's a bigger problem if it's because of sparse.
And then, if we are to take this on, how we'd even do it:
- Should we create a separate development branch, subject to reviews just like main?
- How do we incorporate ongoing development in
maininto the branch? - If people are still developing features on the assumption that NaN == 0, how do we merge these into the development branch?
i use chainladder for individual account pricing, basically fac desk stuff. so less data than your treaty bros deal with. the NaN vs 0 stuff is annoying, but has never been a showstopper. most of the time legitimate 0 ends up giving you as much info as a NaN, and don't need to be treated separately.
if we are a little bit more rigorous with how often we check for valuation <= valuation_date, i think we can resolve a good amount of this NaN business without major API redesign. we'd still have to refactor a good chunk of code, mind you, but it'd be fairly straight forward.
by extension, if we can assure ourselves that the reinsurance use case is met by the addition of a first_valuation_date, i.e. don't turn zeros to NaN when first_valuation_date <= valuation <= valuation_date. it would be a small addition to the API. still a lot of refactoring, but still straightforward.
the approach i would actually want to convince you to take, is to dump sparse altogether. sparse essentially enables efficient storage of claim-level triangle, and some 4d manipulation using .coord. but claim-level triangles cant be used during training (i.e. deriving ldf_), which means that there was actually never a need to store claim-level amounts in triangles, if we simply allowed Chainladder.predict to accept a 2D dataframe directly (i.e. join ldf_ based on age). this is what xgboost and other popular sklearn extensions do, 'give me a standard Pandas dataframe, never mind how we manipulate that dataframe behind the scene'.
but all of this should happen after 1.0. im still finding basic arithmetic bugs in the package through friedland recreation (e.g. #1024). 1.0 should be our "perfect fidelity but shitty internal" release. it gives people something they can keep using forever. then we can start removing legacy bits in 1.x.
I'm open to replacing the backend array at some point, I'm not wed to sparse, and I think it would be prudent to recognize that libraries are refactored as they age to improve performance.
We could probably even write a paper about this at some point, a package that has an externally-facing data structure in Triangle form (readable by actuaries), but an internal representation that might not be that shape (per Clark's paper).
Fixing the NaNs vs. 0 is the more important issue to me at the moment. Regarding your comment in https://github.com/casact/chainladder-python/issues/1029, I think it would be a problem for a new contributor if they didn't know the NaN == 0 assumption, and worse if they balked after being told about it. Even though I, poking around the library as many years as I have, was aware of this assumption, but not how it was applied (thought it was purely a sparse thing). But when I was working on Triangle.fillna(), I realized that the coercion happens purposefully throughout the package and a newcomer would have to do the same if they want to contribute.
I'm open to replacing the backend array at some point
I'm not talking about replacing the backend. i'm talking about removing sparse and maintaining numpy as the only backend. if we only had to support numpy, the 0 vs nan thing become infinitely simpler to resolve.
the need for sparse underlies a very real use case, claim level ultimates (note, not claim level patterns, which is neither practical nor advisable). we can solve for claim level ultimate by allowing Method.predict to accept Dataframe. This doesn't mean backend change. It just means we apply ldf_ to Dataframes.
Fixing the NaNs vs. 0 is the more important issue to me at the moment.
Can you please bring real-life examples where this is a showstopper in an actual application? I'd be happy to solve each and every one and turn each into a gallery example. i say this because i have looked at every related issue and have yet to see the user explaining how they are being stopped from proceeding.
- this issue doesn't present a showstopping situation. having an empty origin doesn't stop the rest of the package from working.
- #164 should have been resolved a long ago as John improved the underlying implementation in an earlier .8.x. I just confirmed and closed it. feel free to double check. and given the similar timeframe as this issue, it's likely that if the OP of this issue gave a more detailed example, we can also prove that it's been resolved
- I don't consider #694 to be a realistic scenario. the business narrative would basically be, "when this other estimate doesn't exist, the sum of these two estimates also doesn't exist". it just doesn't come up. and if there some corner cases I'm not thinking about, just do
tri1.values + tri2.values. - the xyz issue in #695 is definitely annoying. i've actually ran into real world problems in
IncrementalAdditive, and had to resolve it manually viadrop_valuation. but sincedrop_valuationdoes exist and passes all tests, it's still not a showstopper.
I think it would be a problem for a new contributor if they didn't know the NaN == 0 assumption, and worse if they balked after being told about it.
I find this highly unlikely. every single one of us has had to learn and work around how excel deals with errors and 0s and blanks. there are much quirkier things in this package that could drive users away than NaNs vs 0's. certainly i'm not pulling a whataboutism to excuse our long-term tolerance of the zero vs NaN issue. It can be the first issue we tackle post 1.0. But as long as it's not a showstopper in real world analyses, then to me it does not need to be resolved prior to 1.0.
i'm talking about removing sparse and maintaining numpy as the only backend.
I'm still on the fence. Admittedly, if I were to have designed my own reserving package I would have stuck with many small triangles (no index dimension) and parallelized them with spark if I needed more compute, rather than have a really big triangle with lots of index rows. Even then, I rarely work with more than one triangle at a time, maybe a handful if I'm doing a side-by-side visual comparison, so it probably would have never entered my mind to use anything but numpy. But after seeing how sparse is used John, I get the motivations. Plus, I think there's just the apprehension that comes when dropping a feature that clearly shows a huge reduction in memory footprint.
Can you please bring real-life examples where this is a showstopper in an actual application?
We get errors when trying to work with incrementals:
import chainladder as cl
import numpy as np
tri = cl.Triangle(
data={
'origin': [1985, 1985, 1985, 1985, 1986, 1986, 1986, 1987, 1987, 1988],
'development': [1985, 1986, 1987, 1988, 1986, 1987, 1988, 1987, 1988, 1988],
'paid': [np.nan, 500, 400, 300, 100, 400, 500, 200, 300, 500]
},
origin='origin',
development='development',
columns='paid',
cumulative=False
)
print(tri)
print(tri.incr_to_cum())
12 24 36 48
1985 NaN 500.0 400.0 300.0
1986 100.0 400.0 500.0 NaN
1987 200.0 300.0 NaN NaN
1988 500.0 NaN NaN NaN
12 24 36 48
1985 NaN 500.0 900.0 1200.0
1986 100.0 500.0 1000.0 NaN
1987 200.0 500.0 NaN NaN
1988 500.0 NaN NaN NaN
The whole top row should really be NaN:
12 24 36 48
1985 NaN NaN NaN NaN
1986 100.0 500.0 1000.0 NaN
1987 200.0 500.0 NaN NaN
1988 500.0 NaN NaN NaN
This type of bug might not get caught until a project has reached a late stage, or if there's any gap in a reconciliation check, one might erroneously try to impute the NaN after cumulation.
Maybe there's a workaround, but workarounds/hacks are the type of thing I'd like to eliminate by participating in open-source development.
It can be the first issue we tackle post 1.0.
As long as I have you on board with keeping this issue as to-do, I'm OK.
I'm still on the fence. Admittedly, if I were to have designed my own reserving package I would have stuck with many small triangles (no index dimension) and parallelized them with spark if I needed more compute, rather than have a really big triangle with lots of index rows. Even then, I rarely work with more than one triangle at a time, maybe a handful if I'm doing a side-by-side visual comparison, so it probably would have never entered my mind to use anything but numpy. But after seeing how sparse is used John, I get the motivations. Plus, I think there's just the apprehension that comes when dropping a feature that clearly shows a huge reduction in memory footprint.
we are still talking past each other a little bit. i'm not suggesting that we'd leave the users hanging on the claim-level ultimate use case. i'm saying that sparse was never necessary for the claim-level ultimate use case. (to make sure we don't talk past each other again, the huge memory usage of a claim-level dense triangle is the engineering challenge. the underlying business use case is still claim-level ultimate.)
the key fact to consider here is that a claim-level triangle is NEVER directly used for training/fitting, i.e. no one would ever go cl.Development().fit(prism). It's always either cl.Development(groupby).fit(prism) or cl.Development().fit(prism.sum()). said in another way, the ldf_ is always estimated off of a dense triangle. so the mold we actually need to break here isn't how to extend sparse support, but to separate data storage and model algo.
what i mean by separating data storage and model algo is this, right now chainladder forces the user to store claims data inside triangles and then also use triangles to estimate ldf. this is actually highly unusual. for example, sklearn doesn't require a user to have any understanding of its highly optimized index-based node traversal prior to using its random forest models. instead, user can keep the data in a pandas dataframe, and sklearn takes care of the tree and node business. this is the usage pattern we should ultimately strive for, i.e. let the user keep the claims data in dataframes, and chainladder will create private triangle objects within the estimators to derive ldf_.
claim_df = pd.read_csv(cl.sample_url('prism'))
training_df = claim_df[[origin_col,development_col,amount_col]]
pipe = cl.Pipeline(
steps = [
('dev', cl.Development(average='volume')),
('tail', cl.TailCurve('exponential')),
('ibnr', cl.Chainladder())
]
)
model = pipe.fit(training_df)
ult = model.predict(claim_df)
and in this usage pattern, there is simply no need for a sparse triangle. claim_df is memory efficient in and of itself. every private triangle inside model is dense. and ult adds a column to claim_df and therefore similarly memory efficient.
We get errors when trying to work with incrementals:
i'll be honest. this rather contrived example only convinces me further that the NaN vs 0 distinction is entirely theoretical and not a practical bug that we need to prioritize.
-
i would not expect the np.nan to naturally arise in any underlying incremental claims dataset. if an old diagonal of incremental data is somehow missing, every other downstream application would fail simply because sql, pandas, spark, excel sumif, pivot table, etc. would all treat the missing data as a legitimate 0. basically neither
select origin,development,sum(paid) from _ group by 1,2nordf.groupby('origin','development').sum()would return a (1985,12,null). meaning, any unexpected behavior in chainladder is really the least of the user's problems. so we should fully expect that the user is always aware of any missing incremental data points. therefore, this example would never arise in practice. -
we can also look at this from the sklearn precedent angle. many sklearn models don't accept nulls. instead, sklearn expects user to impute or just filter it out of the underlying data in pandas. impute in our case would equivalent to assuming it's a legitimate 0, which is already the package behavior. filtering would be done in Pandas, so it still wouldn't require any change in chainladder. would you call the transformers of
sklearn.imputeworkarounds? we have to assume some basic level of data quality, don't we? -
what behavior would you expect from this triangle?
tri = cl.Triangle(
data={
'origin': [1985, 1985, 1985, 1986, 1986, 1986, 1987, 1987, 1988],
'development': [1986, 1987, 1988, 1986, 1987, 1988, 1987, 1988, 1988],
'paid': [500, 400, 300, 100, 400, 500, 200, 300, 500]
},
origin='origin',
development='development',
columns='paid',
cumulative=False
)
this is the triangle that's far more likely to arise in practice. and both legitimate no claim activity and faulty, missing data could result in this triangle. we can't expect our package to know what's the correct treatment because it simply doesn't have enough info. if (1985,12,NaN) is that additional info we expect the user to add, then I would say that's very silly of us to ask the user to supply that additional data point, because the user ends up with no data in that origin period. instead, we should just tell the user to filter out that origin period.
fyi, I do intend to get through your last comment when we get closer to work on this. I just need to write down a new example because I encountered it and don't want to lose it.
This time it interferes with the proposed styler because the highlighting relies on boolean flags. If we wanted to highlight different colors between NaN and 0, it would be hard to do so without roundabout programming.
Here is one that doesn't stop a fit but changes the answer. When a row's cumulative count is still zero at one age, Development leaves that row out of the next factor, so claims that arrive after a zero never enter the pattern:
import pandas as pd
import chainladder as cl
# Cumulative claim counts; the 2022 origin has none reported at age 12.
df = pd.DataFrame({"origin": [2021, 2021, 2021, 2022, 2022, 2023],
"valuation": [2021, 2022, 2023, 2022, 2023, 2023],
"count": [2, 4, 4, 0, 3, 1]})
tri = cl.Triangle(df, origin="origin", valuation="valuation",
columns="count", cumulative=True)
for fillna in [None, 1e-9, 0.5]:
dev = cl.Development(fillna=fillna).fit(tri)
print(fillna, dev.ldf_.values[0, 0, 0, 0].round(4))
tiny = cl.Triangle(df.replace({"count": {0: 1e-100}}), origin="origin",
valuation="valuation", columns="count", cumulative=True)
print("0 set to 1e-100:", cl.Development().fit(tiny).ldf_.values[0, 0, 0, 0].round(4))
print("keeping the 2022 row:", (4 + 3) / (2 + 0))
None 2.0
1e-09 2.0
0.5 1.8
0 set to 1e-100: 3.5
keeping the 2022 row: 3.5
Development(fillna=…), which is separate from the Triangle.fillna in #1581, doesn't bring the row back, because the weights come from the unfilled triangle (development.py L382–L383, L426). Adding 0.5 only changes the rows already counted: 4.5 / 2.5 = 1.8. The 1e-100 workaround described above keeps the row, though as reported there it makes the Mack variances very large.
How much it matters:
- I simulated a small, fast-growing book: 24 monthly cohorts growing from 150 to 3,000 policies, Poisson claim counts at 0.4% of policies, reported 0 to 8 months after the cohort month. Over 300 runs the first factor averages 1.69 against the 1.86 implied by the reporting pattern, and 1.88 with the zero rows kept. That holds for this design only.
- In
clrdpaid losses on main (0e5a7a9b), 152 of the 722 non-empty triangles drop only rows like this. Keeping those rows raises the ultimate by more than 1% in 51 of them and by more than 5% in 24, and lowers it in none. With the renamed rows in #1580 (12dd4e13) the counts are 154 of 725, 52 and 25.clrdstores zeros as NaN, so these counts treat every blank inside the observed triangle as zero.
If it helps, I can turn the simulated book into a gallery example showing the low first factor and the IBNR it leaves out.
(This comment was made with Árbol, an AI assistant, under my direction.)
i'm not sure i'm following what the snippet is trying to accomplish. is this an accurate summary of the scenario: "when fillna is used, NaN vs 0 matters in the original triangle?"
Not quite: fillna isn't needed. The scenario is an origin whose cumulative count is a real 0 at one age and positive later. The 0 is stored as NaN, so that origin's link ratio is NaN and the origin drops out of the next factor:
import pandas as pd
import chainladder as cl
df = pd.DataFrame({"origin": [2021, 2021, 2021, 2022, 2022, 2023],
"valuation": [2021, 2022, 2023, 2022, 2023, 2023],
"count": [2, 4, 4, 0, 3, 1]})
tri = cl.Triangle(df, origin="origin", valuation="valuation",
columns="count", cumulative=True)
print(tri)
print(cl.Development().fit(tri).ldf_.values[0, 0, 0, 0])
12 24 36
2021 2.0 4.0 4.0
2022 NaN 3.0 NaN
2023 1.0 NaN NaN
2.0
The 12-24 factor comes from 2021 alone (4 / 2). Counting 2022's zero, the volume-weighted factor is (4 + 3) / (2 + 0) = 3.5, and 2023's ultimate goes from 2.0 to 3.5. Nothing errors or warns, so the low factor is easy to miss. The fillna lines in my earlier snippet were only there to show that Development(fillna=…) doesn't bring the row back.
A closer summary: "a legitimate cumulative zero becomes NaN, so an origin whose first claims arrive after that age is left out of the next factor."
(This comment was made with Árbol, an AI assistant, under my direction.)
for starters, i can tell you from personal experience that if an ldf calc would include the 0, i.e. use (4 + 3) / (2 + 0) = 3.5, that calc would get flagged by a big 4 auditor. so even if it was theoretically correct, it is practically a dead end.
continuing down this practical angle, it's very counterintuitive to end up with a factor of 3.5 when the largest underlying data point is 2. this is actually how the big 4 auditor will catch this calc.
then we can come back to the theoretical angle, (4 + 3) / (2 + 0) is only a simplification of the actual theoretical calc, the actual theoretical underpinning is a thru-origin weighted regression using inverse weights. any point that lies on the line of x=0 in a thru-origin regression doesn't impact the regression, because y-hat ≡ 0 when x = 0. so in this case, (4+3) / (2+0) is an incorrect simplification of the theory.
all this means that one of the first things we'd have to do once we separate 0's and NaN's, is to treat 0 like a NaN in WeightedRegression.