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:

  1. Calculate the residuals: Subtract the predicted values from the actual values to obtain the residuals.

  2. Calculate the squared residuals: Square each residual value obtained in step 1.

  3. Calculate the mean of the squared residuals: Sum up all the squared residuals from step 2 and divide by the total number of observations.

  4. Calculate RMSE: Take the square root of the mean of the squared residuals obtained in step 3.

  5. Calculate MAE: Take the mean of the absolute value of the residuals obtained in step 1.

  6. Calculate MSE: Take the mean of the squared residuals obtained in step 2.

  7. Calculate the sum of squares of the residuals (SSR): Sum up all the squared residuals obtained in step 2.

  8. Calculate the total sum of squares (SST): Sum up all the squared differences between the actual values and the mean of the actual values.

  9. 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.