Linear and non-linear regression in gnuplot
Jump to navigation
Jump to search
You can fit a simple linear regression to a set of data quickly using gnuplot:
# Fit a linear polynomial to the data.
# These are the primary instructions for linear regression.
f(x) = a*x + b # define a linear function
fit f(x) 'test.dat' via a,b # compute the regression coefficients a,b
plot f(x), 'test.dat' # plot the line and the data
It can also apparently do non-linear fitting, but I've not tested it:
# Fit a 2nd degree polynomial to the data.
f(x) = a*x**2 + b*x + c # define a quadratic function
fit f(x) 'test.dat' via a,b,c # compute the coefficients a,b,c
plot f(x), 'test.dat' # plot the polynomial and the data
This comes from here.