function logistic ( )

%*****************************************************************************80
%
%% LOGISTIC looks at data related to a logistic function, with some outliers.
%
%  Discussion:
%
%    The data is two-dimensional, (X,Y) pairs.  The data is roughly a
%    logistic curve, with random perturbation:
%      y = 1/(1+exp(-1.5*x)) + 0.1 * random
%
%    Most of the data clusters along a recognizable curving shape,
%    but several values seem to be significantly far away.
%
%    We can spot these outliers by using a moving average, which
%    compares each Y value to an average value computed from the
%    nearby values.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    23 April 2018
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'LOGISTIC:\n' );
  fprintf ( 1, '  MATLAB version\n' );
  fprintf ( 1, '  Set up data by sampling a logistic function, but\n' );
  fprintf ( 1, '  adding random noise.  Perturb several values.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Because these perturbations are not extreme,\n' );
  fprintf ( 1, '  a simple outlier test will not work.\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  However, MATLAB offers a moving average, which compares\n' );
  fprintf ( 1, '  each Y data value to a local average.\n' );
%
%  Generate the data.
%
  x = - 5.0 + 10.0 * rand ( 1, 100 );
  x = sort ( x );
  y1 = 1 ./ ( 1.0 + exp ( -1.5 * x ) );
  y2 = y1 - 0.2 + 0.4 * rand ( 1, 100 );
  y2(25) = 0.6;
  y2(90) = 0.1;
%
%  Apply a moving-average outlier analysis to the Y data.
%
  check = isoutlier ( y2, 'movmedian', 10 );
  bad_index = find ( check );
%
%  Plot the data.
%
  clf
  hold on
  plot ( x, y1, '-k' );
  plot ( x, y2, 'b.', 'Markersize', 10 );
  plot ( x(bad_index), y2(bad_index), 'ro', 'Markersize', 25 );
  grid ( 'on' )
  xlabel ( '<-- X -->', 'FontSize', 16 )
  ylabel ( '<-- Y(X) -->', 'FontSize', 16 )
  title ( 'Y = 1/(1+exp(-1.5*x)+noise ', 'FontSize', 20 )
  hold off
%
%  Add the least squares line through the data.
%
  filename = 'logistic.png';
  print ( '-dpng', filename )
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'LOGISTIC:\n' );
  fprintf ( 1, '  Normal end of execution.\n' );

  return
end
