Path: news.mathworks.com!not-for-mail
From: "Ken Campbell" <campbeks@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: linear regression - inconsistent results
Date: Thu, 6 Nov 2008 22:11:02 +0000 (UTC)
Organization: University of Kentucky
Lines: 51
Message-ID: <gevq1m$g80$1@fred.mathworks.com>
References: <gevnh1$bnn$1@fred.mathworks.com>
Reply-To: "Ken Campbell" <campbeks@gmail.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1226009462 16640 172.30.248.35 (6 Nov 2008 22:11:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 6 Nov 2008 22:11:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 534287
Xref: news.mathworks.com comp.soft-sys.matlab:499398


"Russ Scott" <robinandruss@gmail.com> wrote in message <gevnh1$bnn$1@fred.mathworks.com>...
> I've been noticing when using regress or polyfit that I'm getting inconsistent result when I switch the 1 independent variable with the dependent variable. Mathematically this does not make sense to me.
> 
> If y = mx + b
> 
> then 
> 
> x = y/m - b/m
> 
> But I've found for certain datasets that when I flip the y and x around using either regress (and adding a column of ones to X) or polyfit(x,y,1) I get non-consistent results.
> 
> This is a short example to illustrate my problem.
> 
> >> d=[    0.0074143     0.052035
>     0.0076173    0.0014361
>     0.0077408   -0.0041507
>      0.013317     0.054487
>      0.013289     0.061777
>      0.013346     0.055137
>       0.01397    -0.046578
>      0.014114    -0.026229
>      0.014658     0.042499
>      0.020282   -0.0010642];
> >> polyfit(d(:,2),d(:,1),1)
> 
> ans =
> 
>     -0.011263     0.012788
> 
> >> polyfit(d(:,1),d(:,2),1)
> 
> ans =
> 
>       -1.0641     0.032315
> 
> THESE ARE INCONSISTENT RESULTS AREN'T THEY?
> e.g., 
> 1/-0.011263 ~=  -1.0641


In addition to the points made by Steve, note that regression minimizes

sum((y_data-y_predicition).^2)

which doesn't have to be the same as

sum((x_data-x_prediction).^2)

so transposing your data and repeating the fit won't normally give related regression parameters.

Ken