% hw5a.m % hw5, question 1: logit model via discretization % note: calls the function stdn_cdf.m to calculate standard normal cdf load hw5.mat alpha = (-10):.1:10; beta = 0:.01:.50; K = length(alpha); L = length(beta); Posterior1 = zeros(K,L); Posterior2 = zeros(K,L); for k=1:K, for l=1:L, a = alpha(k); b = beta(l); r = stdn_cdf(a+b*x); f = prod((r.^y).*((1-r).^(1-y))); Posterior1(k,l) = f; Posterior2(k,l) = f * exp(-.5*100*(b^2)); end; end; Posterior1 = Posterior1./(sum(sum(Posterior1))); Posterior2 = Posterior2./(sum(sum(Posterior2))); % calculate marginal posteriors for beta PB1 = sum(Posterior1); PB2 = sum(Posterior2); plot(beta,[PB1' PB2'] ) % end hw5a.m