function value = r8vec_rsquared ( n, y_data, y_model )

%*****************************************************************************80
%
%% R8VEC_RSQUARED computes the R^2 goodness of fit measurement.
%
%  Discussion:
%
%    We suppose a set of N data values Y_DATA are known, and that a
%    formula or model has generated a corresponding set of Y_MODEL values.
%
%    R^2 measures the extent to which the variation in Y_DATA is captured
%    by the model data Y_MODEL.  If the model is linear, then a value
%    of R^2=1 is optimal, and R^2=0 is the worst possible.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    14 January 2019
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer N, the number of values.
%
%    Input, real Y_DATA(N), Y_MODEL(N), the data and model values.
%
%    Output, real R8VEC_RSQUARED, the R^2 value.
%
  y_average = sum ( y_data(1:n) ) / n;

  top = sum ( ( y_data(1:n) - y_model(1:n) ) .^ 2 );
  bot = sum ( ( y_data(1:n) - y_average ) .^ 2 );

  value = 1.0 - top / bot;

  return
end