Residual Variance in Weighted Least Squares (WLS)
The residual variance is a measure of how much the observed data deviates from the predicted values of the model. In weighted least squares (WLS), it reflects the variance of the weighted residuals (i.e., residuals multiplied by the square root of the weights).
1. What is Residual Variance?
In a regression model, the residuals are the differences between the observed values yi and the predicted values y^i=mxi+b. The residual variance is the average of the squared residuals, adjusted for the weights.
-
Unweighted case (OLS):
σ^2=n−2
If the weights are correctly specified (i.e., wi=1/σi2), the residual variance should be close to 1. This is because the weights normalize the residuals to have unit variance.
2. How to Calculate Residual Variance
To compute the residual variance in your code:
-
Compute the predicted values:
y^i=mxi+
3. Can the Residual Variance Be 1?
Yes, if the weights are correctly specified (i.e., wi=1/σi2). This is because:
- The weights are chosen to normalize the errors to have unit variance.
- If the model is correctly specified, the residuals should have a variance of 1.
For example:
- Suppose the true model is yi=mxi+b+ϵ, where .
In this case, the residual variance σ^2 should be close to 1.
4. What Does It Mean to "Absorb the Residual Variance into the Weights"?
When the weights are set as wi=1/σi2, the residual variance is implicitly absorbed into the weights. This means:
- The model assumes that the errors ϵi have known variances σi2.
- The weights w are chosen to (unequal variances).
Example:
Suppose you have two data points:
- Point 1: y1=10, σ1=1 →
The weights ensure that the first point contributes more to the fit (since its error is smaller). If the model is correctly specified, the residual variance should be 1.
5. Why Would the Residual Variance Not Be 1?
If the weights are not correctly specified, the residual variance will differ from 1. For example:
- If you use wi=1 (no weighting), the residual variance will reflect the true heteroscedasticity.
- If you use incorrect weights (e.g., wi=), the residual variance will not be 1, and the uncertainty estimates () will be inaccurate.
In such cases, you should estimate the residual variance and adjust the weights accordingly (e.g., using iterative methods like iteratively reweighted least squares).
6. Implications for Your Code
In your code, the uncertainties in the slope and intercept are calculated as:
sigma_m = sqrt(S / Delta);
sigma_b = sqrt(Sxx / Delta);
This assumes that the residual variance is 1, which is valid only if the weights are correctly specified (i.e., wi=1/σi2).
If the weights are incorrect, the residual variance may not be 1, and the uncertainties σm,σb would need to be scaled by , where is the estimated residual variance.
Summary
| Question | Answer |
|---|
| What is residual variance? | A measure of the spread of residuals after fitting the model. In WLS, it is calculated as the weighted sum of squared residuals divided by degrees of freedom. |
| Can it be 1? | Yes, if the weights are correctly specified (e.g., wi=1/σi2). This implies the errors have unit variance. |
| What does it mean to absorb it into the weights? |
Let me know if you'd like to see an example of calculating residual variance in code!