l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
November 4: Social gathering
Next Installfest:
TBD
Latest News:
Oct. 24: LUGOD election season has begun!
Page last updated:
2003 Mar 21 14:20

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] OT - Finding slope of a line, with lots of points
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] OT - Finding slope of a line, with lots of points



hi jay,

that's called the best fit line, least squares, or linear regression.
i'm sure you can find it on google.

the main idea is:

1. draw an "abstract line" that represents the best fit with no spcified
   slope and y intercept.

2. compute the sum of the distances of each data point to the best fit
   line.

3. realize that the sum of all the distances is zero.  after all, this
   is what we mean by a "best fit line".

4. realize that the dilema is answered by summing the absolute value of
   all the distances between your data points and the best fit line.


in terms of numbers, form a sum of the square of all deviations.
suppose you have N data points.  the sum of deviations is:

          N            N
   D^2 = sum (di)^2 = sum (yi - mxi - b)^2
         i=0          i=0

where (yi, xi) are your data points and (m, b) characterize the best fit
line.

minimize with respect to m (the slope of the best fit line) and b (the y
intercept of the best fit line).  these two equations are minimized when
their derivates are equal to zero.   technically, you need to take a 2nd
derivative to make sure you didn't find maximums or inflection points,
but take my word for it right now.  i've done the calculation many times
over).

so now you have two equations, in m and b, which are set equal to zero.

solve one for m, then plug m into the 2nd equation.
solve the 2nd equation for b.  plug b back into m.
now you have an equation for m and b of the best fit line that only
   depends on your data points, xi and yi.

i don't actually have the equation in front of me -- i derive it every
time i need it (or if a computer is around, i look it up).   :)

pete


BEGIN jAY Strauss <me@heyjay.com> 
> Sorry, I already googled, but can't find what I'm looking for.
> 
> I remember back in science class (must have been Chem), we'd do experiments
> and plot a bunch of points on graph paper.  Then we'd fudge a line that went
> thru the points (trying to get equal numbers of points on one side of the
> line as the other), and that was our "expected" slope.
> 
> Is there some formula or algorithm for doing this with a computer? (I'll do
> it in Perl)  Or where, under what topic would I go a googling?
> 
> Thank
> Jay
> 
> _______________________________________________
> vox-tech mailing list
> vox-tech@lists.lugod.org
> http://lists.lugod.org/mailman/listinfo/vox-tech

-- 
Fingerprint: B9F1 6CF3 47C4 7CD8 D33E 70A9 A3B9 1945 67EA 951D
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
O'Reilly and Associates
For numerous book donations.