is an option for various fitting and other functions which specifies weights to associate with data elements.
Weights
is an option for various fitting and other functions which specifies weights to associate with data elements.
Details
- Weights->Automatic associates weight 1 with all data elements.
- Weights->{w1,w2,…} associates weight wi with the i
data element. - Weights->func associates weight func[xi1,xi2,…,yi] with the i
data element. - Using VarianceEstimatorFunction->(1&) and Weights->{1/Δy12,1/Δy22,…}, Δyi is treated as the known uncertainty of measurement yi and parameter standard errors are effectively computed only from the weights. »
Examples
open all close allBasic Examples (1)
Fit a model using equal weights:
LinearModelFit[Range[10] ^ 2, x, x]//NormalGive explicit weights to the data points:
LinearModelFit[Range[10] ^ 2, x, x, Weights -> 1 / Range[10]]//NormalLinearModelFit[Range[10] ^ 2, x, x, Weights -> (Sqrt[#]&)]//NormalCompute weights from the response values:
LinearModelFit[Range[10] ^ 2, x, x, Weights -> (Sqrt[#2]&)]//NormalScope (2)
Use weights in a nonlinear model:
data = {{0, 1}, {1, 0}, {3, 2}, {5, 4}};NonlinearModelFit[data, Log[a + b x ^ 2], {a, b}, x]//NormalGive explicit weights to the data points:
(nlm = NonlinearModelFit[data, Log[a + b x ^ 2], {a, b}, x, Weights -> {1, (1/2), (1/3), (1/4)}])//Normaldata = {{0, 1}, {1, 0}, {3, 2}, {5, 10}};GeneralizedLinearModelFit[data, x, x, ExponentialFamily -> "Poisson"]//NormalGeneralizedLinearModelFit[data, x, x, ExponentialFamily -> "Poisson", Weights -> {1, 2, 3, 4}]//NormalLogitModelFit[{.01, .3, .5, .7, .9}, x, x]//NormalLogitModelFit[{.01, .3, .5, .7, .9}, x, x, Weights -> (1 / Sqrt[#]&)]//NormalProbitModelFit[{.01, .3, .5, .7, .9}, x, x]//NormalProbitModelFit[{.01, .3, .5, .7, .9}, x, x, Weights -> (1 / Sqrt[#]&)]//NormalWeight by a function of multiple variables:
data = {{2.8, 1.8, 4.5}, {1.8, 2.2, 2.7}, {0.6, 4.6, 1.6}, {2.8, 4.1, 2.6}, {3., 0.1, 3.7}};LinearModelFit[data, {x, y}, {x, y}, Weights -> (Sqrt[#1 ^ 2 + #2 ^ 2]&)]//NormalLinearModelFit[data, {x, y}, {x, y}]//NormalCompute weights from the response values:
LinearModelFit[data, {x, y}, {x, y}, Weights -> (Log[#3]&)]//NormalApplications (1)
Fit a nonlinear model using measurement errors as weights:
data = {{2.8, 1.8, 4.5}, {1.8, 2.2, 2.7}, {0.6, 4.6, 0.6}, {2.8, 4.1, 2.6}, {3., 0.1, 3.7}};Δys = {.1, .15, .12, .2, .08};nlm = NonlinearModelFit[data, a x Exp[b Sin[y]], {a, b}, {x, y}, Weights -> 1 / Δys ^ 2, VarianceEstimatorFunction -> (1&)]Obtain standard errors for the parameters:
nlm["ParameterErrors"]Compare to estimates with weights not assumed to be from measurement errors:
nlm["ParameterErrors", VarianceEstimatorFunction -> Automatic]Properties & Relations (2)
Weights impact the relative importance of data points on the fitting:
LinearModelFit[Range[10], x ^ 2, x, Weights -> Range[10]]//NormalScaling by a constant does not change the parameter estimates:
LinearModelFit[Range[10], x ^ 2, x, Weights -> Range[10] / Total[Range[10]]]//NormalObtain parameter estimates from a weighted linear fitting:
data = RandomReal[10, {5, 2}];
wts = {1, 2, 3, 2, 1};LinearModelFit[data, {x, Sin[x]}, x, Weights -> wts]["BestFitParameters"]LeastSquares gives the equivalent result when weights are incorporated:
dm = DesignMatrix[data, {x, Sin[x]}, x];
resp = data[[All, -1]];
LeastSquares[Sqrt[wts]dm, Sqrt[wts]resp]Related Guides
History
Text
Wolfram Research (2008), Weights, Wolfram Language function, https://reference.wolfram.com/language/ref/Weights.html.
CMS
Wolfram Language. 2008. "Weights." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Weights.html.
APA
Wolfram Language. (2008). Weights. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Weights.html
BibTeX
@misc{reference.wolfram_2026_weights, author="Wolfram Research", title="{Weights}", year="2008", howpublished="\url{https://reference.wolfram.com/language/ref/Weights.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_weights, organization={Wolfram Research}, title={Weights}, year={2008}, url={https://reference.wolfram.com/language/ref/Weights.html}, note=[Accessed: 13-June-2026]}