Trend line
From Wikipedia, the free encyclopedia
For trend lines as used in technical analysis, see Trend lines (technical analysis)
In statistics, a trend line represents a trend, the long-term movement in time series data after other components have been accounted for. It tells whether a particular data set (say GDP, oil prices or stock prices) have increased or decreased over the period of time. Trend line is estimated using statistical techniques like linear regression.
Trend lines are also used as best-fit lines in graphing situations, using it to show the best-fit line for a particular set of data numbers.
[edit] Java code to add a linear trend line
While plotting points on a graph, simply call addPoint() for each point on your graph, then call drawTrend(). A trendline is a line that travels through a middle range in a series of points without touching the points.
double sumXY = 0; double sumX = 0; double sumY = 0; double sumXsq = 0; int n = 0; double m; double b; private void addPoint(int x,int y) { sumXY += x*y; sumX += x; sumY += y; sumXsq += x*x; n++; } private void calcLine() { m = (n*sumXY - (sumX*sumY))/(n*sumXsq - sumX*sumX); b = (sumY/n) - (m*(sumX/n)); } private void drawTrend(int x1, int x2) { calcLine(); int y1=(int)(m*x1+b); int y2=(int)(m*x2+b); /* draw line from x1,y1 to x2,y2 */ }