Extracting fit weights directly from a FittedModel object

Suppose I have the following data:

data = {{{4.05, -5.06579}, ErrorBar[0.180393]},
{{ 4.1, -4.93148}, ErrorBar[0.191881]},
{{4.15, -5.14983}, ErrorBar[0.201101]}}


and I fit it to a constant with weights that are 1/the error bar as follows:

fit = LinearModelFit[ data[[All,1]], 1, t, Weights -> 1/( Sequence@@@data[[All,2]] )^2 ]


Then I know I can recover the actual data points via fit["Data"]. Is it possible to recover the weights used in the fit? I have searched through the documentation extensively and none of the options of FittedModel seem to produce what I'm looking for (and the weights don't seem to be stored in the same way when I look at FullForm@fit).

I'd like to accomplish this because then my analysis can be independent of the data set -- I could just pass around the FittedModel output objects themselves.

• I'm confused. Since you seem to be providing the fitting function with explicit values for the weights that you calculate from data, can't you just recalculate the weights in the same way? Sep 2, 2015 at 0:48
• This is an extremely simplified example. In reality, I have many many data sets, and life would be tremendously simplified if I didn't have to keep track of which fit came from which set. That is, I'd love to generate the fits and then be able to (in principle) throw away data. Sep 2, 2015 at 0:52
• I see. Well, interesting question, and we learned something from Belisarius' answer! If you haven't seen it already, you might also be interested in the following tutorial on using Weights together with VarianceEstimatorFunction : How to | Fit Models with Measurement Errors. Sep 2, 2015 at 14:26

The weights are there, but not documented.
Please beware that the following may not work in future releases. I tested it on v9.

data = {{{4.05, -5.06579}, ErrorBar[0.180393]}, {{4.1, -4.93148}, ErrorBar[0.191881]},
{{4.15, -5.14983}, ErrorBar[0.201101]}};
w    =  1/data[[All, 2, 1]]^2;
fit  = LinearModelFit[data[[All, 1]], 1, t, Weights -> w];
fit[[2, 1]] == w

(* True *)


Note that NonlinearModelFit has a different internal structure:

nlFit = NonlinearModelFit[data[[All, 1]], 1, {t}, Weights -> w];
nlFit[[4]]
(*
Weights -> {30.7299, 27.1604, 24.727}
*)

• (+1) w = 1/(Sequence @@@ data[[All, 2]])^2 can be simplified to w = 1/data[[All, 2, 1]]^2. Sep 2, 2015 at 2:11
• Works in v10, too! Thanks! Sep 2, 2015 at 2:24
• @AlexeyPopkov Thanks. Editing :) Sep 2, 2015 at 2:41
• @belisarius There may be differences between your version and v. 10.2 that I am using. In my version, the NonlinearModelFit expression you use doesn't work. Something like NonlinearModelFit[data[[All, 1]], a, a, t, Weights -> w] will work instead. Also, in my version nlFit[[4]] returns something abstruse; the Weights can be retrieved with nlFit[[2,1]] just like in the LinearModelFit result. Sep 2, 2015 at 14:16
• @MarcoB Thanks! I don't have a Mma v10 installed to test it :( A pity Sep 2, 2015 at 19:16