You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
REF: Pearson estimate of scale parameter/Tweedie parameter with weights #2915
I'm a little confused over how to interpret the Pearson estimates for the scale parameter and a shape parameter in a frequency dataset.
The Pearson estimate of scale is as follows:
If I have 1 record representing 1 year of a policy and it has 1 claim, then the frequency (which is the same as endog and Y) equals 1.
If I split that record into 2 separate 6-month records, then I now have 1 record with a frequency of 2 and a separate record with a frequency of 0. (The claim only occurs once... the only difference is how the data is laid out). Mu is the same between all the scenarios. It becomes pretty intuitive to see that you will get a different estimate of phi based off of my (somewhat) arbitrary splits in the policy.
Is there an adjustment that we could do to the Pearson estimate so that 1 12-month record and 2 six-month records, with 1 annual claim in each scenario, would give the same estimate of scale?
Do you mean the rate (case per period) with frequency? (frequency makes me think of time series)
I haven't done the math yet, so I'm thinking mainly of Poisson and WLS for the following.
The scale parameter phi is relative to something. In general rescaling the process changes the scale.
In terms of exposure (e.g. total time for a Poisson process)
In the first case exposure is 1 (year). In the second case exposure is half a year, so units will be per half year, i.e. the arrival rate = 2 per half year for the first observation.
(... explanation doesn't work because Poisson process doesn't have exess dispersion, so I'm thinking more about mean than dispersion.)
When we predict the mean then we want to standardize the exposure to say for example what's the arrival/claim rate per year. (Like quoting annualized interest rate, even if it's calculated monthly.)
There should be a similar "annualization" for the dispersion or variance but I haven't figured out completely how aggregation works if there is excess dispersion. (QMLE instead of MLE)
For variance (not dispersion) we have that the variance of the sum is n times the variance of each splitted fragment. (back of the envelope calculation)
but in Tweedie or GLM we have the separation between variance function (as function of mean) and the dispersion phi.
another problem: only Poisson distribution is the count distribution that is time homogeneous, other count distributions don't split up into subperiods in the simple additive way.
however, Tweedie as compound Poisson is a time homogeneous process. so we need to link the dispersion coefficient of the tweedie distribution to the sum of claim sizes per standardized unit of time.
based on another quick derivation by hand: the dispersion per subperiod would have to be divided by n**(p-1) to arrive at the dispersion per period, if there are n subperiods per period.
something like this, I haven't seen it in any reference. (thinking while writing, no guarantees)
We need to check at least the distribution of the sum for some special cases like Gamma.
@josef-pkt As usual, you've hit the nail on the head with your interpretation of what I'm writing. By frequency, I mean the number of claims reported per year of policy in-force. (Actuarial texts generally define frequency as claims per unit of exposure... so much different usage for "frequency" and "exposure" than a statistician--or economist--would like. "Exposure" is a unit to measure the financial losses that arise in some insured "thing". "Exposure" can be a percent of annual payroll for workman's compensation, a car-year for automobile insurance, a house-year for home insurance, or annual-miles driven for a pay-by-the-mile auto insurance policy.)
If you stumble across any papers on annualization of phi/scale parameter (a quick google search wasn't fruitful), let me know. Maybe "annualization" isn't the right word...
I didn't find anything yet to verify the dispersion calculation. However, the properties of the variance when aggregating are standard. for example the variance of a compound poisson process is proportional to the time length. So the sub periods should have 1/n times the variance of the full period sum.
What this implies for the dispersion coefficient depends on the shape of the variance function, since the mean also increases also linearly in aggregating subperiods
phi = lambda**(1-p) / (2 - p)
where p = (alpha + 2) / (alpha + 1) alpha is one of the Gamma parameters
Smyth and Jorgensen p. 146 ASTIn Bulletin Vol 32(1) 2002
lambda is the Poisson rate, for given exposure time t, the rate will be lambda * t, so dispersion parameter depends on exposure time through t**(1 - p) (same as what I had above)
I'm just reading the Smyth and Jorgensen 2002 article and they use double exponential to allow dispersion to vary depending on explanatory variables, e.g. if the variance of the gamma claim size distribution varies with subgroups of the population or type of insurance policy separately from the poisson claim frequency.
This reminds me now that we haven't checked the usage of exposure in Tweedie.
I finished reading Smyth and Jorgensen 2002 yesterday. It's a good paper that makes a clear distinction between claim cost only data, and the joint model for claim count and claim cost.
They use w everywhere to normalize for exposure, but I'm not sure what w really is and how this fit's in the code, i.e. exposure or var_weights. For the parameter estimates itself all weights and multiplicative exposure are the same (with appropriate scaling of endog).
partially related:
issues for weights and
issues for aggregation #2831#2840
w_i is the "units at risk". (First paragraph of section 2 of the paper.) I interpret that to be "exposure" more than var_weights. (I've been thinking of them as freq_weights). In other words, if I have a policy in force for 6 months, and it has 2 claims, the rate of claims per year (paper calls it frequency) is 4 (= 2 / 0.5).
I'm thinking a full Tweedie approach would look (something) like this...
Fit GLM Tweedie model with initial estimate of p (say 1.5). (endog is dollars of loss / years at risk)
Calculate new p using step 1 and the estimate_tweedie_power function.
Refit 1, but use updated p from 2.
Repeat between 2 and 3 until converged.
use phi = lambda**(1-p) / (2 - p) to estimate cov_params. For lambda, use mean frequency of the entire dataset. cov_params will then reflect standard errors/z-scores that represent annual variation.
So in other words, I'll have one phi that's used in the esimation of p and a separate phi that used only for calcualting cov_params.
The only thing that (somewhat) concerns me here is that the paper makes it seem phi shoudl really be a vector... and different for each observation. Considering that some of my observations are 1 months of risk and others are 6 months of risk. I'm not convinced if having a vector of phi (as opposed to 2 scalars for these purposes) is of any value.
(just briefly, comment about w_i will follow later)
step 5 doesn't work, steps 1-4 are good
lambda also depends on the explanatory variables and varies by observation, AFAIU.
The calculation go the other way, lambda for the compound Poisson is implied by our estimated parameters for mean and variance.
Now something is strange: because if lambda varies, then phi = lambda**(1-p) / (2 - p) would also vary.
(We really need the functions to move between Tweedie and compound Poisson parameterization so it's easier to understand.)
in terms of expectation (mean)
mean(endog) = E(tweedie) = E(Poisson) * E(Gamma)
cov_params should be independent of any equivalent rescaling of the data.
But we can calculate functions of the estimated parameters that renormalize the parameters and calculate the standard errors for those.
e.g. for the "multiplicities" we want the exponential form of the parameters exp(params) with associated standard errors and confidence interval.
Now something is strange: because if lambda varies, then phi = lambda**(1-p) / (2 - p) would also vary.
I've thought about that in the past as well. What I was thinking is that you could have a vector of phi instead of a scalar. I see that all the math would still work, with the exception of cov_params which is just cov_params = scale * normalized_cov_params. normalized_cov_params is a calculation for the WLS module =
(Full disclosure, my only real interest in this whole issue is that cov_params is awfully high, when I'm confident it shouldn't be. I can a Poisson model on count data and have cov_params be quite reasonable. But with Tweedie, cov_params become really high. I presumed issue was that Pearson seems influenced when you split records. (I think this is an estimate of the hessian?)
Granted, there's a lot of moving parts that go into cov_params... I could be looking in the wrong place. Its just that scale seems the most flexible concept we have, and the one I haven't gotten my mind wrapped fully around. (Especially scale when you have records with different freq_weights in the data...)
P.S... when I got involved with you, I really thought I'd be able to make a handful of fixes and be finished. It does seem that with stats, the deeper I go, the more I realize I don't know... Hopefully there's a bottom to the ocean.
There is no bottom to the ocean. But we might be at a level that is appropriate for what we want or need to do.
You could try cov_type='HC0' in fit, and see whether it's close to what you expect. It doesn't use the builtin scale.
I'm not quite sure about the interaction of exposure and frequency weights.
Do your frequency weights vary a lot?
You could check if you get cov_params closer to what you expect when you don't use freq_weights.
Just a sanity check: integer division
Are you using python 2 or python 3?
Did you check that your total freq_weights is equal to total nobs/exposure when you split the data?
I'm partway through coding the transformation function and a random sampler for compound poisson and tweedie. I hope it helps to look more closely at what's going on.
My intuition is also that there should be some additivity like this, maybe not strict, but we should at least roughly get the same standard errors. What is even stranger is that the standard errors bse are larger in the split data than in the aggregated sample. If we have more detailed information, like per half year instead of per year observations, then the precision of our estimates should increase (unless the model is misspecified and we pick up more information that conflicts with the model, I think)
I think the way you split up the data and used frequency weights is not the right way to do this for inference. If I use exposure instead of frequency weights, or if I leave off the frequency weights, then the bse is only a little bit larger in the split model than in the original model.
On the other hand, additivity might not be possible without including the count, number of claims in an observation. (maybe unless there is only a very small probability to have more than one claim per period, so it's essentially just zero or one claim).
When there is a large payment in one period, then tweedie has to allocate the total payment between number of claims and size of a single claim. It could be that tweedie is a good, approximately correct model for some aggregation level but a bad model for others.
For example (I didn't try to read anything and don't know any details, but it's mentioned in Jorgensen articles). roughly: some distributions converge to a Tweedie distribution similar to convergence to the normal distribution by the law of large numbers. So Tweedie could be good approximation for aggregated samples but could be a inappropriate, misspecified model for disaggregated data. (*)
When we work with actual data, it can be difficult to guess what are the effects of a model (given that we don't know all the statistical theory) and what are the effects of using a misspecified model.
Add the end I did a similar experiment by summing each consecutive two observations (which have the same exog). This means that initially I have half year data that I combine into one year data. (exposure is per half year) (or we could take initially one year and then we combine two years)
Using exposure, I get exactly (at a few decimals) the same numbers in both cases.
With frequency weights the bse differ a bit (assuming each combined observation has frequency 2 with half the endog in the last case in notebook).
Without frequency weights (freq_weights=1), the bse is the same with the 2period aggregate as in the separate period case, but the estimated means double, because we have no normalized to 2 period exposure.
So my guess is that frequency weights don't do the appropriate thing for this case. The correct interpretation requires exposure, and endog as the total claims for the exposure time.
Another guess is that we might need var_weights if the endog is a mean over some observations.
This is with simulated tweedie in a large sample, so it rules out misspecification of the underlying model.
@josef-pkt I have another problem I want to talk through. So bear with me.
I agree--in general--that exposure is the correct thing to use here. I think var_weights is incorrect because I'm not so certain that dispersion--(endog - mu) ** 2--scales linearly with time. In fact, I would think this is not the case. (Let me know if my understanding of dispersion is flawed.)
(Note to self, the paper is from a bio-statistics perspective. We essentially have "observations"--which the paper calls sites--and each observation has 1 replicate. I presume that just dropping the 1 / (n_i - 1) piece is harmless.)
The author presents this formula...
And using a log\gamma GLM, we should be able to solve for a and b.
However, when doing this on my 3.5 million record dataset, it didn't work. I read this section...
Should I be weighting this somehow, perhaps? Maybe based on Exposure? I played with some different ideas and think this is probably as close to something reasonable as I could find...
np.exp(10.4552) == 34724.473308301465 vs the pearson x2 estimate of 6147.95962013. (So not good.)
However, p == 1.1295 is believable to me...
On a side note, I now think that that our shortcut doesn't work well when you have different exposures. I'm fairly certain that we might need to adjust this to account for exposures better. I just don't know where/how to do it... I appreciate any ideas. Recall that we plug 3.8 into 3.9, and then use the brentq optimizer to set this equal to 0.
I'll try to look at it tonight (Central European Time), I don't remember the details now.
Yes, I think the pearson estimate needs to take account of exposure as in (3.9) in your comment. This needs to be fixed (for 0.8) if it doesn't do it correctly.
in estimate_tweedie_power, we could try to replace endog and mu by the exposure corrected values
endog = self.endog / exposure
mu = mu / exposure
where exposure is the correct exponentiated exposure (internally still stored as log exposure, which I think hasn't changed yet). and replace self.endog by endog in all subsequent expressions.
However, I'm not able to figure out right now what the interpretation is. Even without sun, beach, drinks and three kids it will take me some time to remember the different aggregation arguments :)
Essentially, I don't remember how dispersion should scale with exposure given that mu also increases, but I think correcting for exposure in estimate_tweedie_power is most likely correct.
BTW: we should still add a method="gamma-glm" to estimate_tweedie_power, but I got busy with other things before I managed to produce any code for double exponential family.
(correction: I had to stop getting distracted by double exponential family, because I had to go back to scheduled things.)
For gamma-glm, I did that in a branch that I'm working on. I'll make these changes and send to you.
I think if we do this, we ought weight the calculations based on exposure. The way I interpret it is that each row in my design matrix is equivalent to a "site" and and the replicates (n_i in the paper) are the amount of exposure. We should weight using number of exposures too. I think that makes sense to me.
I'll play with the this some more.
Enjoy the drinks. I really should buy you one (or 100)...
On Jun 26, 2016, at 3:30 PM, Josef Perktold [email protected] wrote:
in estimate_tweedie_power, we could try to replace endog and mu by the exposure corrected values
endog = self.endog / exposure
mu = mu / exposure
where exposure is the correct exponentiated exposure (internally still stored as log exposure, which I think hasn't changed yet). and replace self.endog by endog in all subsequent expressions.
However, I'm not able to figure out right now what the interpretation is. Even without sun, beach, drinks and three kids it will take me some time to remember the different aggregation arguments :)
Essentially, I don't remember how dispersion should scale with exposure given that mu also increases, but I think correcting for exposure in estimate_tweedie_power is most likely correct.
BTW: we should still add a method="gamma-glm" to estimate_tweedie_power, but I got busy with other things before I managed to produce any code for double exponential family.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
From Taylor's Power Law for Dependence of Variance on Mean in Animal Populations, Perry (1981) available on jstore.
Note that j indexes the sites, and i indexes the time (which I presume is basically the same thing as replicates.)
From Bias-corrected Pearson estimating functions for Taylor’s power law applied to benthic microfauna data (Jorgensen, 2011), available at link above...
So notice that in the Perry paper, the sigma summation for the variance sums up all the sites (indexed by j) at time i.
In the Jorgensen paper, the sigma summation for the variance sums up all the replicates (indexed by j) at site i.
I'm not sure if this is an error, or just means that you can do the calculation either way.
I wonder if I could use Taylor's power formula and back into 'b' but substituting Var(Yij) for S_i^2 and some kind of average on endog. Alternatively, my insurance data is annual. I could group the data by year (or year and month if I want more samples), calculate S_i^2 and mu_i within each each year, and then use the regression formula outlined to estimate scale/shape...
Let me sleep on this... I might be understanding how this works better...
After contemplating this over again, I've come to a different conclusion. (No surprise..)
I re-read some articles by Glenn Meyers and poked around and found out that a lot of the old-school Tweedie folks in actuarial circles simply assume that the distribution is Poisson/Gamma, with no zero-inflation, and then using some simple algebra, realize that you only need to calculate the coefficient of variation of the losses to back into an estimate of alpha parameter for the gamma distribution, then you back into an estimate of p. I get an answer of 1.6 for Tweedie when I do do that on my real dataset. (Approx 3.5 million records representing about 450,000 exposures.)
In [115]: z=np.array(data['PDIncurredLoss'])
In [116]: n=np.array(data['PDClaimCount'])
In [117]: y=np.where(n>0, z/n, 0)
In [122]: mu_y= (y*n).sum() /n.sum()
In [123]: mu_yOut[123]: 2683.7337468276892In [124]: var_y= ((y**2*n).sum() /n.sum()) - (mu_y**2)
In [125]: var_yOut[125]: 10792740.967788128In [126]: cv2=var_y/ (mu_y**2)
In [127]: cv2Out[127]: 1.4984867228406344In [128]: alpha=1/cv2In [129]: (alpha+2) / (alpha+1)
Out[129]: 1.5997577290052363
I'm thinking my acceptance of the ~1.15 p value earlier was grossly mistaken.
The implementation of 'brentq' I committed yesterday is now feeling a little better. That is calculating a 1.645, which makes sense. Intuitively from Meyer's formulas, you expect a number around 1.5 if you the gamma distribution coefficient of variation is around 1. If its a little greater (which it is based on my math above), you want something above 1.5. A little interesting thing about what I implemented is that I use the unadjusted values to calculate the Pearson scale parameter, then the adjusted endog and mu in the part where the scipy optimizer runs. I also multiply that part by weight, (which I've tenatively defined as the product of freq_weights and exposure.
I'm leaning towards thinking that the implementations of the 'gamma-glm' and 'ols', need work though. I'm hoping to make a few more datasets to provide some clarity to myself on this.
Side note, many of papers I've read use (what I think) is var_weight instead of exposure, and thus endog is claim payments per unit of exposure, while I'm just modelling claim payments. Intuitively, I've come to like exposure as a better concept (I don't like the assumption that variance scales linearly with time, if I understand correctly).
I have some other projects to work on, so I might pause this for a minute to think this through.
Did some more book learning and a few tests using real data.
My bentq method I still don't have an intuitive feel for how it really works. It worked on the largest dataset that I had, but failed miserably on the second largest. The second largest is a less homogenous coverage where the claims can be really small, or really big.. a few hundred dollars to $100k or more. These claims are typically rare, however. These claims are likely to end up in litigation, so they are expensive. Wondering if a small, homogenous claim work work, but a rare, volatile form of claims wouldnt't work.
I found a paper with another method for estimating p and scale. The scale essentially is the deviance scale and the p is derived from it, as far as I can tell. There's a formula that you have to maximize. I presume the spicy optimizers could be helpful.
@thequackdaddy Besides fixing exposure or whatever might not be correct:
I think in your case you need more diagnostics, goodness-of-fit measures and comparison with alternative models to see whether Tweedie is an appropriate distributional assumption for your data.
E.g. It could be that the gamma has not thick enough tails to model your very large values without distorting the distribution like outliers.
If you know the number of claims,, you can also still estimate the poisson and gamma parameters separately and see whether they agree approximately with the implied Tweedie paramaters.
Activity
josef-pkt commentedon Apr 27, 2016
Do you mean the rate (case per period) with
frequency? (frequency makes me think of time series)I haven't done the math yet, so I'm thinking mainly of Poisson and WLS for the following.
The scale parameter phi is relative to something. In general rescaling the process changes the
scale.In terms of exposure (e.g. total time for a Poisson process)
In the first case exposure is 1 (year). In the second case exposure is half a year, so units will be per half year, i.e. the arrival rate = 2 per half year for the first observation.
(... explanation doesn't work because Poisson process doesn't have exess dispersion, so I'm thinking more about mean than dispersion.)
When we predict the mean then we want to standardize the exposure to say for example what's the arrival/claim rate per year. (Like quoting annualized interest rate, even if it's calculated monthly.)
There should be a similar "annualization" for the dispersion or variance but I haven't figured out completely how aggregation works if there is excess dispersion. (QMLE instead of MLE)
For variance (not dispersion) we have that the variance of the sum is n times the variance of each splitted fragment. (back of the envelope calculation)
but in Tweedie or GLM we have the separation between variance function (as function of mean) and the dispersion phi.
another problem: only Poisson distribution is the count distribution that is time homogeneous, other count distributions don't split up into subperiods in the simple additive way.
however, Tweedie as compound Poisson is a time homogeneous process. so we need to link the dispersion coefficient of the tweedie distribution to the sum of claim sizes per standardized unit of time.
based on another quick derivation by hand: the dispersion per subperiod would have to be divided by n**(p-1) to arrive at the dispersion per period, if there are n subperiods per period.
something like this, I haven't seen it in any reference. (thinking while writing, no guarantees)
We need to check at least the distribution of the sum for some special cases like Gamma.
thequackdaddy commentedon Apr 27, 2016
@josef-pkt As usual, you've hit the nail on the head with your interpretation of what I'm writing. By frequency, I mean the number of claims reported per year of policy in-force. (Actuarial texts generally define frequency as claims per unit of exposure... so much different usage for "frequency" and "exposure" than a statistician--or economist--would like. "Exposure" is a unit to measure the financial losses that arise in some insured "thing". "Exposure" can be a percent of annual payroll for workman's compensation, a car-year for automobile insurance, a house-year for home insurance, or annual-miles driven for a pay-by-the-mile auto insurance policy.)
If you stumble across any papers on annualization of phi/scale parameter (a quick google search wasn't fruitful), let me know. Maybe "annualization" isn't the right word...
josef-pkt commentedon Apr 27, 2016
I didn't find anything yet to verify the dispersion calculation. However, the properties of the variance when aggregating are standard. for example the variance of a compound poisson process is proportional to the time length. So the sub periods should have 1/n times the variance of the full period sum.
What this implies for the dispersion coefficient depends on the shape of the variance function, since the mean also increases also linearly in aggregating subperiods
josef-pkt commentedon Apr 27, 2016
phi = lambda**(1-p) / (2 - p)
where p = (alpha + 2) / (alpha + 1) alpha is one of the Gamma parameters
Smyth and Jorgensen p. 146 ASTIn Bulletin Vol 32(1) 2002
lambda is the Poisson rate, for given exposure time t, the rate will be lambda * t, so dispersion parameter depends on exposure time through t**(1 - p) (same as what I had above)
josef-pkt commentedon Apr 27, 2016
I'm just reading the Smyth and Jorgensen 2002 article and they use double exponential to allow dispersion to vary depending on explanatory variables, e.g. if the variance of the gamma claim size distribution varies with subgroups of the population or type of insurance policy separately from the poisson claim frequency.
josef-pkt commentedon Apr 28, 2016
This reminds me now that we haven't checked the usage of exposure in Tweedie.
I finished reading Smyth and Jorgensen 2002 yesterday. It's a good paper that makes a clear distinction between claim cost only data, and the joint model for claim count and claim cost.
They use
weverywhere to normalize for exposure, but I'm not sure whatwreally is and how this fit's in the code, i.e. exposure or var_weights. For the parameter estimates itself all weights and multiplicative exposure are the same (with appropriate scaling of endog).partially related:
issues for weights and
issues for aggregation #2831 #2840
thequackdaddy commentedon Apr 28, 2016
Josef,
w_iis the "units at risk". (First paragraph of section 2 of the paper.) I interpret that to be "exposure" more thanvar_weights. (I've been thinking of them asfreq_weights). In other words, if I have a policy in force for 6 months, and it has 2 claims, the rate of claims per year (paper calls it frequency) is 4 (= 2 / 0.5).I'm thinking a full Tweedie approach would look (something) like this...
Tweediemodel with initial estimate ofp(say1.5). (endog is dollars of loss / years at risk)pusing step 1 and theestimate_tweedie_powerfunction.pfrom 2.cov_params. For lambda, use mean frequency of the entire dataset.cov_paramswill then reflect standard errors/z-scores that represent annual variation.So in other words, I'll have one phi that's used in the esimation of
pand a separate phi that used only for calcualtingcov_params.The only thing that (somewhat) concerns me here is that the paper makes it seem phi shoudl really be a vector... and different for each observation. Considering that some of my observations are 1 months of risk and others are 6 months of risk. I'm not convinced if having a vector of phi (as opposed to 2 scalars for these purposes) is of any value.
josef-pkt commentedon Apr 28, 2016
(just briefly, comment about
w_iwill follow later)step 5 doesn't work, steps 1-4 are good
lambda also depends on the explanatory variables and varies by observation, AFAIU.
The calculation go the other way, lambda for the compound Poisson is implied by our estimated parameters for mean and variance.
Now something is strange: because if lambda varies, then phi = lambda**(1-p) / (2 - p) would also vary.
(We really need the functions to move between Tweedie and compound Poisson parameterization so it's easier to understand.)
in terms of expectation (mean)
mean(endog) = E(tweedie) = E(Poisson) * E(Gamma)
cov_paramsshould be independent of any equivalent rescaling of the data.But we can calculate functions of the estimated parameters that renormalize the parameters and calculate the standard errors for those.
e.g. for the "multiplicities" we want the exponential form of the parameters exp(params) with associated standard errors and confidence interval.
thequackdaddy commentedon Apr 28, 2016
I've thought about that in the past as well. What I was thinking is that you could have a vector of phi instead of a scalar. I see that all the math would still work, with the exception of
cov_paramswhich is justcov_params = scale * normalized_cov_params.normalized_cov_paramsis a calculation for the WLS module =(Full disclosure, my only real interest in this whole issue is that
cov_paramsis awfully high, when I'm confident it shouldn't be. I can a Poisson model on count data and havecov_paramsbe quite reasonable. But with Tweedie,cov_paramsbecome really high. I presumed issue was that Pearson seems influenced when you split records. (I think this is an estimate of the hessian?)Granted, there's a lot of moving parts that go into
cov_params... I could be looking in the wrong place. Its just thatscaleseems the most flexible concept we have, and the one I haven't gotten my mind wrapped fully around. (Especially scale when you have records with differentfreq_weightsin the data...)So I'm still thinking about this...
thequackdaddy commentedon Apr 28, 2016
P.S... when I got involved with you, I really thought I'd be able to make a handful of fixes and be finished. It does seem that with stats, the deeper I go, the more I realize I don't know... Hopefully there's a bottom to the ocean.
josef-pkt commentedon Apr 28, 2016
There is no bottom to the ocean. But we might be at a level that is appropriate for what we want or need to do.
You could try
cov_type='HC0'in fit, and see whether it's close to what you expect. It doesn't use the builtinscale.I'm not quite sure about the interaction of exposure and frequency weights.
Do your frequency weights vary a lot?
You could check if you get cov_params closer to what you expect when you don't use freq_weights.
josef-pkt commentedon Apr 28, 2016
Just a sanity check: integer division
Are you using python 2 or python 3?
Did you check that your total freq_weights is equal to total nobs/exposure when you split the data?
josef-pkt commentedon Apr 28, 2016
Also, if you can come up with a simple example that illustrates the effect, then it would be easier for me to look at it.
12 remaining items
josef-pkt commentedon Apr 29, 2016
I'm partway through coding the transformation function and a random sampler for compound poisson and tweedie. I hope it helps to look more closely at what's going on.
My intuition is also that there should be some additivity like this, maybe not strict, but we should at least roughly get the same standard errors. What is even stranger is that the standard errors bse are larger in the split data than in the aggregated sample. If we have more detailed information, like per half year instead of per year observations, then the precision of our estimates should increase (unless the model is misspecified and we pick up more information that conflicts with the model, I think)
I think the way you split up the data and used frequency weights is not the right way to do this for inference. If I use exposure instead of frequency weights, or if I leave off the frequency weights, then the bse is only a little bit larger in the split model than in the original model.
On the other hand, additivity might not be possible without including the count, number of claims in an observation. (maybe unless there is only a very small probability to have more than one claim per period, so it's essentially just zero or one claim).
When there is a large payment in one period, then tweedie has to allocate the total payment between number of claims and size of a single claim. It could be that tweedie is a good, approximately correct model for some aggregation level but a bad model for others.
For example (I didn't try to read anything and don't know any details, but it's mentioned in Jorgensen articles). roughly: some distributions converge to a Tweedie distribution similar to convergence to the normal distribution by the law of large numbers. So Tweedie could be good approximation for aggregated samples but could be a inappropriate, misspecified model for disaggregated data. (*)
edit wikipedia has a brief section on it (whatever this exactly means)
(*) https://en.wikipedia.org/wiki/Tweedie_distribution#The_Tweedie_convergence_theorem
When we work with actual data, it can be difficult to guess what are the effects of a model (given that we don't know all the statistical theory) and what are the effects of using a misspecified model.
josef-pkt commentedon Apr 29, 2016
estimating a simulated tweedie with nobs = 10000
just a simple two group example
true values p = 1.5, scale (phi) = 2.0
mean in two groups 5 and 10
looks good
josef-pkt commentedon Apr 29, 2016
to continue on this: a Monte Carlo with 1000 replication, nobs=10000
looks very good in large sample and true model is Tweedie compound Poisson, no bias here
update
standard errors also look very good
MC mean of asymptotic bse: [0.01337918, 0.01748119]
MC standard deviation of estimated parameters [ 0.01352804, 0.01704884]
josef-pkt commentedon Apr 30, 2016
I updated the gist https://gist.github.com/josef-pkt/b8354b64959ebaf8a7b51c49cecdb54c
Add the end I did a similar experiment by summing each consecutive two observations (which have the same exog). This means that initially I have half year data that I combine into one year data. (exposure is per half year) (or we could take initially one year and then we combine two years)
Using exposure, I get exactly (at a few decimals) the same numbers in both cases.
With frequency weights the bse differ a bit (assuming each combined observation has frequency 2 with half the endog in the last case in notebook).
Without frequency weights (freq_weights=1), the bse is the same with the 2period aggregate as in the separate period case, but the estimated means double, because we have no normalized to 2 period exposure.
So my guess is that frequency weights don't do the appropriate thing for this case. The correct interpretation requires
exposure, and endog as the total claims for the exposure time.Another guess is that we might need var_weights if the endog is a mean over some observations.
This is with simulated tweedie in a large sample, so it rules out misspecification of the underlying model.
thequackdaddy commentedon May 1, 2016
Oh my. Thank you.
There's a very simplistic analogy to this behavior here.
For Tweedie, my endogenous really needs to be the loss and an offset for exposure is the used.
This is a super helpful notebook.
thequackdaddy commentedon May 1, 2016
(That $150k software really doesn't explain things as well as you do.)
thequackdaddy commentedon Jun 26, 2016
@josef-pkt I have another problem I want to talk through. So bear with me.
I agree--in general--that
exposureis the correct thing to use here. I thinkvar_weightsis incorrect because I'm not so certain that dispersion--(endog - mu) ** 2--scales linearly with time. In fact, I would think this is not the case. (Let me know if my understanding of dispersion is flawed.)Let's go back to this paper.
Recall that
S_i ** 2is:(Note to self, the paper is from a bio-statistics perspective. We essentially have "observations"--which the paper calls sites--and each observation has 1 replicate. I presume that just dropping the
1 / (n_i - 1)piece is harmless.)The author presents this formula...
And using a log\gamma GLM, we should be able to solve for
aandb.However, when doing this on my 3.5 million record dataset, it didn't work. I read this section...
Should I be weighting this somehow, perhaps? Maybe based on
Exposure? I played with some different ideas and think this is probably as close to something reasonable as I could find...Which gives...
np.exp(10.4552) == 34724.473308301465vs the pearson x2 estimate of 6147.95962013. (So not good.)However,
p == 1.1295is believable to me...On a side note, I now think that that our shortcut doesn't work well when you have different exposures. I'm fairly certain that we might need to adjust this to account for exposures better. I just don't know where/how to do it... I appreciate any ideas. Recall that we plug 3.8 into 3.9, and then use the
brentqoptimizer to set this equal to 0.Thanks.
josef-pkt commentedon Jun 26, 2016
I'll try to look at it tonight (Central European Time), I don't remember the details now.
Yes, I think the pearson estimate needs to take account of exposure as in (3.9) in your comment. This needs to be fixed (for 0.8) if it doesn't do it correctly.
josef-pkt commentedon Jun 26, 2016
in estimate_tweedie_power, we could try to replace endog and mu by the exposure corrected values
where exposure is the correct exponentiated exposure (internally still stored as log exposure, which I think hasn't changed yet). and replace self.endog by endog in all subsequent expressions.
However, I'm not able to figure out right now what the interpretation is. Even without sun, beach, drinks and three kids it will take me some time to remember the different aggregation arguments :)
Essentially, I don't remember how dispersion should scale with exposure given that mu also increases, but I think correcting for exposure in estimate_tweedie_power is most likely correct.
BTW: we should still add a
method="gamma-glm"to estimate_tweedie_power, but I got busy with other things before I managed to produce any code for double exponential family.(correction: I had to stop getting distracted by double exponential family, because I had to go back to scheduled things.)
thequackdaddy commentedon Jun 26, 2016
For gamma-glm, I did that in a branch that I'm working on. I'll make these changes and send to you.
I think if we do this, we ought weight the calculations based on exposure. The way I interpret it is that each row in my design matrix is equivalent to a "site" and and the replicates (n_i in the paper) are the amount of exposure. We should weight using number of exposures too. I think that makes sense to me.
I'll play with the this some more.
Enjoy the drinks. I really should buy you one (or 100)...
thequackdaddy commentedon Jun 27, 2016
Ok, I've managed to confuse myself.
From Taylor's Power Law for Dependence of Variance on Mean in Animal Populations, Perry (1981) available on jstore.
Note that j indexes the sites, and i indexes the time (which I presume is basically the same thing as replicates.)
From Bias-corrected Pearson estimating functions for Taylor’s power law applied to benthic microfauna data (Jorgensen, 2011), available at link above...
So notice that in the Perry paper, the sigma summation for the variance sums up all the sites (indexed by j) at time i.
In the Jorgensen paper, the sigma summation for the variance sums up all the replicates (indexed by j) at site i.
I'm not sure if this is an error, or just means that you can do the calculation either way.
I wonder if I could use Taylor's power formula and back into 'b' but substituting Var(Yij) for S_i^2 and some kind of average on endog. Alternatively, my insurance data is annual. I could group the data by year (or year and month if I want more samples), calculate S_i^2 and mu_i within each each year, and then use the regression formula outlined to estimate scale/shape...
Let me sleep on this... I might be understanding how this works better...
It could also be the porter I just drank talking.
thequackdaddy commentedon Jun 27, 2016
After contemplating this over again, I've come to a different conclusion. (No surprise..)
I re-read some articles by Glenn Meyers and poked around and found out that a lot of the old-school Tweedie folks in actuarial circles simply assume that the distribution is Poisson/Gamma, with no zero-inflation, and then using some simple algebra, realize that you only need to calculate the coefficient of variation of the losses to back into an estimate of alpha parameter for the gamma distribution, then you back into an estimate of p. I get an answer of 1.6 for Tweedie when I do do that on my real dataset. (Approx 3.5 million records representing about 450,000 exposures.)
From this newsletter by Glenn Meyers
I'm thinking my acceptance of the ~1.15 p value earlier was grossly mistaken.
The implementation of
'brentq'I committed yesterday is now feeling a little better. That is calculating a1.645, which makes sense. Intuitively from Meyer's formulas, you expect a number around 1.5 if you the gamma distribution coefficient of variation is around 1. If its a little greater (which it is based on my math above), you want something above 1.5. A little interesting thing about what I implemented is that I use the unadjusted values to calculate the Pearson scale parameter, then the adjustedendogandmuin the part where the scipy optimizer runs. I also multiply that part by weight, (which I've tenatively defined as the product offreq_weightsandexposure.I'm leaning towards thinking that the implementations of the
'gamma-glm'and'ols', need work though. I'm hoping to make a few more datasets to provide some clarity to myself on this.Side note, many of papers I've read use (what I think) is
var_weightinstead ofexposure, and thus endog is claim payments per unit of exposure, while I'm just modelling claim payments. Intuitively, I've come to likeexposureas a better concept (I don't like the assumption that variance scales linearly with time, if I understand correctly).I have some other projects to work on, so I might pause this for a minute to think this through.
thequackdaddy commentedon Jul 2, 2016
Note to self:
Did some more book learning and a few tests using real data.
pandscale. Thescaleessentially is the deviance scale and thepis derived from it, as far as I can tell. There's a formula that you have to maximize. I presume the spicy optimizers could be helpful.Wuthrich
josef-pkt commentedon Jul 2, 2016
@thequackdaddy Besides fixing exposure or whatever might not be correct:
I think in your case you need more diagnostics, goodness-of-fit measures and comparison with alternative models to see whether Tweedie is an appropriate distributional assumption for your data.
E.g. It could be that the gamma has not thick enough tails to model your very large values without distorting the distribution like outliers.
If you know the number of claims,, you can also still estimate the poisson and gamma parameters separately and see whether they agree approximately with the implied Tweedie paramaters.
thequackdaddy commentedon Jul 2, 2016
I'm rather comfortable with Tweedie.
Here's a gist of the data. There are 2 claim types, bodily injury (called BI) and property damage (called PD).
Bodily injury is much more likely to have litigation and large claims, you can see that the claim buckets are quite wide.
Property damage claims are a little tighter.
I'll work on goodness of fit tests later this weekend, in all likelihood.