Linear fit
To perform a linear fitting, use the fitlinear function:
using EasyFit, Plots, Random
Random.seed!(1)
x = sort(rand(10))
y = sort(rand(10)) # some data
fit = fitlinear(x, y)------------------- Linear Fit -------------
Equation: y = ax + b
With: a = 0.9199953971900016 ± 0.05823241269166419
b = 0.11453461390009877 ± 0.03221807249002225
Correlation coefficient, R² = 0.9689439025845498
Average square residue = 0.002927284812053499
Predicted Y: ypred = [0.13670126868113086, 0.15977246394781555, ...]
residues = [0.021765971052432165, -0.016852623865029254, ...]
--------------------------------------------
The fit data structure which comes out of fitlinear contains the output data with the same names as shown in the above output:
fit.a, fit.sd_a(0.9199953971900016, 0.05823241269166419)fit.b, fit.sd_b(0.11453461390009877, 0.03221807249002225)fit.R20.9689439025845498The fit.x and fit.y vectors can be used for plotting the results, together with the original data:
scatter(x, y, label="data", framestyle=:box)
plot!(fit.x, fit.y, label="fit", linewidth=2)