Lindo Systems

MODEL:
SETS:  ! Computing probabilities using Bayes rule;
 ACTUAL/1..3/: MPA;  ! Marginal probability of actual;
 FCAST/1..3/ : MPF;  ! Marginal probability of forecast;
 FXA( FCAST, ACTUAL):
         CAGF, !Conditional prob of actual given forecast;
         CFGA, !Conditional prob of forecast given actual;
           JP;  ! Joint probability of both;
ENDSETS
DATA:
      ! Conditional probability of forecast, given actual;
  CFGA = .80  .15  .20
         .10  .70  .20
         .10  .15  .60;
 ! Marginal probabilities of actual;
  MPA  = .5 .3 .2;
ENDDATA

  ! The calculations;
   !Marginal probabilities are sum of joint probabilities;
 @FOR( ACTUAL( J):
  MPA( J) = @SUM( FCAST( I): JP( I, J));
     );
 @FOR( FCAST( I):
  MPF( I) = @SUM( ACTUAL( J): JP( I, J));
     );

  !Bayes rule relating joint to conditional probabilities;
 @FOR(FXA( I, J):
    JP( I, J) = MPF( I) * CAGF( I, J);
    JP( I, J) = MPA( J) * CFGA( I, J); );
END