Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to define link function in glmfit?

Subject: How to define link function in glmfit?

From: grace

Date: 14 Feb, 2012 09:55:39

Message: 1 of 3

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.

Subject: How to define link function in glmfit?

From: Peter Perkins

Date: 14 Feb, 2012 14:53:29

Message: 2 of 3

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.


On 2/14/2012 4:55 AM, grace wrote:
> 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.

Subject: How to define link function in glmfit?

From: Tom Lane

Date: 14 Feb, 2012 15:39:17

Message: 3 of 3

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.Perkins.This@mathworks.com> wrote in message
news:jhdsh9$8ve$1@newscl01ah.mathworks.com...
> 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.
>
>
> On 2/14/2012 4:55 AM, grace wrote:
>> 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.
>

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us