function r = r8vec_correlation ( n, x, y )

%*****************************************************************************80
%
%% r8vec_correlation() returns the correlation of two R8VEC's.
%
%  Discussion:
%
%    The correlation coefficient is also known as Pearson's r coefficient.
%
%    It must be the case that -1 <= r <= +1.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    11 August 2019
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer n: the dimension of the vectors.
%
%    real x(n), y(n): the vectors.
%
%  Output:
%
%    real r: the correlation coefficient.
%
  if ( n <= 1 )

    r = 0.0;

  else

    x = x(:);
    x_mean = mean ( x );
    x_std = std ( x );

    y = y(:);
    y_mean = mean ( y );
    y_std = std ( y );

    r = ( x - x_mean )' * ( y - y_mean ) / x_std / y_std / ( n - 1 );

  end

  return
end
