# lfex2

## PURPOSE

Model the success probability of successive trials of a monkey

## SYNOPSIS

This is a script file.

## DESCRIPTION

     Model the success probability of successive trials of a monkey
     performing a task.

     The 'y' variable is a vector of 0/1, with 1 denoting success on
     the trial; 0 failure. The fitting procedure uses logistic
     regression within sliding windows (specified by the 'family','binomial'
     arguments).

     Choosing the bandwidth here is critical. The data shows `on/off' behavior,
     exhibiting periods of mainly successes, and mainly failures, respectively.
     Large values of alpha will smooth out this behavior, while small values
     will be too sensitive to random variability. Values of 0.15 to 0.2 seem
     reasonable for this example.

     AIC is based on asymptotic approximations, and seems unreliable here --
     formal model selection needs more investigation.

     Data is from Keith Purpura.

## CROSS-REFERENCE INFORMATION

This function calls:

- lfband adds confidence bands around the plot of a locfit() fit.
- lfplot Plot (for one or two dimensions) a locfit() fit.
- locfit Smoothing noisy data using Local Regression and Likelihood.

This function is called by:

## SOURCE CODE

    0001 % Model the success probability of successive trials of a monkey
    0002 % performing a task.
    0003 %
    0004 % The 'y' variable is a vector of 0/1, with 1 denoting success on
    0005 % the trial; 0 failure. The fitting procedure uses logistic
    0006 % regression within sliding windows (specified by the 'family','binomial'
    0007 % arguments).
    0008 %
    0009 % Choosing the bandwidth here is critical. The data shows `on/off' behavior,
    0010 % exhibiting periods of mainly successes, and mainly failures, respectively.
    0011 % Large values of alpha will smooth out this behavior, while small values
    0012 % will be too sensitive to random variability. Values of 0.15 to 0.2 seem
    0013 % reasonable for this example.
    0014 %
    0015 % AIC is based on asymptotic approximations, and seems unreliable here --
    0016 % formal model selection needs more investigation.
    0017 %
    0018 % Data is from Keith Purpura.
    0019
    0020 load 050527_correct.mat;
    0021 y = byTrial(1).correct';
    0022 n = length(y);
    0023 fit = locfit((1:n)',y,'family','binomial','alpha',0.15);
    0024 lfplot(fit);
    0025 title('Local Logistic Regression - Estimating Success Probability');
    0026 lfband(fit);