<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/165557</link>
    <title>MATLAB Central Newsreader - Linear regression.</title>
    <description>Feed for thread: Linear regression.</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, 12 Mar 2008 19:52:24 -0400</pubDate>
      <title>Linear regression.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/165557#420551</link>
      <author>Zebbik</author>
      <description>Hello.&lt;br&gt;
&lt;br&gt;
My problem is that I am supposed to find trend line /regression of from &lt;br&gt;
the results made in experiment. I know&lt;br&gt;
&lt;br&gt;
p = polyfit(x,y,1)&lt;br&gt;
&lt;br&gt;
gives me coefficients of line (the correlation is strong almost 1 so &lt;br&gt;
it's linear tendency), where in terms of y = mx + c&lt;br&gt;
&lt;br&gt;
p(1) - slope (m)&lt;br&gt;
p(2) - 'c' coefficient&lt;br&gt;
&lt;br&gt;
I know also that&lt;br&gt;
&lt;br&gt;
yfit = polyval(p, y)&lt;br&gt;
&lt;br&gt;
gives me the fit of line such that it's going to be linear reggresion.&lt;br&gt;
&lt;br&gt;
Now. The value im looking for is the slope. I would like to find the &lt;br&gt;
slope itself with the error or let's say Delta that the slope could &lt;br&gt;
differ arround like&lt;br&gt;
(Slope - Delta_Slope, Slope + Delta_Slope)&lt;br&gt;
&lt;br&gt;
Does any1 know how to do that?&lt;br&gt;
&lt;br&gt;
Thanks.</description>
    </item>
    <item>
      <pubDate>Thu, 13 Mar 2008 00:21:02 -0400</pubDate>
      <title>Re: Linear regression.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/165557#420590</link>
      <author>Paul </author>
      <description>Zebbik &amp;lt;zebik@op.pl&amp;gt; wrote in message&lt;br&gt;
&amp;lt;fr9c9t$o1p$1@news.onet.pl&amp;gt;...&lt;br&gt;
&amp;gt; Hello.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; My problem is that I am supposed to find trend line&lt;br&gt;
/regression of from &lt;br&gt;
&amp;gt; the results made in experiment. I know&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; p = polyfit(x,y,1)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; gives me coefficients of line (the correlation is strong&lt;br&gt;
almost 1 so &lt;br&gt;
&amp;gt; it's linear tendency), where in terms of y = mx + c&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; p(1) - slope (m)&lt;br&gt;
&amp;gt; p(2) - 'c' coefficient&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I know also that&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; yfit = polyval(p, y)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; gives me the fit of line such that it's going to be linear&lt;br&gt;
reggresion.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Now. The value im looking for is the slope. I would like&lt;br&gt;
to find the &lt;br&gt;
&amp;gt; slope itself with the error or let's say Delta that the&lt;br&gt;
slope could &lt;br&gt;
&amp;gt; differ arround like&lt;br&gt;
&amp;gt; (Slope - Delta_Slope, Slope + Delta_Slope)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Does any1 know how to do that?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks.&lt;br&gt;
&lt;br&gt;
I suggest you search the file exchange.</description>
    </item>
    <item>
      <pubDate>Thu, 13 Mar 2008 02:38:50 -0400</pubDate>
      <title>Re: Linear regression.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/165557#420595</link>
      <author>Arthur G</author>
      <description>On 2008-03-12 20:21:02 -0400, &quot;Paul &quot; &amp;lt;par@ceri.memphis.edu&amp;gt; said:&lt;br&gt;
&lt;br&gt;
&amp;gt; Zebbik &amp;lt;zebik@op.pl&amp;gt; wrote in message&lt;br&gt;
&amp;gt; &amp;lt;fr9c9t$o1p$1@news.onet.pl&amp;gt;...&lt;br&gt;
&amp;gt;&amp;gt; Hello.&lt;br&gt;
&amp;gt;&amp;gt; &lt;br&gt;
&amp;gt;&amp;gt; My problem is that I am supposed to find trend line&lt;br&gt;
&amp;gt; /regression of from&lt;br&gt;
&amp;gt;&amp;gt; the results made in experiment. I know&lt;br&gt;
&amp;gt;&amp;gt; &lt;br&gt;
&amp;gt;&amp;gt; p = polyfit(x,y,1)&lt;br&gt;
&amp;gt;&amp;gt; &lt;br&gt;
&amp;gt;&amp;gt; gives me coefficients of line (the correlation is strong&lt;br&gt;
&amp;gt; almost 1 so&lt;br&gt;
&amp;gt;&amp;gt; it's linear tendency), where in terms of y = mx + c&lt;br&gt;
&amp;gt;&amp;gt; &lt;br&gt;
&amp;gt;&amp;gt; p(1) - slope (m)&lt;br&gt;
&amp;gt;&amp;gt; p(2) - 'c' coefficient&lt;br&gt;
&amp;gt;&amp;gt; &lt;br&gt;
&amp;gt;&amp;gt; I know also that&lt;br&gt;
&amp;gt;&amp;gt; &lt;br&gt;
&amp;gt;&amp;gt; yfit = polyval(p, y)&lt;br&gt;
&amp;gt;&amp;gt; &lt;br&gt;
&amp;gt;&amp;gt; gives me the fit of line such that it's going to be linear&lt;br&gt;
&amp;gt; reggresion.&lt;br&gt;
&amp;gt;&amp;gt; &lt;br&gt;
&amp;gt;&amp;gt; Now. The value im looking for is the slope. I would like&lt;br&gt;
&amp;gt; to find the&lt;br&gt;
&amp;gt;&amp;gt; slope itself with the error or let's say Delta that the&lt;br&gt;
&amp;gt; slope could&lt;br&gt;
&amp;gt;&amp;gt; differ arround like&lt;br&gt;
&amp;gt;&amp;gt; (Slope - Delta_Slope, Slope + Delta_Slope)&lt;br&gt;
&amp;gt;&amp;gt; &lt;br&gt;
&amp;gt;&amp;gt; Does any1 know how to do that?&lt;br&gt;
&amp;gt;&amp;gt; &lt;br&gt;
&amp;gt;&amp;gt; Thanks.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I suggest you search the file exchange.&lt;br&gt;
&lt;br&gt;
If you have the statistics toolbox, the regress function will give 95% &lt;br&gt;
confidence intervals.</description>
    </item>
    <item>
      <pubDate>Thu, 13 Mar 2008 12:56:07 -0400</pubDate>
      <title>Re: Linear regression.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/165557#420676</link>
      <author>Peter Perkins</author>
      <description>Zebbik wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt; Now. The value im looking for is the slope. I would like to find the &lt;br&gt;
&amp;gt; slope itself with the error or let's say Delta that the slope could &lt;br&gt;
&amp;gt; differ arround like&lt;br&gt;
&amp;gt; (Slope - Delta_Slope, Slope + Delta_Slope)&lt;br&gt;
&lt;br&gt;
POLYCONF in the Statistics Toolbox, or LSCOV in core MATLAB.&lt;br&gt;
&lt;br&gt;
Hope this helps.&lt;br&gt;
&lt;br&gt;
- Peter Perkins&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;The MathWorks, Inc.</description>
    </item>
    <item>
      <pubDate>Thu, 13 Mar 2008 16:38:20 -0400</pubDate>
      <title>Re: Linear regression.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/165557#420733</link>
      <author>Zebbik</author>
      <description>Paul wrote:&lt;br&gt;
&amp;gt; Zebbik &amp;lt;zebik@op.pl&amp;gt; wrote in message&lt;br&gt;
&amp;gt; &amp;lt;fr9c9t$o1p$1@news.onet.pl&amp;gt;...&lt;br&gt;
&amp;gt;&amp;gt; Hello.&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; My problem is that I am supposed to find trend line&lt;br&gt;
&amp;gt; /regression of from &lt;br&gt;
&amp;gt;&amp;gt; the results made in experiment. I know&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; p = polyfit(x,y,1)&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; gives me coefficients of line (the correlation is strong&lt;br&gt;
&amp;gt; almost 1 so &lt;br&gt;
&amp;gt;&amp;gt; it's linear tendency), where in terms of y = mx + c&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; p(1) - slope (m)&lt;br&gt;
&amp;gt;&amp;gt; p(2) - 'c' coefficient&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; I know also that&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; yfit = polyval(p, y)&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; gives me the fit of line such that it's going to be linear&lt;br&gt;
&amp;gt; reggresion.&lt;br&gt;
&amp;gt;&amp;gt; Now. The value im looking for is the slope. I would like&lt;br&gt;
&amp;gt; to find the &lt;br&gt;
&amp;gt;&amp;gt; slope itself with the error or let's say Delta that the&lt;br&gt;
&amp;gt; slope could &lt;br&gt;
&amp;gt;&amp;gt; differ arround like&lt;br&gt;
&amp;gt;&amp;gt; (Slope - Delta_Slope, Slope + Delta_Slope)&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; Does any1 know how to do that?&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; Thanks.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I suggest you search the file exchange.&lt;br&gt;
I am not quite sure what you mean.</description>
    </item>
    <item>
      <pubDate>Thu, 13 Mar 2008 18:20:58 -0400</pubDate>
      <title>Re: Linear regression.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/165557#420764</link>
      <author>Zebbik</author>
      <description>Peter Perkins wrote:&lt;br&gt;
&amp;gt; Zebbik wrote:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;&amp;gt; Now. The value im looking for is the slope. I would like to find the &lt;br&gt;
&amp;gt;&amp;gt; slope itself with the error or let's say Delta that the slope could &lt;br&gt;
&amp;gt;&amp;gt; differ arround like&lt;br&gt;
&amp;gt;&amp;gt; (Slope - Delta_Slope, Slope + Delta_Slope)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; POLYCONF in the Statistics Toolbox, or LSCOV in core MATLAB.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Hope this helps.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; - Peter Perkins&lt;br&gt;
&amp;gt;   The MathWorks, Inc.&lt;br&gt;
The thing i am looking for is in Excel, however, i would like to find it &lt;br&gt;
in MATLAB to be honest. I will try to explain that on Excel example&lt;br&gt;
&lt;br&gt;
In EXCEL there is a formula called LINEST and has the form below&lt;br&gt;
&lt;br&gt;
LINEST(knowm_y value cells, known_x values cells, CONST, STATS)&lt;br&gt;
&lt;br&gt;
This formula produce more or less such results as:&lt;br&gt;
SLope Coeff          Point Of intercept&lt;br&gt;
Slope Coeff Error    Point Of Intercep Error&lt;br&gt;
...&lt;br&gt;
...&lt;br&gt;
...&lt;br&gt;
&lt;br&gt;
I dont know that yet but i believe in produces results with 95% &lt;br&gt;
confidence intervals. The other values are not important here at the &lt;br&gt;
moment. The Slope Error is the thing i am looking for in MATLAB.&lt;br&gt;
Can someone please be so kind and help me to find/understand that.&lt;br&gt;
&lt;br&gt;
Regards</description>
    </item>
    <item>
      <pubDate>Thu, 13 Mar 2008 18:50:19 -0400</pubDate>
      <title>Re: Linear regression.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/165557#420772</link>
      <author>Yuri Geshelin</author>
      <description>Hello,&lt;br&gt;
&lt;br&gt;
I had the same problem and did not find anything in matlab.&lt;br&gt;
Below is the code, which I wrote up for this purpose. It &lt;br&gt;
contains the reference to the source, which I used. Perhaps &lt;br&gt;
I will consider uploading it to file exchange, but for now &lt;br&gt;
I will just copy-paste it. Hope you will cope with text &lt;br&gt;
wrapping and figure it out.&lt;br&gt;
&lt;br&gt;
Yuri&lt;br&gt;
------------------------&lt;br&gt;
%*******************************&lt;br&gt;
function [sesl, cisl, sein, ciin] = secisi(X,Y,pr);&lt;br&gt;
&lt;br&gt;
% Returns Standard Errors and Confidence Intervals&lt;br&gt;
% for the Slope and Intercept of a regression.&lt;br&gt;
&lt;br&gt;
% Author: Yuri Geshelin, 2002.&lt;br&gt;
&lt;br&gt;
% Source: N. R. Draper and H. Smith, 1966:&lt;br&gt;
% Applied Regression Analysis, 407 p. Publ. by&lt;br&gt;
% John Wiley and Sons, Inc. New York - London - Sydney.&lt;br&gt;
&lt;br&gt;
% Input: &lt;br&gt;
% 1-D arrays X and Y, for which the regression&lt;br&gt;
%        Y = B0 + B1 * X is computed&lt;br&gt;
% pr - probability (e.g. if we want 95% &lt;br&gt;
%      confidence level, then pr = 95.&lt;br&gt;
&lt;br&gt;
% Output: &lt;br&gt;
% sesl - standard error for slope B1&lt;br&gt;
% clsl - pr%-confindence interval for slope B1&lt;br&gt;
% sein - standard error for intercept B0 &lt;br&gt;
% clin - pr%-confindence interval for intercept B0&lt;br&gt;
&lt;br&gt;
if pr &amp;lt; 10 | pr &amp;gt; 99.9&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;error('pr should be between 10 and 99.9!') &lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
n = length(X);&lt;br&gt;
if length(Y) ~= n&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;error('X, Y should be the same lengths!')&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
n2 = n - 2; % n - 2 degrees of freedom&lt;br&gt;
&lt;br&gt;
if n2 &amp;lt; 121 % if n2 = 120, then we already would &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;% have to use the next-to-last line &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;% of the table on p. 305: this code is only&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;% for the last line.&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;error('This code only works with n &amp;gt; 120!')&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
% The following line is the result of &lt;br&gt;
% prob = 100 * ...&lt;br&gt;
% (1 - [0.9:-0.2:0.3 0.2 0.1 0.05 0.02 0.01 0.001]) ...&lt;br&gt;
% (see p. 305):&lt;br&gt;
&lt;br&gt;
prob = [10 30 50 70 80 90 95 98 99 99.9]; % percentage&lt;br&gt;
&lt;br&gt;
pp = [0.126 0.385 0.674 1.036 1.282 ...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1.645 1.960 2.326 2.576 3.291]; % last line of the &lt;br&gt;
table,&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;% p. 305.&lt;br&gt;
&lt;br&gt;
% Compute total corrected sum of squares (SS) of the Y's&lt;br&gt;
% (see p.14 and table on p. 16):&lt;br&gt;
&lt;br&gt;
SStot = sum((Y - mean(Y)).^2);&lt;br&gt;
&lt;br&gt;
% Compute SS due to regression (see p. 16):&lt;br&gt;
&lt;br&gt;
SX2 = sum(X .^ 2);&lt;br&gt;
SSrgr = ...&lt;br&gt;
(sum(X .* Y) - sum(X) * sum(Y) / n) ^2 / ...&lt;br&gt;
(SX2 - sum(X) ^2 / n);&lt;br&gt;
&lt;br&gt;
% Compute SS due to residual (see p. 16):&lt;br&gt;
&lt;br&gt;
SSres = SStot - SSrgr;&lt;br&gt;
&lt;br&gt;
% Compute mean square about regression &lt;br&gt;
% (see tables on pp. 15, 16):&lt;br&gt;
&lt;br&gt;
s2 = SSres / n2; &lt;br&gt;
&lt;br&gt;
% Compute estimate of variance of slope B1 (p. 19)&lt;br&gt;
&lt;br&gt;
sesl = sqrt(s2 / sum((X - mean(X)) .^2 ));&lt;br&gt;
&lt;br&gt;
% Found the interpolated value from the table&lt;br&gt;
% (page 305):&lt;br&gt;
&lt;br&gt;
val_int = interp1(prob,pp,pr);&lt;br&gt;
&lt;br&gt;
% Compute confidence limit for slope:&lt;br&gt;
&lt;br&gt;
cisl =  val_int * sesl;&lt;br&gt;
&lt;br&gt;
% Compute estimate of variance of intercept B0 (p. 21)&lt;br&gt;
&lt;br&gt;
sein = sesl * sqrt(SX2 / n);&lt;br&gt;
&lt;br&gt;
% Compute confidence limit for intercept:&lt;br&gt;
&lt;br&gt;
ciin = val_int * sein;&lt;br&gt;
%***********************************</description>
    </item>
    <item>
      <pubDate>Thu, 13 Mar 2008 19:30:56 -0400</pubDate>
      <title>Re: Linear regression.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/165557#420777</link>
      <author>Peter Perkins</author>
      <description>Zebbik wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt; The thing i am looking for is in Excel, however, i would like to find it &lt;br&gt;
&amp;gt; in MATLAB to be honest. I will try to explain that on Excel example&lt;br&gt;
&lt;br&gt;
Again, POLYCONF in the Statistics Toolbox, or LSCOV in core MATLAB.</description>
    </item>
    <item>
      <pubDate>Thu, 13 Mar 2008 19:43:02 -0400</pubDate>
      <title>Re: Linear regression.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/165557#420782</link>
      <author>Yuri Geshelin</author>
      <description>Peter Perkins &amp;lt;Peter.PerkinsRemoveThis@mathworks.com&amp;gt; wrote &lt;br&gt;
in message &amp;lt;frbvdg$7t7$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Zebbik wrote:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; The thing i am looking for is in Excel, however, i &lt;br&gt;
would like to find it &lt;br&gt;
&amp;gt; &amp;gt; in MATLAB to be honest. I will try to explain that on &lt;br&gt;
Excel example&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Again, POLYCONF in the Statistics Toolbox, or LSCOV in &lt;br&gt;
core MATLAB.&lt;br&gt;
&lt;br&gt;
Hi,&lt;br&gt;
&lt;br&gt;
Here is what Zebbik wrote:&lt;br&gt;
&lt;br&gt;
&quot;The Slope Error is the thing i am looking for in MATLAB.&quot;&lt;br&gt;
&lt;br&gt;
Does lscov or polyconf accomplish this task?</description>
    </item>
    <item>
      <pubDate>Fri, 14 Mar 2008 13:13:13 -0400</pubDate>
      <title>Re: Linear regression.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/165557#420896</link>
      <author>Peter Perkins</author>
      <description>Yuri Geshelin wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt; Here is what Zebbik wrote:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &quot;The Slope Error is the thing i am looking for in MATLAB.&quot;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Does lscov or polyconf accomplish this task?&lt;br&gt;
&lt;br&gt;
Yuri, &quot;yes&quot; to LSCOV (depending on what is meant by &quot;error&quot;), but you're &lt;br&gt;
right, my suggestion of polyconf was off track; I I wasn't paying enough &lt;br&gt;
attention.&lt;br&gt;
&lt;br&gt;
Zebbik, if by &quot;error&quot;, you mean a standard error, then LSCOV will give &lt;br&gt;
you that as its second output.&lt;br&gt;
&lt;br&gt;
If you want a confidence interval for the coefficient, then REGRESS in &lt;br&gt;
the Statistics Toolbox (as pointed out by Arthur G) returns that as its &lt;br&gt;
second output.&lt;br&gt;
&lt;br&gt;
In both cases, all you have to do is to create the design matrix X as&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;X = [ones(length(x),1) x(:)]&lt;br&gt;
&lt;br&gt;
where x and y are vectors containing your data.</description>
    </item>
    <item>
      <pubDate>Tue, 18 Mar 2008 14:01:56 -0400</pubDate>
      <title>Re: Linear regression.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/165557#421491</link>
      <author>Zebbik</author>
      <description>Yuri Geshelin wrote:&lt;br&gt;
&amp;gt; Hello,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I had the same problem and did not find anything in matlab.&lt;br&gt;
&amp;gt; Below is the code, which I wrote up for this purpose. It &lt;br&gt;
&amp;gt; contains the reference to the source, which I used. Perhaps &lt;br&gt;
&amp;gt; I will consider uploading it to file exchange, but for now &lt;br&gt;
&amp;gt; I will just copy-paste it. Hope you will cope with text &lt;br&gt;
&amp;gt; wrapping and figure it out.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Yuri&lt;br&gt;
&amp;gt; ------------------------&lt;br&gt;
&amp;gt; %*******************************&lt;br&gt;
&amp;gt; function [sesl, cisl, sein, ciin] = secisi(X,Y,pr);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Returns Standard Errors and Confidence Intervals&lt;br&gt;
&amp;gt; % for the Slope and Intercept of a regression.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Author: Yuri Geshelin, 2002.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Source: N. R. Draper and H. Smith, 1966:&lt;br&gt;
&amp;gt; % Applied Regression Analysis, 407 p. Publ. by&lt;br&gt;
&amp;gt; % John Wiley and Sons, Inc. New York - London - Sydney.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Input: &lt;br&gt;
&amp;gt; % 1-D arrays X and Y, for which the regression&lt;br&gt;
&amp;gt; %        Y = B0 + B1 * X is computed&lt;br&gt;
&amp;gt; % pr - probability (e.g. if we want 95% &lt;br&gt;
&amp;gt; %      confidence level, then pr = 95.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Output: &lt;br&gt;
&amp;gt; % sesl - standard error for slope B1&lt;br&gt;
&amp;gt; % clsl - pr%-confindence interval for slope B1&lt;br&gt;
&amp;gt; % sein - standard error for intercept B0 &lt;br&gt;
&amp;gt; % clin - pr%-confindence interval for intercept B0&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; if pr &amp;lt; 10 | pr &amp;gt; 99.9&lt;br&gt;
&amp;gt;    error('pr should be between 10 and 99.9!') &lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; n = length(X);&lt;br&gt;
&amp;gt; if length(Y) ~= n&lt;br&gt;
&amp;gt;    error('X, Y should be the same lengths!')&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; n2 = n - 2; % n - 2 degrees of freedom&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; if n2 &amp;lt; 121 % if n2 = 120, then we already would &lt;br&gt;
&amp;gt;             % have to use the next-to-last line &lt;br&gt;
&amp;gt;             % of the table on p. 305: this code is only&lt;br&gt;
&amp;gt;             % for the last line.&lt;br&gt;
&amp;gt;    error('This code only works with n &amp;gt; 120!')&lt;br&gt;
&amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % The following line is the result of &lt;br&gt;
&amp;gt; % prob = 100 * ...&lt;br&gt;
&amp;gt; % (1 - [0.9:-0.2:0.3 0.2 0.1 0.05 0.02 0.01 0.001]) ...&lt;br&gt;
&amp;gt; % (see p. 305):&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; prob = [10 30 50 70 80 90 95 98 99 99.9]; % percentage&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; pp = [0.126 0.385 0.674 1.036 1.282 ...&lt;br&gt;
&amp;gt;       1.645 1.960 2.326 2.576 3.291]; % last line of the &lt;br&gt;
&amp;gt; table,&lt;br&gt;
&amp;gt;                                       % p. 305.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Compute total corrected sum of squares (SS) of the Y's&lt;br&gt;
&amp;gt; % (see p.14 and table on p. 16):&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; SStot = sum((Y - mean(Y)).^2);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Compute SS due to regression (see p. 16):&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; SX2 = sum(X .^ 2);&lt;br&gt;
&amp;gt; SSrgr = ...&lt;br&gt;
&amp;gt; (sum(X .* Y) - sum(X) * sum(Y) / n) ^2 / ...&lt;br&gt;
&amp;gt; (SX2 - sum(X) ^2 / n);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Compute SS due to residual (see p. 16):&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; SSres = SStot - SSrgr;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Compute mean square about regression &lt;br&gt;
&amp;gt; % (see tables on pp. 15, 16):&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; s2 = SSres / n2; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Compute estimate of variance of slope B1 (p. 19)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; sesl = sqrt(s2 / sum((X - mean(X)) .^2 ));&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Found the interpolated value from the table&lt;br&gt;
&amp;gt; % (page 305):&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; val_int = interp1(prob,pp,pr);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Compute confidence limit for slope:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; cisl =  val_int * sesl;&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Compute estimate of variance of intercept B0 (p. 21)&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; sein = sesl * sqrt(SX2 / n);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % Compute confidence limit for intercept:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; ciin = val_int * sein;&lt;br&gt;
&amp;gt; %***********************************&lt;br&gt;
&amp;gt; &lt;br&gt;
thanks for that =))</description>
    </item>
    <item>
      <pubDate>Tue, 18 Mar 2008 14:04:06 -0400</pubDate>
      <title>Re: Linear regression.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/165557#421492</link>
      <author>Zebbik</author>
      <description>Peter Perkins wrote:&lt;br&gt;
&amp;gt; Yuri Geshelin wrote:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;&amp;gt; Here is what Zebbik wrote:&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; &quot;The Slope Error is the thing i am looking for in MATLAB.&quot;&lt;br&gt;
&amp;gt;&amp;gt;&lt;br&gt;
&amp;gt;&amp;gt; Does lscov or polyconf accomplish this task?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Yuri, &quot;yes&quot; to LSCOV (depending on what is meant by &quot;error&quot;), but you're &lt;br&gt;
&amp;gt; right, my suggestion of polyconf was off track; I I wasn't paying enough &lt;br&gt;
&amp;gt; attention.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Zebbik, if by &quot;error&quot;, you mean a standard error, then LSCOV will give &lt;br&gt;
&amp;gt; you that as its second output.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If you want a confidence interval for the coefficient, then REGRESS in &lt;br&gt;
&amp;gt; the Statistics Toolbox (as pointed out by Arthur G) returns that as its &lt;br&gt;
&amp;gt; second output.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; In both cases, all you have to do is to create the design matrix X as&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt;    X = [ones(length(x),1) x(:)]&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; where x and y are vectors containing your data.&lt;br&gt;
It's np. thanks for ur answer it is always helpful to know something new.</description>
    </item>
    <item>
      <pubDate>Wed, 13 Apr 2011 01:15:07 -0400</pubDate>
      <title>Re: Linear regression.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/165557#830799</link>
      <author>ashkan </author>
      <description>Zebbik &amp;lt;zebik@op.pl&amp;gt; wrote in message &amp;lt;froi4p$e0s$2@news.onet.pl&amp;gt;...&lt;br&gt;
&amp;gt; Peter Perkins wrote:&lt;br&gt;
&amp;gt; &amp;gt; Yuri Geshelin wrote:&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; Here is what Zebbik wrote:&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; &quot;The Slope Error is the thing i am looking for in MATLAB.&quot;&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt;&amp;gt; Does lscov or polyconf accomplish this task?&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Yuri, &quot;yes&quot; to LSCOV (depending on what is meant by &quot;error&quot;), but you're &lt;br&gt;
&amp;gt; &amp;gt; right, my suggestion of polyconf was off track; I I wasn't paying enough &lt;br&gt;
&amp;gt; &amp;gt; attention.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Zebbik, if by &quot;error&quot;, you mean a standard error, then LSCOV will give &lt;br&gt;
&amp;gt; &amp;gt; you that as its second output.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; If you want a confidence interval for the coefficient, then REGRESS in &lt;br&gt;
&amp;gt; &amp;gt; the Statistics Toolbox (as pointed out by Arthur G) returns that as its &lt;br&gt;
&amp;gt; &amp;gt; second output.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; In both cases, all you have to do is to create the design matrix X as&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt;    X = [ones(length(x),1) x(:)]&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; where x and y are vectors containing your data.&lt;br&gt;
&amp;gt; It's np. thanks for ur answer it is always helpful to know something new.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
[b,stats] = robustfit(x,y,'ols') &lt;br&gt;
&lt;br&gt;
returns a stats structure with the following fields:&lt;br&gt;
stats.ols_s - sigma estimate (rmse) from least squares fit&lt;br&gt;
&lt;br&gt;
stats.robust_s - robust estimate of sigma&lt;br&gt;
&lt;br&gt;
&amp;nbsp;stats.mad_s - estimate of sigma computed using the median absolute deviation of the residuals from their median; used for scaling residuals during the iterative fitting&lt;br&gt;
&lt;br&gt;
stats.s - final estimate of sigma, the larger of robust_s and a weighted average of ols_s and robust_s&lt;br&gt;
&lt;br&gt;
stats.se - standard error of coefficient estimates&lt;br&gt;
&lt;br&gt;
stats.t - ratio of b to stats.se&lt;br&gt;
&lt;br&gt;
&amp;nbsp;stats.p - p-values for stats.t&lt;br&gt;
&lt;br&gt;
&amp;nbsp;stats.coeffcorr - estimated correlation of coefficient estimates&lt;br&gt;
&lt;br&gt;
stats.w - vector of weights for robust fit stats.h - vector of leverage values for least squares fit&lt;br&gt;
&lt;br&gt;
stats.dfe - degrees of freedom for error&lt;br&gt;
&lt;br&gt;
stats.R - R factor in QR decomposition of X matrix</description>
    </item>
    <item>
      <pubDate>Wed, 13 Apr 2011 03:30:08 -0400</pubDate>
      <title>Re: Linear regression.</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/165557#830808</link>
      <author>John D'Errico</author>
      <description>&quot;Yuri Geshelin&quot; wrote in message &amp;lt;frbt1b$9nn$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hello,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I had the same problem and did not find anything in matlab.&lt;br&gt;
&lt;br&gt;
You did not look that hard then. &lt;br&gt;
&lt;br&gt;
I can point out at least three places at a glance.&lt;br&gt;
&lt;br&gt;
john</description>
    </item>
  </channel>
</rss>

