Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to define link function in glmfit?

11 views
Skip to first unread message

grace

unread,
Feb 14, 2012, 4:55:39 AM2/14/12
to
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.

Peter Perkins

unread,
Feb 14, 2012, 9:53:29 AM2/14/12
to
Grace, this is the expression you have passed into glmfit:

{ @(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))) }


Since you haven't provided the errors you get, we can only guess as to
what's happening. But there are a number of problems with this.

* You've used the character "1" (the number one) when you want "l" (the
letter ell)
* You've used matrix operators such as *, ^, and / when you want
elementwise operators such as .*, .^, and ./
* Your link function is parameterized by a and b, which you have not
defined.

You probably also want to make use of the log1p function and replace all
those log(1-y)'s with log1p(-y).

Hope this helps.

Tom Lane

unread,
Feb 14, 2012, 10:39:17 AM2/14/12
to
In addition, this link function is usually used with 'binomial' instead of
'normal' -- did you really mean to use normal?

Also (assuming you did intend binomial), please verify this matches what you
want, but I think it would be equivalent and simpler to use

glmfit(log10(x),y,'binomial','link','comploglog')

That is, use the complementary log-log link on the log10 of your data,
instead of building the log10 transform into your function.

-- Tom

"Peter Perkins" <Peter.Remove...@mathworks.com> wrote in message
news:jhdsh9$8ve$1...@newscl01ah.mathworks.com...
0 new messages