Site icon R-bloggers

Assessing the Accuracy of our models (R Squared, Adjusted R Squared, RMSE, MAE, AIC)

[This article was first published on R tutorial for Spatial Statistics, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Assessing the accuracy of our model

There are several ways to check the accuracy of our models, some are printed directly in R within the summary output, others are just as easy to calculate with specific functions.< o:p>


R-Squared

This is probably the most commonly used statistics and allows us to understand the percentage of variance in the target variable explained by the model. It can be computed as a ratio of the regression sum of squares and the total sum of squares. This is one of the standard measures of accuracy that R prints out through the function summary for linear models and ANOVAs.< o:p>


Adjusted R-Squared

This is a form of R-squared that is adjusted for the number of terms in the model. It can be computed as follows:< o:p>

Where R2 is the R-squared of the model, n is the sample size and p is the number of terms (or predictors) in the model. This index is extremely useful to determine possible overfitting in the model. This happens particularly when the sample size is small, in such cases if we fill the model with predictors we may end up increasing the R-squared simply because the model starts adapting to the noise in the data and not properly describing the data. 


Root Mean Squared Deviation or Root Mean Squared Error

The previous indexes measure the amount of variance in the target variable that can be explained by our model. This is a good indication but in some cases we are more interested in quantifying the error in the same measuring unit of the variable. In such cases we need to compute indexes that average the residuals of the model. The problem is the residuals are both positive and negative and their distribution should be fairly symmetrical. This means that their average will always be zero. So we need to find other indexes to quantify the average residuals, for example by averaging the squared residuals:< o:p>

This is the square root of the mean the squared residuals, with < !--[if gte msEquation 12]>< m:oMath>< m:sSub>< m:sSubPr>< m:ctrlPr>< m:e>< m:acc>< m:accPr>< m:ctrlPr>< m:e>< m:r>y< m:sub>< m:r>t< ![endif]-->< !--[if !msEquation]-->< v:shapetype coordsize="21600,21600" filled="f" id="_x0000_t75" o:preferrelative="t" o:spt="75" path="m@4@5l@4@11@9@11@9@5xe" stroked="f"> < v:stroke joinstyle="miter"> < v:formulas> < v:f eqn="if lineDrawn pixelLineWidth 0"> < v:f eqn="sum @0 1 0"> < v:f eqn="sum 0 0 @1"> < v:f eqn="prod @2 1 2"> < v:f eqn="prod @3 21600 pixelWidth"> < v:f eqn="prod @3 21600 pixelHeight"> < v:f eqn="sum @0 0 1"> < v:f eqn="prod @6 1 2"> < v:f eqn="prod @7 21600 pixelWidth"> < v:f eqn="sum @8 21600 0"> < v:f eqn="prod @7 21600 pixelHeight"> < v:f eqn="sum @10 21600 0"> < v:path gradientshapeok="t" o:connecttype="rect" o:extrusionok="f"> < o:lock aspectratio="t" v:ext="edit">< v:shape id="_x0000_i1025" style="height: 14.25pt; width: 9.75pt;" type="#_x0000_t75"> < v:imagedata chromakey="white" o:title="" src="file:///C:/Users/00754140/AppData/Local/Temp/msohtmlclip1/01/clip_image001.png">< !--[endif]--> being the estimated value at point t, < !--[if gte msEquation 12]>< m:oMath>< m:sSub>< m:sSubPr>< m:ctrlPr>< m:e>< m:r>y< m:sub>< m:r>t< ![endif]-->< !--[if !msEquation]-->< v:shape id="_x0000_i1025" style="height: 14.25pt; width: 9.75pt;" type="#_x0000_t75"> < v:imagedata chromakey="white" o:title="" src="file:///C:/Users/00754140/AppData/Local/Temp/msohtmlclip1/01/clip_image002.png">< !--[endif]--> being the observed value in t and < !--[if gte msEquation 12]>< m:oMath>< m:r>n< ![endif]-->< !--[if !msEquation]-->< v:shape id="_x0000_i1025" style="height: 14.25pt; width: 6.75pt;" type="#_x0000_t75"> < v:imagedata chromakey="white" o:title="" src="file:///C:/Users/00754140/AppData/Local/Temp/msohtmlclip1/01/clip_image003.png">< !--[endif]--> being the sample size. The RMSE has the same measuring unit of the variable y.< o:p>


Mean Squared Deviation or Mean Squared Error

This is simply the numerator of the previous equation, but it is not used often. The issue with both the RMSE and the MSE is that since they square the residuals they tend to be more affected by large residuals. This means that even if our model explains the large majority of the variation in the data very well, with few exceptions; these exceptions will inflate the value of RMSE.



Mean Absolute Deviation or Mean Absolute Error

To solve the problem with large residuals we can use the mean absolute error, where we average the absolute value of the residuals:< o:p>
This index is more robust against large residuals. Since RMSE is still widely used, even though its problems are well known, it is always better calculate and present both in a research paper.< o:p>



Akaike Information Criterion

This index is another popular index we have used along the text to compare different models. It is very popular because it corrects the RMSE for the number of predictors in the model, thus allowing to account for overfitting. It can be simply computed as follows:< o:p>


Where again p is the number of terms in the model.< o:p>
< o:p>

To leave a comment for the author, please follow the link and comment on their blog: R tutorial for Spatial Statistics.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.