<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238384</link>
    <title>MATLAB Central Newsreader - glm with probit model</title>
    <description>Feed for thread: glm with probit model</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Wed, 29 Oct 2008 22:50:18 -0400</pubDate>
      <title>glm with probit model</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238384#607980</link>
      <author>Daniel </author>
      <description>I have successfully implemented a glmfit with binary response and a probit model.  My model has the form of p(t)=probit(-x^2).  This seems to work fairly well until a lapse occurs and subjects miss a level that they &quot;should&quot; have detected.  For example, maybe they fall asleep for a few moments.  I understand that this can be modeled by including a lapse rate lambda (usually assume to be less than 0.05 or so) yielding a model of the form:&lt;br&gt;
&lt;br&gt;
lambda + (1 - lambda)*probit (-x^2)&lt;br&gt;
&lt;br&gt;
I haven't been able to figure out how to fit this with glmfit.  Am I missing something?  Ideas?</description>
    </item>
    <item>
      <pubDate>Thu, 30 Oct 2008 15:12:06 -0400</pubDate>
      <title>Re: glm with probit model</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238384#608096</link>
      <author>Peter Perkins</author>
      <description>Daniel wrote:&lt;br&gt;
&amp;gt; I have successfully implemented a glmfit with binary response and a probit model.  My model has the form of p(t)=probit(-x^2).  This seems to work fairly well until a lapse occurs and subjects miss a level that they &quot;should&quot; have detected.  For example, maybe they fall asleep for a few moments.  I understand that this can be modeled by including a lapse rate lambda (usually assume to be less than 0.05 or so) yielding a model of the form:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; lambda + (1 - lambda)*probit (-x^2)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I haven't been able to figure out how to fit this with glmfit.  Am I missing something?  Ideas?&lt;br&gt;
&lt;br&gt;
Daniel, your description is a little vague to me.  It sounds like you're using the GLMFIT function in the Statistics Toolbox with a probit link and a binomial distribution.  It sounds like what you want is to model the probability of &quot;success&quot; (whatever that means in your case) as&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;p = lambda + (1-lambda)*Phi(eta)&lt;br&gt;
&lt;br&gt;
where Phi is the standard normal CDF, and eta is the linear predictor X*beta.  Is that right?&lt;br&gt;
&lt;br&gt;
You can do this by defining your own link function as described in the help for GLMFIT.  I believe the usual thing described in the literature is to fix lambda, fit the GLM and compute the deviance, and then vary lambda to find the value that minimizes the deviance.&lt;br&gt;
&lt;br&gt;
The one catch in doing this with GLMFIT is that you'll probably find that the standard GLM initialization doesn't work well with that kind of link function -- depending on your data and the value of lambda, it may try to initialize with probabilities that are less than lambda.  That's easy to fix if you can modify GLMFIT in your MATLAB installation.&lt;br&gt;
&lt;br&gt;
If you can't, there was a thread a few weeks ago with the subject &quot;glmfit binomial-probit with natural mortality&quot; that describes a way to call GLMFIT to fit this model.&lt;br&gt;
&lt;br&gt;
Hope this helps.&lt;br&gt;
&lt;br&gt;
- Peter Perkins&lt;br&gt;
&amp;nbsp;&amp;nbsp;The MathWorks, Inc.</description>
    </item>
    <item>
      <pubDate>Sun, 09 Nov 2008 09:58:01 -0500</pubDate>
      <title>Re: glm with probit model</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238384#609807</link>
      <author>Daniel </author>
      <description>Peter, thanks for your reply.  Yes, you seem to have understood my model even though my description was not clear.  I understand that I can create my own functions, and I understand the example that you provided.  However, I am still struggling with how to implement my model, so let me first spell out my model more clearly.  The underlying model is based on a probit link.  To make this even more explicit, here is the call that I use for model fitting:&lt;br&gt;
[b,dev2,stats]=glmfit(motion,correct,'binomial','link','probit');&lt;br&gt;
&lt;br&gt;
In fact, this works very well for much of my data.  However, humans sometimes &quot;miss&quot; on trials when the probability says that they should almost never miss and this can severely bias the desired parameter fits from the model.  (An example of a lapse is that I should hear that tone except that I fell asleep while you played the tone for me.)  This is often handled in the psychophysical literature by adding one additional parameter to the model to represent the fact that subjects might sometimes miss on trials that they should have detected.  (See below for an equation showing how this is implemented.)&lt;br&gt;
&lt;br&gt;
To avoid ambiguity, I'll provide some portions of an m-file that will explicitly outline my model.&lt;br&gt;
&lt;br&gt;
mu=-3;  %This is the location of the peak of the probability distribution function.&lt;br&gt;
sigma=3; %This is the standard deviation.&lt;br&gt;
lambda=0.01; % This is my lapse rate.&lt;br&gt;
&amp;nbsp;&lt;br&gt;
x=-20:.01:20;&lt;br&gt;
&lt;br&gt;
If I understand the m-file you provided, the following represent the three functions that are required. &lt;br&gt;
deta=(1-2*lambda)*normpdf(x,mu,sigma);    %This is the derivative of the link function&lt;br&gt;
eta=norminv((p_lapse-lambda)/(1-2*lambda),mu,sigma);     %This is a form of the link function&lt;br&gt;
mu=lambda + (1-2*lambda)*normcdf(x,mu,sigma);  %This is a form of the inverse link function&lt;br&gt;
&lt;br&gt;
However, when I try to use the m-file that you provided as a template, I start to run into problems.&lt;br&gt;
&lt;br&gt;
I can almost figure out how to implement the derivative function, since I can write this equation in a simple closed form solution:&lt;br&gt;
deta=(1-2*L)*exp(-((mu)).^2)/sqrt(2*pi);  &lt;br&gt;
(But this is missing the normalization by sigma which I can't see how to write in the desired format for the GLM, but I probably am just missing something.)&lt;br&gt;
&lt;br&gt;
However, the inverse link function cannot be written in a closed form solution.  In fact it includes the normal cdf, which is a from of the error function and I just can't see how to write this in a closed form that is appropriate for the glmfit.  Seems like the same is true for the link function.&lt;br&gt;
&lt;br&gt;
Am I missing something?&lt;br&gt;
&lt;br&gt;
Thanks in advance for any advice.  Sincerely,&lt;br&gt;
Dan</description>
    </item>
    <item>
      <pubDate>Mon, 10 Nov 2008 15:33:43 -0500</pubDate>
      <title>Re: glm with probit model</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238384#610055</link>
      <author>Peter Perkins</author>
      <description>Daniel wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt; If I understand the m-file you provided, the following represent the three functions that are required. &lt;br&gt;
&amp;gt; deta=(1-2*lambda)*normpdf(x,mu,sigma);    %This is the derivative of the link function&lt;br&gt;
&amp;gt; eta=norminv((p_lapse-lambda)/(1-2*lambda),mu,sigma);     %This is a form of the link function&lt;br&gt;
&amp;gt; mu=lambda + (1-2*lambda)*normcdf(x,mu,sigma);  %This is a form of the inverse link function&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; However, when I try to use the m-file that you provided as a template, I start to run into problems.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I can almost figure out how to implement the derivative function, since I can write this equation in a simple closed form solution:&lt;br&gt;
&amp;gt; deta=(1-2*L)*exp(-((mu)).^2)/sqrt(2*pi);  &lt;br&gt;
&amp;gt; (But this is missing the normalization by sigma which I can't see how to write in the desired format for the GLM, but I probably am just missing something.)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; However, the inverse link function cannot be written in a closed form solution.  In fact it includes the normal cdf, which is a from of the error function and I just can't see how to write this in a closed form that is appropriate for the glmfit.  Seems like the same is true for the link function.&lt;br&gt;
&lt;br&gt;
I'm not sure where those 2's are coming from.&lt;br&gt;
&lt;br&gt;
These are the probit link, link derivative, and inverse link functions that GLMFIT uses (edit private/stattestlink, called by glmfit):&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;link = @(mu) norminv(mu);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dlink = @(mu) 1 ./ normpdf(norminv(mu));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;% keep mu = ilink(eta) in [eps, (1-eps)];&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;lowerBnd = norminv(eps(dataClass)); upperBnd = -lowerBnd;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ilink = @(eta) normcdf(min(max(eta,lowerBnd),upperBnd));&lt;br&gt;
&lt;br&gt;
Given lambda, I believe you want &lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ilink = @(eta) lambda + ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(1-lambda).*normcdf(min(max(eta,lowerBnd),upperBnd));&lt;br&gt;
&lt;br&gt;
and therefore&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;link = @(mu) norminv((mu-lambda)./(1-lambda));&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;dlink = @(mu) 1 ./ ((1-lambda).*normpdf(norminv((mu-lambda)./(1-lambda))));&lt;br&gt;
&lt;br&gt;
but you'll want to check my work.  If your lambda is really .01, then you may not run into the problem with initial values that I alluded to, unless youhave more than 100 observations.&lt;br&gt;
&lt;br&gt;
Hope this helps.</description>
    </item>
    <item>
      <pubDate>Mon, 10 Nov 2008 16:43:02 -0500</pubDate>
      <title>Re: glm with probit model</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238384#610080</link>
      <author>Daniel </author>
      <description>Thanks very much.  We will try your suggestions and let you know. &lt;br&gt;
&lt;br&gt;
FYI, the 2 comes from the fact that people can lapse on both ends, so we want the cdf to range from lambda on the low end to (1-lambda) on the high end.  For example, if lambda equals 0.01, then the lowest probability for very small values of the independent variable would be 0.01 and the highest probability for very large values of the independent variable would be 0.99.&lt;br&gt;
&lt;br&gt;
Hope that makes sense.  Will let you know if this works.</description>
    </item>
    <item>
      <pubDate>Mon, 10 Nov 2008 22:26:16 -0500</pubDate>
      <title>Re: glm with probit model</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238384#610173</link>
      <author>Peter Perkins</author>
      <description>Daniel wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt; FYI, the 2 comes from the fact that people can lapse on both ends, so we want the cdf to range from lambda on the low end to (1-lambda) on the high end.  For example, if lambda equals 0.01, then the lowest probability for very small values of the independent variable would be 0.01 and the highest probability for very large values of the independent variable would be 0.99.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Hope that makes sense.  Will let you know if this works.&lt;br&gt;
&lt;br&gt;
It does, but my versions of those three functions are not what you want.  But I think the changes needed are obvious.</description>
    </item>
    <item>
      <pubDate>Tue, 11 Nov 2008 13:13:01 -0500</pubDate>
      <title>Re: glm with probit model</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238384#610269</link>
      <author>Daniel </author>
      <description>Hi Peter , thanks for all of your help.  it seems that I am very close but I seem to missing something critical.  Following your suggestion, I defined the following functions:&lt;br&gt;
&lt;br&gt;
myilink = @(eta) L + (1-2*L).*normcdf(min(max(eta,lowerBnd),upperBnd));&lt;br&gt;
mylink = @(mu) norminv((mu-L)./(1-2*L));&lt;br&gt;
mydlink = @(mu) 1 ./ ((1-2*L).*normpdf(norminv((mu-L)./(1-L))));&lt;br&gt;
&lt;br&gt;
If I fit with the standard probit model:&lt;br&gt;
b = glmfit(motion,y,'binomial','link','probit');&lt;br&gt;
everything works fine, so I know that my input vectors and general approach are correct.&lt;br&gt;
&lt;br&gt;
However, when I fit using the following call (as I believe you had suggested):&lt;br&gt;
b = glmfit(motion,y,'binomial','link',{mylink mydlink myilink});&lt;br&gt;
I get the following error message:&lt;br&gt;
&lt;br&gt;
??? Input argument &quot;L&quot; is undefined.&lt;br&gt;
&lt;br&gt;
Error in ==&amp;gt; direction_detect&amp;gt;@(mu,L)norminv((mu-L)./(1-2*L)) at 64&lt;br&gt;
mylink = @(mu,L) norminv((mu-L)./(1-2*L));&lt;br&gt;
&lt;br&gt;
Error in ==&amp;gt; glmfit at 277&lt;br&gt;
eta = linkFun(mu);&lt;br&gt;
&lt;br&gt;
Error in ==&amp;gt; direction_detect at 77&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;b = glmfit(motion,y,'binomial','link',{mylink mydlink myilink});&lt;br&gt;
&lt;br&gt;
First, I should probably let you know that L is defined and is a scalar.  It is defined via the following three lines of m-file code:&lt;br&gt;
lambda=0:.01:.06;&lt;br&gt;
for j=1:length(lambda)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;L = lambda(j);&lt;br&gt;
so I believe that it both exists and is a scalar.&lt;br&gt;
&lt;br&gt;
Now, if were to be calling my function(s) directly myself, I know that I could simply add my variable L in the function definition.  For example:&lt;br&gt;
myilink = @(eta, L) L + (1-2*L).*normcdf(min(max(eta,lowerBnd),upperBnd));&lt;br&gt;
&lt;br&gt;
However, since I do not control the call function within glmfit, I do not see how to pass the L variable to my function(s).&lt;br&gt;
&lt;br&gt;
Suggestions?&lt;br&gt;
&lt;br&gt;
Thanks in advance,&lt;br&gt;
Dan</description>
    </item>
    <item>
      <pubDate>Tue, 11 Nov 2008 16:23:29 -0500</pubDate>
      <title>Re: glm with probit model</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238384#610324</link>
      <author>Tom Lane</author>
      <description>&amp;gt; myilink = @(eta) L + (1-2*L).*normcdf(min(max(eta,lowerBnd),upperBnd));&lt;br&gt;
&amp;gt; mylink = @(mu) norminv((mu-L)./(1-2*L));&lt;br&gt;
&amp;gt; mydlink = @(mu) 1 ./ ((1-2*L).*normpdf(norminv((mu-L)./(1-L))));&lt;br&gt;
...&lt;br&gt;
&amp;gt; I get the following error message:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; ??? Input argument &quot;L&quot; is undefined.&lt;br&gt;
&lt;br&gt;
Dan, you should set L before you define the functions above.  Its value is &lt;br&gt;
then incorporated into the function definitions.&lt;br&gt;
&lt;br&gt;
It sounds like you're setting L in a loop.  Then re-define these functions &lt;br&gt;
each time through the loop, so they pick up the new value of L.  I don't &lt;br&gt;
think there will be a lot of overhead in doing that.&lt;br&gt;
&lt;br&gt;
-- Tom </description>
    </item>
    <item>
      <pubDate>Tue, 11 Nov 2008 16:26:47 -0500</pubDate>
      <title>Re: glm with probit model</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238384#610325</link>
      <author>Peter Perkins</author>
      <description>Daniel wrote:&lt;br&gt;
&amp;gt; Hi Peter , thanks for all of your help.  it seems that I am very close but I seem to missing something critical.  Following your suggestion, I defined the following functions:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; myilink = @(eta) L + (1-2*L).*normcdf(min(max(eta,lowerBnd),upperBnd));&lt;br&gt;
&amp;gt; mylink = @(mu) norminv((mu-L)./(1-2*L));&lt;br&gt;
&amp;gt; mydlink = @(mu) 1 ./ ((1-2*L).*normpdf(norminv((mu-L)./(1-L))));&lt;br&gt;
&lt;br&gt;
I think you want 1-2*L in the denom of the last one.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&amp;gt; However, when I fit using the following call (as I believe you had suggested):&lt;br&gt;
&amp;gt; b = glmfit(motion,y,'binomial','link',{mylink mydlink myilink});&lt;br&gt;
&amp;gt; I get the following error message:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; ??? Input argument &quot;L&quot; is undefined.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Error in ==&amp;gt; direction_detect&amp;gt;@(mu,L)norminv((mu-L)./(1-2*L)) at 64&lt;br&gt;
&amp;gt; mylink = @(mu,L) norminv((mu-L)./(1-2*L));&lt;br&gt;
&lt;br&gt;
Where did that link function come from?  It isn't the one you cited above, and it has L as an argument.  L should not be an input argument.  Let the anonomous function &quot;captures&quot; L by creating a new mylink at each iteration inside this loop:&lt;br&gt;
&lt;br&gt;
&amp;gt; lambda=0:.01:.06;&lt;br&gt;
&amp;gt; for j=1:length(lambda)&lt;br&gt;
&amp;gt;     L = lambda(j);</description>
    </item>
    <item>
      <pubDate>Tue, 11 Nov 2008 17:35:10 -0500</pubDate>
      <title>Re: glm with probit model</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238384#610339</link>
      <author>Daniel </author>
      <description>Peter Perkins &amp;lt;Peter.PerkinsRemoveThis@mathworks.com&amp;gt; wrote in message &amp;lt;gfcbo7$sfi$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; mydlink = @(mu) 1 ./ ((1-2*L).*normpdf(norminv((mu-L)./(1-L))));&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I think you want 1-2*L in the denom of the last one.&lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
&lt;br&gt;
You are correct.  My mistake.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&amp;gt; &amp;gt; mylink = @(mu,L) norminv((mu-L)./(1-2*L));&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Where did that link function come from?  It isn't the one you cited above, and it has L as an argument.  L should not be an input argument.  Let the anonomous function &quot;captures&quot; L by creating a new mylink at each iteration inside this loop:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; lambda=0:.01:.06;&lt;br&gt;
&amp;gt; &amp;gt; for j=1:length(lambda)&lt;br&gt;
&amp;gt; &amp;gt;     L = lambda(j);&lt;br&gt;
&lt;br&gt;
You are correct.  I tried  using the function above after I had tried: &lt;br&gt;
&lt;br&gt;
mylink = @(mu) norminv((mu-L)./(1-2*L));&lt;br&gt;
&lt;br&gt;
Both gave the same error message.&lt;br&gt;
&lt;br&gt;
I think that it is working now.  When I am certain, would you like the &quot;final&quot; code.  I simply modified the example code that you had provided earlier with the updated model and model fit, etc.</description>
    </item>
    <item>
      <pubDate>Tue, 11 Nov 2008 19:28:00 -0500</pubDate>
      <title>Re: glm with probit model</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/238384#610357</link>
      <author>Peter Perkins</author>
      <description>Daniel wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt; I think that it is working now.  When I am certain, would you like the &quot;final&quot; code.  I simply modified the example code that you had provided earlier with the updated model and model fit, etc.&lt;br&gt;
&lt;br&gt;
Post it on the MATLAB Central File Exchange!</description>
    </item>
  </channel>
</rss>

