Weighted Least Squares Calculator

JJ Ben-Joseph headshot JJ Ben-Joseph

Provide matching lists of x, y, and weight values to compute the weighted fit.

Why Weighted Regression?

In ordinary least squares, each observation influences the fitted line equally. Weighted least squares (WLS) lets you prioritize points according to their reliability. Suppose you measure pairs x i , y i with positive weights w i . The objective is to minimize the weighted sum of squared residuals S = i = 1 n w i y i a x i b 2 where a is the slope and b the intercept.

Deriving the Formulas

Setting the partial derivatives of S with respect to a and b equal to zero yields the normal equations. Solving the linear system produces a = W i = 1 n w i x i y i i = 1 n w i x i i = 1 n w i y i W i = 1 n w i x i 2 i = 1 n w i x i and b = i = 1 n w i y i a i = 1 n w i x i W where W denotes the total weight.

Example Dataset

The table below uses four observations with weights that downplay the final two measurements. Enter the numbers into the calculator to verify that the weighted line matches the summary values.

x y Weight
1 2.1 1.0
2 3.9 1.0
3 6.2 0.5
4 7.8 0.5

For unweighted fits, compare results with the linear regression calculator. When smoothing a time series instead of fitting a straight line, the weighted moving average calculator may be more appropriate.

Embed this calculator

Copy and paste the HTML below to add the Weighted Least Squares Calculator - Fit Data with Emphasis to your website.