# Quality of weighted least square fit

I fitted a linear regression with heteroscedescity using weighted least square method. How do I evaluate the quality of my fitting? I’m thinking by the p-value of slope/intercept. Or maybe because I minimized the cost function and that process already does the talking?

• A p-value of a slope never measures the quality of a fit, at least not in any usual sense of "quality." Could you elaborate on what you mean by "quality"? – whuber Oct 29 '17 at 19:02
• @whuber thats the question I would like to ask. How do I define the quality of the fit? – HanaKaze Oct 30 '17 at 21:11

A simple function to calculate R squared from a weighted LS fit would be

get_r2_ss <- function(y, y_pred, w) {
# Calculate R2 using the Sum of Squares method
# https://en.wikipedia.org/wiki/Coefficient_of_determination#Definitions
ss_residual = sum(w * (y - y_pred) ^ 2)
ss_total = sum(w * (y - weighted.mean(y, w)) ^ 2)
return(1 - ss_residual / ss_total)
}


but if you use a weighted lm fit you will also simply get it using

summary(lm(y~x, weights=weights))$r.squared  If you want to look at the quality of the fit taking into account the nr of parameters that were fit then you can of course also use adjusted R squared summary(lm(y~x, weights=weights))$adj.r.squared


or AIC or BIC, using

AIC(lm(y~x, weights=weights)) or BIC(lm(y~x, weights=weights))