I get the following results when I run the following regression on datass
:
datass = {{0, 1}, {1, 0}, {3, 2}, {5, 4}, {1, 4}};
testsOls = LinearModelFit[datass, x, x];
FittedModel[1.2 + 0.5x]
testsOls["FitResiduals"]
{-0.2, -1.7, -0.7, 0.3, 2.3}
However, when I run LinearModelFit
in sublists like the following, I get a different type of result:
datas = {{{0, 1}, {1, 0}, {3, 2}, {5, 4}, {1, 4}},
{{3, 4}, {5, 6}, {9, 9}, {8, 6}, {5, 5}}};
testOls = LinearModelFit[#, x, x] & @@@ datas
{FittedModel[-1. + 1.x], FittedModel[2. + 1.x]}
Through[testOls["FitResiduals"]]
{{2.22045*10^-16, -2.22045*10^-16}, {-8.88178*10^-16, 0.}}
I ran Clear["Global*']
many times and even exited Mathematica before reopening and rerunning both experiments.
Why do I
- Get different FittedModels for the same data (
datass = datas[[1]]
) and - The
Dimensions
of myFitResiduals
in the second experiment is[2,2]
as opposed to[2,5]
?
Map (/@)
, that is,testOls = LinearModelFit[#, x, x] & /@ datas
, (notApply (@@@)
). $\endgroup$f@@@datas = {f[{0, 1}, {1, 0}, {3, 2}, {5, 4}, {1, 4}], f[{3, 4}, {5, 6}, {9, 9}, {8, 6}, {5, 5}]}
? $\endgroup$