Lindo Systems

! Maximum Likelihood Estimation with censored data;
! Keywords: Maximum Likelihood Estimation, Censored Data,
            Statistics;
sets:
 obs: stock, leftover;
endsets
! Renard de Lac newspaper data;
data:
! Simple [mean,sd] of (stock-leftover)
  =  [101.46, 13.10];
  stock, leftover =
   110    17
    85     0
   110    18
   110    15
   110    14
   110    15
   110    10
   110     6
   100     0
   110    10
    95    10
    95     0
   100    20
   100     0
   110    11
   115    17
   115     9
   115    11
   115    17
   115     0
   115    18
   115    15
   115     0
   135     0
   150    13
   150    37;
enddata  

! Find mu and sigma that maximize the log of the
  likelihood that we would observe the above data,
  assuming the demands are Normal with mean mu 
  and standard deviation sigma.  Some of the 
  observations are "censored" in the sense that
  we do not know the exact demand, only that demand
  was at least equal to the amount of product
  we stocked(which we do know);
max =
! Cases where demand = sales = stock - leftover;
   @sum(obs(i)| leftover(i) #gt# 0: 
     -.5* @log( 2*3.1415926)- @log(sigma)
     -.5*((stock(i)- leftover(i)- mu)/sigma)^2)
! Cases where we do not know demand, only
  that demand >= sales = stock;
 + @sum(obs(i)| leftover(i) #eq# 0:
     @log(1 - @psn((stock(i)-mu)/sigma)));