Can't make correct linear extrapolation. Here is the graph.
It is clear that the extrapolation should decrease, because there are points on the left at the top, and on the right, everything is at the bottom, and there are many of them. Sample data.
1.12.2010;6700
5.12.2010;330000
8.12.2010;45300
12.12.2010;15400
5.05.2011;5300
31.05.2011;1500
2.06.2011;11400
24.11.2011;51000
19.03.2012;3300
....
I draw the graph using the following script.
#! /usr/bin/gnuplot -persist
set terminal postscript eps enhanced color solid
set output "result.ps"
set grid xtics ytics
set datafile separator ";"
set xtics rotate by 45 right
set grid xtics ytics
set xdata time
set timefmt "%d.%m.%Y"
# The equation
f(x) = a*x + b
fit f(x) "q.csv" u 1:2 via a,b
plot "q.csv" using 1:2 title "DATA" with p linestyle 3 lt 7 lw 2, \
f(x) w l lt 1 lw 2 title "trendline"
Here is the part that makes linear extrapolation described in many places. For example, here. And as if logic dictates that it should work, but does not work ...
# The equation
f(x) = a*x + b
fit f(x) "q.csv" u 1:2 via a,b
What am I doing wrong?
I tested it. Tried what is given there, it didn't help me. This is how I did it.
# find out the StartDate
StartDate = "1.12.2010" # manually by setting a value
f(x) = a*(x-StartDate) + b
set fit brief nolog
b=10
fit f(x) "q.csv" u 1:2 via a,b
set key top left
set format x "%d.%m.%Y" timedate
plot "q.csv" u 1:2 ti "Data" with linespoints linestyle 1 pt 7 ps 1, \
f(x) w l lc rgb "red" ti "Fit"