how to define link function in glmfit
4 views (last 30 days)
Show older comments
Dear all,
I am employing glmfit to solve Generalized Linear Models, and the link function I choose is Weibull, which is also known as Gompertz,
y=1-exp(-exp(a+b*log10(x))) ;
The guiding information I find in help reads "cell array of the form {FL FD FI}, containing three function handles, created using @, that define the link (FL), the derivative of the link (FD), and the inverse link (FI)." And I try to write some code:
[b,dev,stats]=glmfit(X,Y,'normal','link',{@(y)(10^((log(-1og(1-y))-a)/b)),@(y)(10.^((log(-1og(1-y))-a)/b)/(b*(-1og(1-y)*(1-y)))),@(y)(1-exp(-exp(a+b*log10(y))))})
There are always errors. I am not familiar with function handles. And I want to know if y should be a matrix, how to define the link function in the right way?
Thanks a lot.
0 Comments
Answers (1)
Tom Lane
on 14 Feb 2012
Did you really mean to specify the normal distribution? This type of link is more commonly used with the binomial distribution. In fact, it is the complementary log-log link using log data:
>> x = 10*rand(1000,1);
>> a = 1; b = -2;
>> p = 1-exp(-exp(a+b*log10(x)));
>> y = binornd(1,p);
>> glmfit(log10(x),y,'binomial','link','comploglog')
ans =
0.8951
-1.8827
This is possible with the normal distribution also, but there is a risk of problems as the fitted values approach 0 and 1. Here's an illustration on a well-conditioned problem:
>> x = 2+2*rand(1000,1);
>> p = 1-exp(-exp(a+b*log10(x)));
>> y = normrnd(p,.01);
>> glmfit(log10(x),y,'normal','link','comploglog')
ans =
0.9999
-1.9990
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!