calculating RMSE, MAE, MSE, Rsquared manually in R
To calculate RMSE (Root Mean Squared Error), MAE (Mean Absolute Error), MSE (Mean Squared Error), and Rsquared manually in R, follow these steps:
Calculate the residuals: Subtract the predicted values from the actual values to obtain the residuals.
Calculate the squared residuals: Square each residual value obtained in step 1.
Calculate the mean of the squared residuals: Sum up all the squared residuals from step 2 and divide by the total number of observations.
Calculate RMSE: Take the square root of the mean of the squared residuals obtained in step 3.
Calculate MAE: Take the mean of the absolute value of the residuals obtained in step 1.
Calculate MSE: Take the mean of the squared residuals obtained in step 2.
Calculate the sum of squares of the residuals (SSR): Sum up all the squared residuals obtained in step 2.
Calculate the total sum of squares (SST): Sum up all the squared differences between the actual values and the mean of the actual values.
Calculate Rsquared: Subtract the SSR obtained in step 7 from the SST obtained in step 8, and divide the result by the SST. Multiply the quotient by 100 to obtain the Rsquared value as a percentage.
Note: These steps assume that you have the actual values and the predicted values available in your R environment.