Linear regression for time series with Gnuplot
-
22-08-2019 - |
Question
I am a big fan of Gnuplot and I used it all along my studies for various projects.
Lately I wanted to use Gnuplot to chart some time series like weight loss, exercising results, gas consumptions etc.
Therefore I scale the x-axis like
set xdata time
set timefmt "%d.%m %Y"
set format x "%d.%m"
Now I want to use the fit-function to give me a linear fit. My problem is, that I cannot get that to work if the x-axis is time-related.
Solution
R is probably a better tool for this kind of problem. It is one of most popular languages for data analysis. Plotting is as simple (or simpler) as in gnu plot.
OTHER TIPS
Then change the date to a number, for example a number of days starting from the first date, make the fit, and then convert the numbers back again into dates. That way you'll have "regular" x and y data set.
Another good alternative to gnuplot is matplotlib. It's a set of Python libraries for reading, manipulating, and graphing points. They have a nice cookbook at scipy.org, and here's the entry for linear regressions.