function glogit(call)

% This is the machine-generated representation of a MATLAB object

% and its children.  Note that handle values may change when these

% objects are re-created. This may cause problems with some callbacks.

% The command syntax may be supported in the future, but is currently 

% incomplete and subject to change.

%

% To re-open this system, just type the name of the m-file at the MATLAB

% prompt. The M-file and its associtated MAT-file must be on your path.



if nargin==0, call='start'; end



switch call



case 'start'



load glogit                            



a = figure('Units','points', ...

	'Color',[0.8 0.8 0.8], ...

	'Colormap',mat0, ...

	'Name','Bayesian Fit of a Logistic Model', ...

	'PointerShapeCData',mat1, ...

	'Position',[296.069 153.31 306.621 246.414], ...

	'Tag','Fig2');

b = uicontrol('Parent',a, ...

	'Units','normalized', ...

	'Callback',mat2, ...

	'Position',[0.629553 0.750632 0.157895 0.0755668], ...

	'String','Load Data', ...

	'Tag','Load', ...

	'UserData',mat3);

b = uicontrol('Parent',a, ...

	'Units','normalized', ...

	'Callback','glogit(''mcmc_call'')', ...

	'Position',[0.690283 0.506299 0.202429 0.0957179], ...

	'String','Run Simulation', ...

	'Tag','Pushbutton2');

b = uicontrol('Parent',a, ...

	'Units','normalized', ...

	'BackgroundColor',[0.752941 0.752941 0.752941], ...

	'Position',[0.811742 0.637278 0.163968 0.0806047], ...

	'String',['  100';'  500';' 1000';' 5000';'10000'], ...

	'Style','popupmenu', ...

	'Tag','Iterations', ...

	'Value',3);

b = uicontrol('Parent',a, ...

	'Units','normalized', ...

	'BackgroundColor',[0.752941 0.752941 0.752941], ...

	'Position',[0.629553 0.657431 0.172065 0.0554157], ...

	'String','# of Iterations', ...

	'Style','text', ...

	'Tag','StaticText1');

b = uicontrol('Parent',a, ...

	'Units','normalized', ...

	'BackgroundColor',[0.752941 0.752941 0.752941], ...

	'Position',[0.00809717 0.198993 0.194332 0.09068], ...

	'String',['beta_0  ';'beta_1  ';'function'], ...

	'Style','popupmenu', ...

	'Tag','Parameter', ...

	'UserData',mat4, ...

	'Value',1);

b = uicontrol('Parent',a, ...

	'Units','normalized', ...

	'BackgroundColor',[0.752941 0.752941 0.752941], ...

	'Position',[0.232793 0.206549 0.210526 0.0831236], ...

	'String',['histogram ';'trace plot';'dist. fun.'], ...

	'Style','popupmenu', ...

	'Tag','Graph_type', ...

	'Value',1);

b = uicontrol('Parent',a, ...

	'Units','normalized', ...

	'BackgroundColor',[0.752941 0.752941 0.752941], ...

	'Position',[0.00809717 0.309824 0.200405 0.0528968], ...

	'String','Parameter', ...

	'Style','text', ...

	'Tag','StaticText2');

b = uicontrol('Parent',a, ...

	'Units','normalized', ...

	'BackgroundColor',[0.752941 0.752941 0.752941], ...

	'Position',[0.228745 0.307305 0.216599 0.0579347], ...

	'String','Type of Graph', ...

	'Style','text', ...

	'Tag','StaticText3');

b = uicontrol('Parent',a, ...

	'Units','normalized', ...

	'Callback','glogit(''mcmc_graph'')', ...

	'Position',[0.461538 0.234257 0.091093 0.0654911], ...

	'String','Plot', ...

	'Tag','Pushbutton1');

b = axes('Parent',a, ...

	'Box','on', ...

	'CameraUpVector',[0 1 0], ...

	'CameraUpVectorMode','manual', ...

	'Color',[1 1 1], ...

	'ColorOrder',mat5, ...

	'Position',[0.0809717 0.496222 0.530365 0.435767], ...

	'Tag','Axes1', ...

	'XColor',[0 0 0], ...

	'YColor',[0 0 0], ...

	'ZColor',[0 0 0]);

c = text('Parent',b, ...

	'Color',[0 0 0], ...

	'HandleVisibility','callback', ...

	'HorizontalAlignment','center', ...

	'Position',[0.5 1.05523 0], ...

	'Tag','Text1', ...

	'VerticalAlignment','bottom');

set(get(c,'Parent'),'Title',c);

c = text('Parent',b, ...

	'Color',[0 0 0], ...

	'HandleVisibility','callback', ...

	'HorizontalAlignment','center', ...

	'Position',[0.5 -0.15407 0], ...

	'Tag','Text2', ...

	'VerticalAlignment','cap');

set(get(c,'Parent'),'XLabel',c);

c = text('Parent',b, ...

	'Color',[0 0 0], ...

	'HandleVisibility','callback', ...

	'HorizontalAlignment','center', ...

	'Position',[-0.132184 0.502907 0], ...

	'Rotation',90, ...

	'Tag','Text3', ...

	'VerticalAlignment','baseline');

set(get(c,'Parent'),'YLabel',c);

c = text('Parent',b, ...

	'Color',[0 0 0], ...

	'HandleVisibility','callback', ...

	'HorizontalAlignment','right', ...

	'Position',[-0.151341 1.15988 0], ...

	'Tag','Text4', ...

	'Visible','off');

set(get(c,'Parent'),'ZLabel',c);

b = uicontrol('Parent',a, ...

	'Units','normalized', ...

	'BackgroundColor',[0.752941 0.752941 0.752941], ...

	'HorizontalAlignment','left', ...

	'Position',[0.587045 0.0176323 0.394735 0.27204], ...

	'Style','text', ...

	'Tag','summ');

b = uicontrol('Parent',a, ...

	'Units','normalized', ...

	'Callback','glogit(''mcmc_summ'')', ...

	'Position',[0.718624 0.297229 0.165992 0.0806047], ...

	'String','Summarize', ...

	'Tag','Pushbutton3');

b = uicontrol('Parent',a, ...

	'Units','normalized', ...

	'BackgroundColor',[1 1 1], ...

	'HorizontalAlignment','left', ...

	'Position',[0.0384615 0.0125945 0.404859 0.100756], ...

	'Style','edit', ...

	'Tag','func_def');

b = uicontrol('Parent',a, ...

	'Units','normalized', ...

	'Position',[0.12753 0.120907 0.226721 0.0478589], ...

	'String','Function definition', ...

	'Style','text', ...

	'Tag','StaticText4');

b = uicontrol('Parent',a, ...

	'Units','normalized', ...

	'BackgroundColor',[0.752941 0.752941 0.752941], ...

	'Position',[0.218624 0.209068 0.342107 0.171285], ...

	'Style','frame', ...

	'Tag','Frame1');

b = uicontrol('Parent',a, ...

	'Units','normalized', ...

	'BackgroundColor',[0.752941 0.752941 0.752941], ...

	'Position',[0.811742 0.760704 0.17004 0.0629721], ...

	'Style','text', ...

	'Tag','data_name');

b = uicontrol('Parent',a, ...

	'Units','normalized', ...

	'Callback',mat6, ...

	'Position',[0.631578 0.848865 0.159919 0.0705289], ...

	'String','Load Prior', ...

	'Tag','Prior');

b = uicontrol('Parent',a, ...

	'Units','normalized', ...

	'BackgroundColor',[0.752941 0.752941 0.752941], ...

	'Position',[0.809717 0.848865 0.172065 0.0629721], ...

	'Style','text', ...

	'Tag','prior_name');



case 'mcmc_graph'



% find which beta component to plot



h=findobj('tag','Parameter');

index=get(h,'value');



% get type of graph



h=findobj('tag','Graph_type');

type=get(h,'value');



% get simulated data



h=findobj('tag','Parameter');

Mb=get(h,'userdata');



% plot



s=size(Mb,2);

if index<=s

   beta=Mb(:,index);

   stbeta=['beta_' num2str(index-1)];

else

   h=findobj('tag','func_def');

   st=get(h,'string');

   beta=eval(mcmc_st(st,s));

   stbeta='function';

end



switch type   

case 1

   hist(beta)

   title('HISTOGRAM')

case 2

   plot(beta)

   title('TRACE PLOT')

case 3

   m=size(beta,1);

   i=((1:m)-.5)/m;

   plot(sort(beta),i)

   title('EMPIRICAL CDF')

end



xlabel(stbeta)



case 'mcmc_summ'



% find which beta component to summarize



h=findobj('tag','Parameter');

index=get(h,'value');



% get simulated data



h=findobj('tag','Parameter');

Mb=get(h,'userdata');

s=size(Mb,2);



% summarize



if index<=s

   beta=Mb(:,index);

   stbeta=['beta_' num2str(index-1)];

else

   h=findobj('tag','func_def');

   stbeta=get(h,'string');

   stnew=mcmc_st(stbeta,s);

   beta=eval(stnew);

end

   

mn=mean(beta); st=std(beta);

m=length(beta); sbeta=sort(beta);

lo=sbeta(round(.05*m)); hi=sbeta(round(.95*m));



S=strvcat(stbeta, ...

   '------------------------------',...

   ['Mean = ' num2str(mn)],...

   ['St dev = ' num2str(st)], ...

   ['90% interval: (' num2str(lo) ',' num2str(hi) ')']);

   

h=findobj('tag','summ');

set(h,'string',S);

  



case 'mcmc_call'



h=findobj('tag','Load');

CurrentData=get(h,'userdata');



h=findobj('tag','Prior');

Prior=get(h,'userdata');



h=findobj('tag','Iterations');

v=get(h,'value'); st=get(h,'string');

m=eval(st(v,:));



h=findobj('tag','Parameter');

p=size(CurrentData,2)-2;

st=[];

for i=1:p

   st=[st;['beta_' num2str(i-1)]];

end

st=strvcat(st,'function');

set(h,'string',st);



scale=1;

[Mb,accept]=b_logit([CurrentData;Prior],m,scale);



set(h,'userdata',Mb);



end

