Calculate Coefficient of determination.

        Same as the square of the Pearson correlation coefficient (r),
        and, the same as the built-in Excel function RSQ().
        Programmed according to equation (1) in
        
        Legates, D.R. and G.J. McCabe, 1999.  Evaluating the use of "goodness of fit" measures
        in hydrologic and hydroclimatic model variation.  Water Resources Research 35:233-241.

        Args:
            obsvalues: observe values array
            simvalues: simulate values array

        Examples:
            >>> obs = [2.92, 2.75, 2.01, 1.09, 2.87, 1.43, 1.96,\
                       4.00, 2.24, 29.28, 5.88, 0.86, 13.21]
            >>> sim = [2.90, 2.87, 2.85, 2.83, 3.04, 2.81, 2.85,\
                       2.78, 2.76, 13.40, 2.70, 2.09, 1.62]
            >>> MathClass.rsquare(obs, sim)  # doctest: +ELLIPSIS
            0.7528851650345053...

        Returns:
            R-square value, or raise exception

def rsquare(obsvalues,  # type: Union[numpy.ndarray, List[Union[float, int]]]
                simvalues  # type: Union[numpy.ndarray, List[Union[float, int]]]
                ):
        # type: (...) -> Union[float, numpy.ScalarType]
        """Calculate Coefficient of determination.

        Same as the square of the Pearson correlation coefficient (r),
        and, the same as the built-in Excel function RSQ().
        Programmed according to equation (1) in
        
        Legates, D.R. and G.J. McCabe, 1999.  Evaluating the use of "goodness of fit" measures
        in hydrologic and hydroclimatic model variation.  Water Resources Research 35:233-241.

        Args:
            obsvalues: observe values array
            simvalues: simulate values array

        Examples:
            >>> obs = [2.92, 2.75, 2.01, 1.09, 2.87, 1.43, 1.96,\
                       4.00, 2.24, 29.28, 5.88, 0.86, 13.21]
            >>> sim = [2.90, 2.87, 2.85, 2.83, 3.04, 2.81, 2.85,\
                       2.78, 2.76, 13.40, 2.70, 2.09, 1.62]
            >>> MathClass.rsquare(obs, sim)  # doctest: +ELLIPSIS
            0.7528851650345053...

        Returns:
            R-square value, or raise exception
        """
        if len(obsvalues) != len(simvalues):
            raise ValueError("The size of observed and simulated values must be "
                             "the same for R-square calculation!")
        if not isinstance(obsvalues, numpy.ndarray):
            obsvalues = numpy.array(obsvalues)
        if not isinstance(simvalues, numpy.ndarray):
            simvalues = numpy.array(simvalues)
        obs_avg = numpy.mean(obsvalues)
        pred_avg = numpy.mean(simvalues)
        obs_minus_avg_sq = numpy.sum((obsvalues - obs_avg) ** 2)
        pred_minus_avg_sq = numpy.sum((simvalues - pred_avg) ** 2)
        obs_pred_minus_avgs = numpy.sum((obsvalues - obs_avg) * (simvalues - pred_avg))
        # Calculate R-square
        yy = obs_minus_avg_sq ** 0.5 * pred_minus_avg_sq ** 0.5
        if MathClass.floatequal(yy, 0.):
            return 1.
        return (obs_pred_minus_avgs / yy) ** 2.