Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Calculate R-squared value from gnuplot 'fit' output?

6,145 views
Skip to first unread message

Mike

unread,
Dec 28, 2011, 3:14:18 PM12/28/11
to
OK, my statistics is perhaps not what it should be. I have a script
make a linear fit of some x-y pairs:

#
# Correlations
#
set xdata
set format x
set term png size 400, 400
f(x) = m*x + b
set output "./corr-00.png"
fit f(x) "2011-10.dat" using 2:3 via m,b
plot "2011-10.dat" using 2:3 t "C1 vs C2" with dots, f(x) title "Model
Fit"

And I get the following output, just showing the end here:

Iteration 0
WSSR : 9404.93 delta(WSSR)/WSSR : 0
delta(WSSR) : 0 limit for stopping : 1e-05
lambda : 7.53716

After 3 iterations the fit converged.
final sum of squares of residuals : 1980.57
rel. change during last iteration : -5.27226e-11

degrees of freedom (FIT_NDF) : 4462
rms of residuals (FIT_STDFIT) = sqrt(WSSR/ndf) : 0.66624
variance of residuals (reduced-chisquare) = WSSR/ndf : 0.443875

Final set of parameters Asymptotic Standard Error
======================= ==========================

m = 0.889071 +/- 0.002949 (0.3317%)
b = 0.881951 +/- 0.03129 (3.548%)


correlation matrix of the fit parameters:

m b
m 1.000
b -0.948 1.000

Shouldn't I be able to calculate the R-squared value from this data? I
read in wikipedia that

R^2 1 - (SS_err / SS_tot)

and that WSSR is SS_err, as far as I can make out. Can anyone help me
with SS_tot or another way to do it?

Thanks!

Hans-Bernhard Bröker

unread,
Dec 28, 2011, 4:11:11 PM12/28/11
to
On 28.12.2011 21:14, Mike wrote:

> Shouldn't I be able to calculate the R-squared value from this data?

In a word: no.

R^2 doesn't have any useful relation to what 'fit' calculates.

wolfgang

unread,
Dec 29, 2011, 3:17:06 AM12/29/11
to
Why does that take 3 iterations? That is just a linear LS problem?
Linear LS regression has an analytical solution, i.e. with normal
equations.
Solution should be either intelligent starting values or one iteration
from
dummy starting point?
Wolfgang

Hans-Bernhard Bröker

unread,
Dec 29, 2011, 6:39:53 AM12/29/11
to
On 29.12.2011 09:17, wolfgang wrote:

> Why does that take 3 iterations? That is just a linear LS problem?

Because 'fit' is not linear regression.

Generic tools generally don't work as smoothly as special-purpose ones.

ab

unread,
Jan 2, 2012, 3:37:56 AM1/2/12
to
>
> Why does that take 3 iterations? That is just a linear LS problem?
> Linear LS regression has an analytical solution, i.e. with normal
> equations.
> Solution should be either intelligent starting values or one iteration
> from

Hi,

You can force the fit to converge in one iteration by using
FIT_START_LAMBDA=1.e-15
FIT_MAXITER=1
This is only suited for a linear model.

A better way is the stats command in gnuplot 4.5.
The correlation coefficient r is calculated directly.

benjam...@aztopia.com

unread,
Nov 4, 2013, 10:17:33 PM11/4/13
to
Try using this instead:
stats 'file.dat' using 1:2 name "A"

In should print out something like this:
* FILE:
Records: 21
Out of range: 0
Invalid: 0
Blank: 1
Data Blocks: 1

* COLUMNS:
Mean: 500.0000 7.5762
Std Dev: 302.7650 3.9789
Sum: 10500.0000 159.1000
Sum Sq.: 7.17500e+06 1537.8300

Minimum: 0.0000 [ 0] 1.0000 [ 0]
Maximum: 1000.0000 [20] 14.1000 [20]
Quartile: 250.0000 4.5000
Median: 500.0000 7.2000
Quartile: 750.0000 11.1000

Linear Model: y = 0.01311 x + 1.019
Correlation: r = 0.9979
Sum xy: 1.048e+05

Karl

unread,
Nov 5, 2013, 8:14:06 AM11/5/13
to
Am 05.11.2013 04:17, schrieb benjam...@aztopia.com:
> El miércoles, 28 de diciembre de 2011 15:14:18 UTC-5, Mike escribió:


It´s useless, most likely, to answer to a newspost question that is two
years old. Bonus points for the effort, but your comment will probably
be lost.

K




o...@st-andrews.ac.uk

unread,
Dec 10, 2014, 7:09:29 PM12/10/14
to
It's not useless in this era, somebody may be looking for this help 5 years from now.

ali.a...@gmail.com

unread,
Jan 26, 2015, 2:32:16 PM1/26/15
to
Yes I used it 2 years later. Google indexes all of this stuffs and it was a hit for my query.

thiag...@gmail.com

unread,
Jul 8, 2016, 3:58:20 PM7/8/16
to
I used it NOW =)

luis.b...@gmail.com

unread,
Jul 15, 2016, 11:29:22 AM7/15/16
to
On Friday, July 8, 2016 at 4:58:20 PM UTC-3, thiag...@gmail.com wrote:
> I used it NOW =)

Not exactly five years, but it certainly answered my question

ar...@armbrusters.name

unread,
Feb 21, 2017, 3:40:23 PM2/21/17
to
More than 5 years by now and it's still helpful!

henryx...@gmail.com

unread,
Oct 13, 2017, 1:25:06 PM10/13/17
to
Still relevant!

Karl Ratzsch

unread,
Oct 13, 2017, 1:53:36 PM10/13/17
to
Am 13.10.2017 um 19:25 schrieb henryx...@gmail.com:
> Still relevant!
>

This is a newsgroup.

1. Be polite, and sign your message, and
2. cite the original post, because most people don't read this on
googles stolen archive pages, but in their newsreader, and delete
old messages after a few months.

Karl

ruben safir

unread,
Oct 24, 2017, 5:35:10 PM10/24/17
to
On 10/13/2017 01:53 PM, Karl Ratzsch wrote:
> Am 13.10.2017 um 19:25 schrieb henryx...@gmail.com:
>> Still relevant!
>>
> This is a newsgroup.
>

First of all, your an idiot.

> 1. Be polite, and sign your message, and

Be polite and stop trying to control others behavior. Don't post
messages like this. If you have nothing constructive to say, say nothing.


> 2. cite the original post,

If nobody knows what he refers to, that is his problem. If you want to
ask him wtf he is refering to, just ask.

> because most people don't read this on
> googles stolen archive pages,

That archive, which actually originated with Dejanews before you grew
out of diapers, is in no way stolen and is blessing for the public.

> but in their newsreader, and delete
> old messages after a few months.
>

And if not, you your eyes they are second class humans unfit to stand
with German Supermen like yourself?


Go find some therapy, smoke some grass, or get layed, Do anything more
than troll innocent usenet posters.

Karl Ratzsch

unread,
Oct 25, 2017, 3:26:58 AM10/25/17
to
Am 24.10.2017 um 23:35 schrieb ruben safir:

> messages like this. If you have nothing constructive to say, say nothing.

Word.
0 new messages