You're right in that it's strange that WeightedData
doesn't work here, but LinearModelFit
has the Weights
options that you can use to specify the weights. This example is from the documentation of LinearModelFit
(specifically the Weights
section under Options):
LinearModelFit[Range[10]^2, x, x] // Normal
LinearModelFit[Range[10]^2, x, x, Weights -> 1/Range[10]] // Normal
Out[1]= -22. + 11. x
Out[2]= -13.5039 + 9.45526 x
As a general tip for finding these kinds of options, it's always worthwhile to browse the Options section in the documentation of a function if you think some logical functionality of a function is missing. Many option symbols have their own documentation page as well. Furthermore, some functions have hidden options that aren't shown in the documentation. You can see all of them by simply typing:
Options[LinearModelFit]
{ConfidenceLevel -> 19/20, IncludeConstantBasis -> True,
LinearOffsetFunction -> None, NominalVariables -> None,
Tolerance -> Automatic, VarianceEstimatorFunction -> Automatic,
Weights -> Automatic, WorkingPrecision -> Automatic}
WeightedData
doesn't work here, butLinearModelFit
has theWeights
options that you can use to specify the weights. See: reference.wolfram.com/language/ref/Weights.html $\endgroup$x
such as $y=a+b x+x \epsilon$ with $\epsilon \sim N(0,\sigma^2)$? Or are the weights related to the measured precision of an observation? I ask because you might consider different options depending on what defines the weights. $\endgroup$