* SAS Programs for signal detection examples;
* from DeCarlo, L. T. (1998). Signal detection theory and
  generalized linear models, Psychological Methods, 3, 186-205;
options ls=80; options formdlim='-';
title"Example 2a from Macmillan & Creelman, 1991, p.31";
* Note - the events/trials syntax is used for the response.
  See the SAS/STATS User's guide for details;
data temp;
  input cond $ hypno signal pyes trials;
  sighypno=signal*hypno;
  cards;
    normal 0 0 31 100
    normal 0 1 69 100
    hypnot 1 0 59 100
    hypnot 1 1 89 100
  ;
title2"Fit of the saturated model with normal as reference";
proc logistic data=temp;
  model pyes/trials=hypno signal sighypno;
run;
title2"Reduced model with d equal across the two conditions";
proc logistic data=temp;
  model pyes/trials=hypno signal / scale=none;
run;
title2"An example of PROC PROBIT";
proc probit data=temp;
  model pyes/trials=hypno signal/d=logistic lackfit;
run;
title2"An example of PROC GENMOD and contrast statements";
* Note - the model is fit without an intercept, and the
  coefficients give direct estimates of di and -ci;
proc genmod data=temp order=data;
  class cond;
  model pyes/trials=cond cond*signal/noint dist=bin link=logit;
  contrast'd1=d2' cond*signal 1 -1;
run;
title2"A fit of the choice theory version of the model";
* the results match those shown by Macmillan & Creelman, p.36;
data choice;
  input cnorm chypno dnorm dhypno pyes trials;
  cards;
    1 0 -1  0 31 100
    1 0  1  0 69 100
    0 1  0 -1 59 100
    0 1  0  1 89 100
  ;
proc logistic data=choice;
  model pyes/trials=cnorm chypno dnorm dhypno/noint;
run;
****************************************************************;
title"Rating expt. - Ogilvie & Creelman, J. Math. Psy, 1968";
* responses are coded 1=sure noise to 6=sure signal;
data rate;
  input stim resp freq @@;
  cards;
   0 6 15 0 5 17 0 4 40 0 3 83 0 2 29 0 1 66
   1 6 68 1 5 37 1 4 68 1 3 46 1 2 10 1 1 21
  ;
title2"Fit of the logistic model using PROC LOGISTIC";
proc logistic data=rate;
  weight freq;
  model resp=stim / aggregate scale=none;
run;
****************************************************************;
title"Intensity identification - Macmillan & Creelman, p.222";
* Note - the reference distribution corresponds to stimulus 1;
data ident;
  input stim2 stim3 stim4 resp freq @@;
  cards;
    0 0 0 1 39 0 0 0 2  7 0 0 0 3  3 0 0 0 4  1
    1 0 0 1 17 1 0 0 2 12 1 0 0 3 10 1 0 0 4 11
    0 1 0 1 11 0 1 0 2 10 0 1 0 3 12 0 1 0 4 17
    0 0 1 1  3 0 0 1 2  5 0 0 1 3  9 0 0 1 4 33
  ;
proc logistic data=ident;
  weight freq;
  model resp=stim2 stim3 stim4/link=normit;
run;
****************************************************************;
title"Obs 1, rating response, Swets, Tanner, & Birdsall 1961 ";
* responses are coded 1=sure noise to 6=sure signal;
data temp;
  input signal resp freq @@;
  cards;
    0 1 174 0 2 172 0 3 104 0 4  92 0 5  41 0 6   8
    1 1  46 1 2  57 1 3  66 1 4 101 1 5 154 1 6 173
  ;
title2"Fit of the logistic model";
proc logistic data=temp;
  weight freq;
  model resp=signal/link=logit aggregate scale=none;
run;
title2"Fit of the extreme value model";
proc logistic data=temp;
  weight freq;
  model resp=signal/link=cloglog aggregate scale=none;
run;