CCL Home Page
Up Directory CCL linreg
From Anchor.!headwall.Stanford.EDU!agate!usenet.hana.nm.kr!scoupe.postech.ac.kr!wgchoe Wed Mar 16 08:14:10 PST 1994
Article: 2301 of comp.graphics.gnuplot
Path: Anchor.!headwall.Stanford.EDU!agate!usenet.hana.nm.kr!scoupe.postech.ac.kr!wgchoe
From: wgchoe@scoupe.postech.ac.kr ( Kim Hee Jeong(prof-swan))
Newsgroups: comp.graphics.gnuplot
Subject: Linear Regression : use awk.
Date: 16 Mar 1994 14:26:23 GMT
Organization: HANAnet Operating Centre(KTRC)
Lines: 37
Message-ID: <2m74ug$1gs@usenet.hana.nm.kr>
NNTP-Posting-Host: scoupe.postech.ac.kr
X-Newsreader: TIN [version 1.2 PL2]


 Gnuplot does not support linear regression, and I recommend you to use
the pipe input and the unix utility awk. Suppose you have two column x,y data.

====== Your data file ========
1 1.2
2 2.1
3 3.2
4 4.1
5 5.3
6 6.4
7 7.7
====== End ===================

 And here is the awk script, named as "lsq" (least square fit), which prints
out the x values and the least square fit.

====== The Awk script , named "lsq" as ========
{ x[NR] = $1; y[NR] = $2;\
 sx += x[NR]; sy += y[NR]; \
 sxx += x[NR]*x[NR];\
 sxy += x[NR]*y[NR];\
}END{\
 det = NR*sxx - sx*sx;\
 a = (NR*sxy - sx*sy)/det;\
 b = (-sx*sxy+sxx*sy)/det;\
 for(i=1;i<=NR;i++) print x[i],a*x[i]+b;}
===============================================

To see the result, 

gnuplot> plot 'data' w po, ' log($1), $2 -> log($2), and the
last line , a*x[i]+b -> exp( b + a*x[i] ).




Modified: Mon Nov 13 17:00:00 1995 GMT
Page accessed 6259 times since Sat Apr 17 21:58:08 1999 GMT