2
$\begingroup$

Suppose that I have a data and a statistical model that is not the result of fitting, but has a different origin. For example, I have a list of measurements and a theoretical model whose predicting accuracy I want to assess.

Is there a simple way to obtain all the properties of a FittedModel object, but from my theoretical model?

For example, suppose that

mt=Table[{i,1+i+RandomReal[]},{i,5}]

yields mt={{1,2.56508},{2,3.58291},{3,4.8005},{4,5.24265},{5,6.38087}}

If I call

LinearModelFit[mt,x,x]

I get

FittedModel[1.72701 +0.929131 x]

And I can then get R$^2$ for the adjusted model:

%["RSquared"]

which gives $0.9851$.

But I know the theoretical model is $1.5+x$. Can I have the power of a FittedModel (residuals, ANOVA, RSquared, etc.) for my non-fitted model?

$\endgroup$
1
  • $\begingroup$ If you look at FullForm[LinearModelFit[mt,x,x]] from your example above then the internal structure seems reasonably simple and understandable. What happens if you carefully build a FittedModel using that structure as an example, not by doing a fit but by substituting your theoretical model in that and then you query that constructed FittedModel for residuals, ANOVA, etc? Can you do this on test cases where you know what the calculations should show to verify that this is being done correctly? $\endgroup$
    – Bill
    Commented Dec 21, 2018 at 22:04

1 Answer 1

8
$\begingroup$

You can use NonlinearModelFit but not all output options will either be appropriate and some will require "adjustment".

All of the fitting procedures want to estimate parameters (that's what they're made for) so NonlinearModelFit can be tricked by included a parameter that isn't in the model. Here I used a parameter named a:

SeedRandom[12345];
mt = Table[{i, 1 + i + RandomReal[]}, {i, 5}]
nlm = NonlinearModelFit[mt, 1.5 + x, {a}, x]

So the following work fine with no adjustment needed:

nlm["FitResiduals"]
(* {-0.378754, -0.170078, 0.282753, -0.0698316, -0.276414} *)
nlm["PredictedResponse"]
(* {2.5, 3.5, 4.5, 5.5, 6.5} *)

The "EstimatedVariance" needs adjustment:

Mean[(mt[[All, 2]] - 1.5 - mt[[All, 1]])^2]
(* 0.0667223 *)
n = Length[mt];
nlm["EstimatedVariance"] (n - 1)/n
(* 0.0667223 *)
$\endgroup$
2
  • $\begingroup$ Nice! You get some information on the dummy model/parameter a (in the ANOVA, ParameterTable, etc.), is it possible to get such information for my coefficients (i.e., 1.5 and 1)? Or is all that kind of information just meaningless for a non-fitted model? $\endgroup$
    – Rafael
    Commented Dec 21, 2018 at 19:55
  • 2
    $\begingroup$ Yes, I'd vote for meaningless. I'd also avoid any option that starts with "Parameter..." as the residual variance is the only parameter estimated. $\endgroup$
    – JimB
    Commented Dec 21, 2018 at 20:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.