function value = r8vec_rsquared_adjusted ( n, y_data, y_model, degree )

%*****************************************************************************80
%
%% R8VEC_RSQUARED_ADJUSTED computes the adjusted 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.
%
%    The adjusted value of R^2 accounts for the use of a polynomial model
%    of degree higher than 1.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    16 January 2019
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the number of values.
%
%    real Y_DATA(N), Y_MODEL(N), the data and model values.
%
%    integer DEGREE, the polynomial degree of the model.
%
%  Output:
%
%    real R8VEC_RSQUARED_ADJUSTED, the adjusted 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 ) * ( n - 1 ) / ( n - degree - 1 );

  return
end
