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
links probit, CDFLink precision loss in Hessian #1878
CDFLink uses numerical derivative for deriv2
(complaining again links are back to front)
deriv2 is computed in a very roundabout way, inverse_deriv2 would have an explicit form
using inverse function math res_tmp.model.family.link.deriv2(mu) - (linpred * stats.norm.pdf(linpred)) / stats.norm.pdf(linpred)**3
differs by 8.9e-5
in an example where I add noise to endog to check whether it works for interval [0, 1] data, the hessian looks pretty unstable as I increase the noise, bse changes quite a bit.
HC0 for fractional regression with GLM-probit differs from Stata, some of this might be a noisy hessian computation
also inverse_deriv is computed through the link deriv function and not directly from pdf res_tmp.model.family.link.inverse_deriv(linpred) - stats.norm.pdf(linpred)
agrees at 2e-16
SPSS algorithm manual has cauchit only as cumulative link, and there they specify first and second inverse derivatives.
They use gamma instead of mu for expected in cumulative link, gamma = link_inverse(linpred)
base class Link already defines inverse_deriv2 which uses the second derivative of an inverse function formula and deriv2
if I go generically in cdf link in the other direction, then I will get a circular infinite recursion.
I could override this by adding NotImplementedError to CDFLink.inverse_deriv2
assuming that we have cdf, pdf in easier form than ppf and inverse derivative function. i.e. we have derivative/score of log pdf already in models.
another disabled probit test
test_deriv2 in statsmodels.genmod.families.tests.test_link skips probit
If I enable it, then tests pass if I increase rtol from 1e-6 to 5e-6, diff in my test run is rtol 1.164e-06
(I ran into these by chance and didn't read anything.
"generalised extreme value regression models" in some titles is misleading because it is Binomial/Bernoulli with GEV link and not a GEV distributed (continuous) endog.)
related: add more asymmetric link functions for Binomial/Bernoulli (besides loglog and cloglog)
Wang, Xin, Vivekananda Roy, and Zhengyuan Zhu. "A new algorithm to estimate monotone nonparametric link functions and a comparison with parametric approach." Statistics and Computing 28, no. 5 (2018): 1083-1094.
many of the references for asymmetric CDFLinks use Bayesian method.
The above uses MLE, GEV link as a case. The articles also compares with symmetric and nonparametric links.
also we could cross-test cdf links for distributions that are equivalent to traditional "named" links, e.g.
loglog sounds like extreme value distribution.
logit versus logistic cdflink
For asymmetric distributions we could add generic sf link based on survival function (1 - F(x))`.
like loglog versus cloglog?
We should still be able to maintain increasing monotonicity.
Activity
josef-pkt commentedon Aug 10, 2014
example is still burried in a script
josef-pkt commentedon Dec 17, 2020
CDFLink uses numerical derivative for
deriv2(complaining again links are back to front)
deriv2is computed in a very roundabout way,inverse_deriv2would have an explicit formusing inverse function math
res_tmp.model.family.link.deriv2(mu) - (linpred * stats.norm.pdf(linpred)) / stats.norm.pdf(linpred)**3differs by 8.9e-5
in an example where I add noise to endog to check whether it works for interval [0, 1] data, the hessian looks pretty unstable as I increase the noise, bse changes quite a bit.
HC0 for fractional regression with GLM-probit differs from Stata, some of this might be a noisy hessian computation
background
g" = - f" / f'**3 where g is inverse function of f
SPSS algorithm manual has explicit formula for second derivatives of link function
res_tmp.model.family.link.deriv(mu)**2 * stats.norm.ppf(mu)which agrees closely with the inverse function formula
also
inverse_derivis computed through the link deriv function and not directly from pdfres_tmp.model.family.link.inverse_deriv(linpred) - stats.norm.pdf(linpred)agrees at 2e-16
josef-pkt commentedon Dec 17, 2020
cauchy link has an explicit
deriv2SPSS algorithm manual has cauchit only as cumulative link, and there they specify first and second inverse derivatives.
They use gamma instead of mu for expected in cumulative link, gamma = link_inverse(linpred)
josef-pkt commentedon Dec 17, 2020
after adding the inverse definition for deriv2, I get agreement with Stata in fracreg case with bse-HC0
great, it was only a precision problem
josef-pkt commentedon Dec 17, 2020
base class Link already defines
inverse_deriv2which uses the second derivative of an inverse function formula andderiv2if I go generically in cdf link in the other direction, then I will get a circular infinite recursion.
I could override this by adding NotImplementedError to
CDFLink.inverse_deriv2assuming that we have cdf, pdf in easier form than ppf and inverse derivative function. i.e. we have derivative/score of log pdf already in models.
josef-pkt commentedon Dec 17, 2020
Based on a quick search it looks like R doesn't define second derivatives in link functions
a bit more Wolfram
derivative of
t.pdf(x, df), i.e. inverse_deriv2-((Sqrt[df]*(1 + df)*x*(df/(df + x^2))^(-1 + (1 + df)/2))/ ((df + x^2)^2*Beta[df/2, 1/2]))-(((1 + df)*x*(df/(df + x^2))^((3 + df)/2))/(df^(3/2)*Beta[df/2, 1/2]))using n for df
-((Sqrt[n] (1 + n) x (n/(n + x^2))^(-1 + (1 + n)/2))/((n + x^2)^2 Beta[n/2, 1/2]))https://www.wolframalpha.com/input/?i=d%2Fdx+PDF%5BStudentTDistribution%5B0%2C1%2Cn%5D%2C+x%5D
We should be able to get the TLink also, or
StudentT? to have a more than one letter distribution namejosef-pkt commentedon Dec 21, 2020
another disabled probit test
test_deriv2 in statsmodels.genmod.families.tests.test_link skips probit
If I enable it, then tests pass if I increase rtol from 1e-6 to 5e-6, diff in my test run is rtol 1.164e-06
josef-pkt commentedon Jun 2, 2021
more distributions for cdf link
I found several references that use generalized extreme value distribution for rare events binomial/bernoulli
Medford, Anthony, and James W. Vaupel. 2019. “An Introduction to Gevistic Regression Mortality Models.” Scandinavian Actuarial Journal 2019 (7): 604–20. https://doi.org/10.1080/03461238.2019.1586756.
especially also referenced articles by Calabrese
(I ran into these by chance and didn't read anything.
"generalised extreme value regression models" in some titles is misleading because it is Binomial/Bernoulli with GEV link and not a GEV distributed (continuous) endog.)
josef-pkt commentedon Jun 2, 2021
related: add more asymmetric link functions for Binomial/Bernoulli (besides loglog and cloglog)
Wang, Xin, Vivekananda Roy, and Zhengyuan Zhu. "A new algorithm to estimate monotone nonparametric link functions and a comparison with parametric approach." Statistics and Computing 28, no. 5 (2018): 1083-1094.
many of the references for asymmetric CDFLinks use Bayesian method.
The above uses MLE, GEV link as a case. The articles also compares with symmetric and nonparametric links.
josef-pkt commentedon Jul 22, 2021
student t link #7287 (comment)
josef-pkt commentedon Jul 22, 2021
generalized logistic, log-F is a cdflink
#5409 (comment)
also we could cross-test cdf links for distributions that are equivalent to traditional "named" links, e.g.
loglog sounds like extreme value distribution.
logit versus logistic cdflink
For asymmetric distributions we could add generic
sflink based on survival function (1 - F(x))`.like loglog versus cloglog?
We should still be able to maintain increasing monotonicity.