<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/161675</link>
    <title>MATLAB Central Newsreader - fitting the norm CDF</title>
    <description>Feed for thread: fitting the norm CDF</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>Mon, 07 Jan 2008 21:30:21 -0500</pubDate>
      <title>fitting the norm CDF</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/161675#408411</link>
      <author>Pete sherer</author>
      <description>I tried using the glmfit to estimate the parameters for the&lt;br&gt;
normal distribution. However, the fit didn't look right. I&lt;br&gt;
presume that I set up the GLMFIT wrongly. Any suggestions&lt;br&gt;
would be appreciate it.&lt;br&gt;
x =&lt;br&gt;
[0.0246;0.04;0.0585;0.0801;0.0926;0.1019;0.1083;0.1178;0.1243;0.1277;0.1342;0.1376;0.1441;0.1509;0.1544;0.1642;0.1709;0.1806;0.1874;0.194;0.1975;0.204;0.2075;0.217;0.2234;0.2452;0.2577;0.2701;0.2887;0.3103;0.3318;0.3534;0.3749;];&lt;br&gt;
y =&lt;br&gt;
[0.0045;0.0045;0.009;0.0224;0.0404;0.0583;0.0852;0.1166;0.148;0.1883;0.2242;0.2601;0.3004;0.3677;0.4126;0.4843;0.5381;0.5964;0.6592;0.7175;0.7623;0.8027;0.843;0.8744;0.9013;0.9372;0.9552;0.9686;0.9821;0.991;1;1;1;];&lt;br&gt;
&lt;br&gt;
b    = glmfit( x, y, 'normal'); &lt;br&gt;
refx = linspace( min(x), max(x), 50);&lt;br&gt;
Xb   = b(1)+ b(2).*refx;&lt;br&gt;
yfit = normcdf( Xb, 0, 1); % Standardized Normal CDF&lt;br&gt;
&lt;br&gt;
figure&lt;br&gt;
hold on&lt;br&gt;
plot( x, y, 'ob')&lt;br&gt;
th = plot( refx, yfit, '--r', 'linewidth', 2.5);&lt;br&gt;
&lt;br&gt;
box on&lt;br&gt;
hold off</description>
    </item>
    <item>
      <pubDate>Mon, 07 Jan 2008 22:00:57 -0500</pubDate>
      <title>Re: fitting the norm CDF</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/161675#408415</link>
      <author>Tom Lane</author>
      <description>&amp;gt;I tried using the glmfit to estimate the parameters for the&lt;br&gt;
&amp;gt; normal distribution. However, the fit didn't look right. I&lt;br&gt;
&amp;gt; presume that I set up the GLMFIT wrongly. Any suggestions&lt;br&gt;
&amp;gt; would be appreciate it.&lt;br&gt;
&amp;gt; x =&lt;br&gt;
&amp;gt; [0.0246;0.04;0.0585;0.0801;0.0926;0.1019;0.1083;0.1178;0.1243;0.1277;0.1342;0.1376;0.1441;0.1509;0.1544;0.1642;0.1709;0.1806;0.1874;0.194;0.1975;0.204;0.2075;0.217;0.2234;0.2452;0.2577;0.2701;0.2887;0.3103;0.3318;0.3534;0.3749;];&lt;br&gt;
&amp;gt; y =&lt;br&gt;
&amp;gt; [0.0045;0.0045;0.009;0.0224;0.0404;0.0583;0.0852;0.1166;0.148;0.1883;0.2242;0.2601;0.3004;0.3677;0.4126;0.4843;0.5381;0.5964;0.6592;0.7175;0.7623;0.8027;0.843;0.8744;0.9013;0.9372;0.9552;0.9686;0.9821;0.991;1;1;1;];&lt;br&gt;
&lt;br&gt;
Pete, the problem as you set it up estimates the parameters for a linear fit &lt;br&gt;
of y as a function of x, under the assumption that the errors in y come from &lt;br&gt;
a normal distribution.&lt;br&gt;
&lt;br&gt;
When I look at a plot of your raw data, the relationship is not linear.  It &lt;br&gt;
appears to resemble the situation where y is the proportion of responses of &lt;br&gt;
some sort (call these &quot;successes&quot;) for various x values.  That proportion &lt;br&gt;
generally seems to follow the shape of a normal cdf.  Is that accurate?&lt;br&gt;
&lt;br&gt;
If it is, you need to enter your response Y as a two-column matrix with each &lt;br&gt;
row giving the number of successes and the number of trials for one &lt;br&gt;
observation.  For the purposes of the following, I set the number of trials &lt;br&gt;
to 100 for each observation, and I used your y to compute the number of &lt;br&gt;
responses.  It turns out glmfit doesn't force this number to be an integer; &lt;br&gt;
maybe non-integer values make sense in some situations.  The &quot;probit&quot; option &lt;br&gt;
requests a curve in the form of a normal cdf.&lt;br&gt;
&lt;br&gt;
Try this and see if it does what you need:&lt;br&gt;
&lt;br&gt;
Y = [y*100, repmat(100,size(y))];&lt;br&gt;
b = glmfit( x, Y, 'binomial','link','probit');&lt;br&gt;
refx = linspace( min(x), max(x), 50);&lt;br&gt;
Xb = b(1)+ b(2).*refx;&lt;br&gt;
yfit = glmval(b,refx,'probit');&lt;br&gt;
figure&lt;br&gt;
hold on&lt;br&gt;
plot( x, y, 'ob')&lt;br&gt;
th = plot( refx, yfit, '--r', 'linewidth', 2.5);&lt;br&gt;
box on&lt;br&gt;
hold off&lt;br&gt;
&lt;br&gt;
-- Tom </description>
    </item>
    <item>
      <pubDate>Mon, 07 Jan 2008 22:39:02 -0500</pubDate>
      <title>Re: fitting the norm CDF</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/161675#408423</link>
      <author>Pete sherer</author>
      <description>&quot;Tom Lane&quot; &amp;lt;tlane@mathworks.com&amp;gt; wrote in message&lt;br&gt;
&amp;lt;flu7ep$hpl$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt;I tried using the glmfit to estimate the parameters for the&lt;br&gt;
&amp;gt; &amp;gt; normal distribution. However, the fit didn't look right. I&lt;br&gt;
&amp;gt; &amp;gt; presume that I set up the GLMFIT wrongly. Any suggestions&lt;br&gt;
&amp;gt; &amp;gt; would be appreciate it.&lt;br&gt;
&amp;gt; &amp;gt; x =&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
[0.0246;0.04;0.0585;0.0801;0.0926;0.1019;0.1083;0.1178;0.1243;0.1277;0.1342;0.1376;0.1441;0.1509;0.1544;0.1642;0.1709;0.1806;0.1874;0.194;0.1975;0.204;0.2075;0.217;0.2234;0.2452;0.2577;0.2701;0.2887;0.3103;0.3318;0.3534;0.3749;];&lt;br&gt;
&amp;gt; &amp;gt; y =&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
[0.0045;0.0045;0.009;0.0224;0.0404;0.0583;0.0852;0.1166;0.148;0.1883;0.2242;0.2601;0.3004;0.3677;0.4126;0.4843;0.5381;0.5964;0.6592;0.7175;0.7623;0.8027;0.843;0.8744;0.9013;0.9372;0.9552;0.9686;0.9821;0.991;1;1;1;];&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Pete, the problem as you set it up estimates the&lt;br&gt;
parameters for a linear fit &lt;br&gt;
&amp;gt; of y as a function of x, under the assumption that the&lt;br&gt;
errors in y come from &lt;br&gt;
&amp;gt; a normal distribution.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; When I look at a plot of your raw data, the relationship&lt;br&gt;
is not linear.  It &lt;br&gt;
&amp;gt; appears to resemble the situation where y is the&lt;br&gt;
proportion of responses of &lt;br&gt;
&amp;gt; some sort (call these &quot;successes&quot;) for various x values. &lt;br&gt;
That proportion &lt;br&gt;
&amp;gt; generally seems to follow the shape of a normal cdf.  Is&lt;br&gt;
that accurate?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If it is, you need to enter your response Y as a&lt;br&gt;
two-column matrix with each &lt;br&gt;
&amp;gt; row giving the number of successes and the number of&lt;br&gt;
trials for one &lt;br&gt;
&amp;gt; observation.  For the purposes of the following, I set the&lt;br&gt;
number of trials &lt;br&gt;
&amp;gt; to 100 for each observation, and I used your y to compute&lt;br&gt;
the number of &lt;br&gt;
&amp;gt; responses.  It turns out glmfit doesn't force this number&lt;br&gt;
to be an integer; &lt;br&gt;
&amp;gt; maybe non-integer values make sense in some situations. &lt;br&gt;
The &quot;probit&quot; option &lt;br&gt;
&amp;gt; requests a curve in the form of a normal cdf.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Try this and see if it does what you need:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Y = [y*100, repmat(100,size(y))];&lt;br&gt;
&amp;gt; b = glmfit( x, Y, 'binomial','link','probit');&lt;br&gt;
&amp;gt; refx = linspace( min(x), max(x), 50);&lt;br&gt;
&amp;gt; Xb = b(1)+ b(2).*refx;&lt;br&gt;
&amp;gt; yfit = glmval(b,refx,'probit');&lt;br&gt;
&amp;gt; figure&lt;br&gt;
&amp;gt; hold on&lt;br&gt;
&amp;gt; plot( x, y, 'ob')&lt;br&gt;
&amp;gt; th = plot( refx, yfit, '--r', 'linewidth', 2.5);&lt;br&gt;
&amp;gt; box on&lt;br&gt;
&amp;gt; hold off&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; -- Tom &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&lt;br&gt;
Hi Tom,&lt;br&gt;
&lt;br&gt;
I tried the code you sent. However, I received the following&lt;br&gt;
error message:&lt;br&gt;
&lt;br&gt;
??? Error using ==&amp;gt; glmfit at 154&lt;br&gt;
Y must contain values in the interval [0,N] for the binomial&lt;br&gt;
distribution.&lt;br&gt;
&lt;br&gt;
I would appreciate your suggestion.&lt;br&gt;
&lt;br&gt;
P</description>
    </item>
    <item>
      <pubDate>Mon, 07 Jan 2008 22:48:02 -0500</pubDate>
      <title>Re: fitting the norm CDF</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/161675#408425</link>
      <author>Pete sherer</author>
      <description>It seems to work now by using&lt;br&gt;
Y = round(Y);&lt;br&gt;
&lt;br&gt;
One more question is how I can can transform the b (fitted&lt;br&gt;
parameters) into the estimated mean and dispersion of the&lt;br&gt;
normal distribution.  From glmfit I received &lt;br&gt;
b(1) =  -3.6396 and&lt;br&gt;
b(2) =  21.6186;&lt;br&gt;
&lt;br&gt;
Thanks a lot.&lt;br&gt;
&lt;br&gt;
P</description>
    </item>
    <item>
      <pubDate>Wed, 09 Jan 2008 20:08:41 -0500</pubDate>
      <title>Re: fitting the norm CDF</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/161675#408766</link>
      <author>Tom Lane</author>
      <description>&amp;gt; One more question is how I can can transform the b (fitted&lt;br&gt;
&amp;gt; parameters) into the estimated mean and dispersion of the&lt;br&gt;
&amp;gt; normal distribution.  From glmfit I received&lt;br&gt;
&amp;gt; b(1) =  -3.6396 and&lt;br&gt;
&amp;gt; b(2) =  21.6186;&lt;br&gt;
&lt;br&gt;
Pete, the model being fit is&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;p = normcdf( b(1) + b(2)*x )&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= normcdf(  (x - (-b(1)/b(2))  )/ (1/b(2))  )&lt;br&gt;
&lt;br&gt;
so -b(1)/b(2) and 1/b(2) are I think what you are trying to get.  Try this &lt;br&gt;
after the code you have so far:&lt;br&gt;
&lt;br&gt;
line(refx,normcdf(refx, -b(1)/b(2), 1/b(2)),'color','g')&lt;br&gt;
&lt;br&gt;
-- Tom </description>
    </item>
  </channel>
</rss>

