% HW4.M % Solutions to HW4 % calls logit_mle.m and logit_weighted.m % sample results are given at the end % 03/6/06 load hw4b.dat %this is an edited version of the data, removing the header info % Logit MLE y=hw4b(:,1); w=hw4b(:,2); n = length(w); x = [ones(n,1) w]; [beta_ML,se_ML] = logit_mle(y,x); beta_ML se_ML % weighted logit n0 = sum(y==0); n1 = sum(y==1); Q0 = 1/4; Q1 = 3/4; weights = (Q0/(n0/n)).*(y==0) + (Q1/(n1/n)).*(y==1); beta_weighted = logit_weighted(y,x,weights); beta_weighted % nonparametric bootstrap B=1000; nb_draws=NaN*ones(B,2); constant_vec = ones(n,1); for b=1:B, % sample with replacement from observed data points % first calculate a random draw for integers between 1 and n: b_index = ceil( n*rand(n,1) ); % then use these integers as index of the original data x_b = [constant_vec w(b_index)]; y_b = y(b_index); % calculate MLE and record [beta_nb, se_nb] = logit_mle(y_b, x_b); nb_draws(b,:) = beta_nb'; end; % parametric bootstrap pb_draws=NaN*ones(B,2); for b=1:B, % sample with replacement from observed W data points b_index = ceil( n*rand(n,1) ); x_b = [constant_vec w(b_index)]; % generate y according to probit model based on MLE estimate xbb = x_b*beta_ML; Eyx = exp(xbb)./(1+exp(xbb)); y_b = rand(n,1)