# Calculate 25 Statistical metrics using R Studio

## Calculate 25 Statistical metrics using R Studio

Regression analysis is a powerful statistical technique to model the relationship between variables. When working with regression models, it is essential to assess their performance using statistical metrics such as Mean Absolute Error (MAE), Mean Squared Error (MSE), and Root Mean Squared Error (RMSE) etc. These performance metrics help us evaluate the accuracy and effectiveness of the model’s predictions.
The statistical metrics (MAE, ME, RMSE, MSE, NRMSE, PBIAS, NSE, KGE, r, r², ...) are used to evaluate models by summarizing the differences between the actual (observed) and predicted values.
This tutorial explains how to compute 25 statistical metrics using RStudio. In the following, I’ll show you how to calculate 25 statistical metrics, how to build data frame (df) and how to export df to .csv file.
The use of this article and the video (link below) is highly recommended for mastering the Course.

### Statistical Metrics most used

How to Calculate Mean Absolute Error (MAE)in r?
How to Calculate Mean Error(ME)in r?
How to Calculate Root Mean Square Error (RMSE) in r?
How to Calculate Mean Squared Error (MSE) in r?
How to Calculate Normalized root mean square error (NRMSE) in r?
How to Calculate Percent Bias (PBIAS) in r?
How to Calculate Nash-Sutcliffe efficiency (NSE) in r?
How to Calculate Kling-Gupta Efficiency (KGE) in r?
How to Calculate Correlation coefficient (r) in r?
How to Calculate the coefficient of determination (R²) in r?

### Run the packages already installed

library(openxlsx)
library(zoo)
library(hydroGOF)

### Open data from excel file

sheet = "Data",
startRow = 1,
colNames = TRUE,
detectDates = TRUE)

### Calculate 25 Statistical Mrtrics

Metrics <- gof(sim = df\$Predicted, obs=df\$Observed)
Metrics

### Build data frame

Convert Matrix to data frame
MatToDf=as.data.frame(Metrics)
df <- cbind(Row.Names = rownames(MatToDf), MatToDf)
df
Remove row names
rownames(df) <- NULL
Change cols names
names(df) = c("Metrics", "Value")

### Write df to csv file

write.csv(df, "D:/RStudio/Metrics/Metrics.csv", row.names=FALSE)