Gary King Homepage Previous: Purpose: Up: EIMODELS Next: Globals:

Example:

The following example uses the sample file sample.asc that comes with $ {\mathfrak{E}I}$. Consult section 6.1 for the description of data and explanation of the commands to load the data set. The code first stores the three different model definitions in a meta data buffer using eimodels_def, and then it runs ei for each of the three models. Finally, it implements the Bayesian Model Averaging to combine the results from the three models using eimodels_avg.
new;                                     @ clear workspace @
library ei;                              @ initialize libraries @
clear t,x,n;                             @ clear all variables in dataset @
loadvars sample.asc t x n;               @ load variables from disk file @

eiset;                                   @ clear for Model 1 @
_Eres = vput(_Eres, "Model 1", "titl");  @ print out model number @
_Eeta = 1;                               @ zb=x, zw=1 @
_Ealpha_B = {0 2};                       @ prior for betaB @
_Esims = 1000;                           @ number of simulation @
dbufdef = eimodels_def("",1,t,x,n,1,1);  @ save Model 1, the first model @

eiset;                                   @ clear for Model 2 @
_Eres = vput(_Eres, "Model 2", "titl");
_Eeta = 2;                               @ zb=1, zw=x @
_Ealpha_W = {0 2};                       @ prior for betaW @
_Esims = 1000;
dbufdef = eimodels_def(dbufdef,2,t,x,n,1,1); @ save Model 2 @

eiset;                                   @ clear for Model 3 @
_Eres = vput(_Eres, "Model 3", "titl");
_Eeta = 3;                               @ zb=x, zw=x @
_Ealpha_B = {0 2};                       @ prior for betaB @
_Ealpha_W = {0 2};                       @ prior for betaW @
_Esims = 1000;
dbufdef = eimodels_def(dbufdef,3,t,x,n,1,1); @ save Model 3 @

save rvdef = dbufdef;                    @ save ndbuf in file rvdef.fmt @
dbufrun = eimodels_run(dbufdef);         @ run ei on all the models @
save rvrun = dbufrun;                    @ save ndbres in file rvrun.fmt @

_EIMetaR = 1;
call eiread(dbufrun, "sum");             @ summary of ei run for Model 1 @

_EIMetaR = 3;
graphon;
call eigraph(dbufrun, "tomog");          @ tomography plot for Model 3 @
graphoff;

_EI_bma_prior = {0.2,0.4,0.4};           @ set prior model probabilities @
dbufavg = eimodels_avg(dbufrun);         @ Bayesian Model Averaging @
save rvavg = dbufavg;                    @ save dbres in file rvavg.fmt @

graphon;
call eiread(dbufavg,"sum");              @ summary for dbres @
call eigraph(dbufavg,"post");            @ draw district level posterior @
graphoff;                                @ close graphics window @



Gary King 2006-09-13