
fn_R2RV {Morefi}
14 June 2025
fn_R2RV.Rmd
Robust version of the coefficient of determination
Description
The function calculates a robust version of the coefficient of determination using the Equation Summary values fitted with the robustbase::nlrob() function.
This is the consistency corrected robust coefficient of determination by Renaud and Victoria-Feser (2010) which allows for a possible correction factor a for consistency considerations.
Inside the function:
The vectors of observed (y1), predicted (yc) and weighted (W) values are obtained from the summary model (eq).
The value of the Weighted Estimate Average (ywea), the modified sum of squares for explained (SSEw), total (SSTw), and residual (SSRw) were estimated.
The correction factor value for consistency considerations a for 95 percent was also obtained from summary model (eq).
A vector with the robust version of the coefficient of determination R2wa and its adjusted value R2wa_adj were returned as a vector.
In the function, the following were estimated:
The Weighted Estimate Average (called as ywea).
The modified sum of squares explained SSEw The modified sum of squared residuals SSRw
The robust version of the coefficient of determination The adjusted coefficient of determination
where
,
and
are the
observed and predicted values,
is the correction factor value for consistency considerations for
95
percent,
the number of pairs of observations and
the number of variables included in the model.
The function requires defining:
- eq: Summary of the equation fitted using robustbase::nlrob() function.
The function returns the a vector with the robust version of the coefficient of determination and its adjusted value .
fn_R2RV
The function is included in the Morefi
package
Morphological Relationships Fitted by Robust
Regression.
The function is detailed below.
fn_R2RV <- function(eq){
w <- eq$rweights # w a vector of weights values
yc <- eq$fitted.values # yc a vector of predicted values
ywea <- (1/sum(w)) * sum(w*yc) # a value of the Weighted Estimate Average
y1 <- eq$model[,1]
SSEw <- sum(w*(yc-ywea)^2)
SSRw <- sum(w*(y1-yc)^2)
a <- environment(eq[["psi"]])[["cc"]]
R2wa <- SSEw/(SSEw+a*SSRw)
R2wa_adj <- 1-(1-R2wa)*((length(y1)-1)/summary(eq)$df[2])
R2was <- c(R2wa,R2wa_adj)
print(R2was)
}
References
Renaud, O., & Victoria-Feser, M. P. (2010). A robust coefficient of determination for regression. Journal of Statistical Planning and Inference, 140(7), 1852-1862. doi:10.1016/j.jspi.2010.01.008.