JAVA: RMSE, MBE, Willmott, Correlation and Determination Coefficient Algorithm

shape
shape
shape
shape
shape
shape
shape
shape

JAVA: RMSE, MBE, Willmott, Correlation Coefficient and Determination Algorithm

public class Estatistica {
    
    
    public String getStats (double valorObs[], double valorEst[], int n){
    double somaQuadrados = 0;
    double somaTotalObs = 0;
    double somaTotalEst = 0;
    double estMenosMediaObs = 0;
    double obsMenosMediaObs = 0;
    double somaQuadradoEstMenosMediaObsMaisObsMenosMediaObs = 0;
    double somaEstMenosObs = 0;
    double somatorioUm = 0; // (Leiest - Med Leiest) x (Leiobs - Med Leiobs)
    double somatorioDois = 0; // (Leiest - Media Leiest)^2
    double somatorioTres = 0; // (Leiobs - Media Leiobs)^2
    
    for(int i = 0; i<n; i++){
    somaTotalObs += valorObs[i];
    somaTotalEst += valorEst[i];
    }
    double mediaObs = somaTotalObs/n;
    double mediaEst = somaTotalEst/n;
     
    for(int i = 0; i<n; i++){
    somaQuadrados += Math.pow((valorObs[i] - valorEst[i]), 2);
    estMenosMediaObs = Math.abs(valorEst[i] - mediaObs);
    obsMenosMediaObs = Math.abs(valorObs[i] - mediaObs);
    somaQuadradoEstMenosMediaObsMaisObsMenosMediaObs += Math.pow((estMenosMediaObs + obsMenosMediaObs), 2);
    somaEstMenosObs += valorEst[i] - valorObs[i];
    somatorioUm += (valorEst[i] - mediaEst) * (valorObs[i] - mediaObs);
    somatorioDois += Math.pow((valorEst[i] - mediaEst), 2);
    somatorioTres += Math.pow((valorObs[i] - mediaObs), 2);
    }
    
    double rmse = Math.pow((somaQuadrados/n), 0.5);   //root mean square error (RMSE)
    double d = 1-(somaQuadrados/somaQuadradoEstMenosMediaObsMaisObsMenosMediaObs);   // Concordancia de Willmott (d)
    double mbe = somaEstMenosObs/n;  // mean bias error (MBE)
    double r = somatorioUm/(Math.pow((somatorioDois*somatorioTres), 0.5));  // Coeficiente de correlação (r)
    double r2 = r*r;    // Coeficiente de determinação (R²)

    String stats = "RMSE;" + rmse + ";Concordancia de Willmott (d);" + d + ";MBE;" + mbe + ";Correlacao (r);" +
            r +";Determinacao (R2);" + r2;
    return stats; 
    }
    
 
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Latest news

Latest news directly from our blog.