Good day,
In WM I made next computations:
- data generation -{{x1,y1},{x2,y3},{x3,y3},…,{xn,yn},}
-building a model by LinearModelFit and NonlinearModelFit model.
Why the RSquared value are different for these two models? NOTE:In NonLinearModelFit set model a+bx^1.
Below is the code:
(*data generation*)
data = Table[{i, 5 + 5*i + RandomReal[{-55, 55}]}, {i, 1, 50}];
(*building a model by LinearModelFit and NonLinearModelFit model*)
nolm = NonlinearModelFit[data, a + b *x^1, {a, b}, x]
lm = LinearModelFit[data, x, x]
(*Plotting points and models*)
Row[{Show[ListPlot[data, ImageSize -> Large], Plot[lm[x], {x, 1, 50}],
Frame -> True]
Show[ListPlot[data, ImageSize -> Large], Plot[nolm[x], {x, 1, 50}],
Frame -> True]}]
(* RSquared for LinearModelFit, Correlation coeficient, RSquared for \
NonLinearModelFit*)
{lm["RSquared"],
Correlation[data[[All, 1]], data[[All, 2]]],
nolm["RSquared"]}
Thank you in advance