n=2;
thetatrue=[1 1 2 2 0.2];
mu = [0 0];
sd = [1 thetatrue(2*n+1); thetatrue(2*n+1) 1];
load data
X=data(:,1:n);
Y=data(:,n+1:size(data,2));
A1(:,2)=-X(:,1);
A1(:,1)=-1;
A2(:,2)=-X(:,2);
A2(:,1)=-1;
W1=(all(bsxfun(@eq,Y,[0 0]),2));
W2=1-W1;
cdfun=@(x) mvncdf( [A1*[x(1);x(3)], A2*[x(2);x(4)] ]...
,mu,[1 x(5); x(5) 1]);
options=optimset('Algorithm','interior-...
point','Display','iter','MaxIter',10000,'TolX',10^-30,'TolFun',10^-30);
alpha1=normrnd(thetatrue(1),1,1,5);
alpha2=normrnd(thetatrue(2),1,1,5);
beta1=normrnd(thetatrue(3),1,1,5);
beta2=normrnd(thetatrue(4),1,1,5);
rho=(-0.9:0.1:0.9);
CC = {alpha1,alpha2,beta1,beta2,rho};
b = cellfun(@numel,CC);
n1 = cumsum(b);
a = fullfact(b);
idx = bsxfun(@plus,a,[0, n1(1:end-1)]);
v = cat(2,CC{:});
theta0grid = v(idx);
L_nstar=zeros(size(theta0grid,1),1);
Exitflag=zeros(size(theta0grid,1),1);
for j=1:size(theta0grid,1)
theta0=theta0grid(j,:);
[theta,fval,exitflag,output]=...
fmincon(@(x) log_lik(x,cdfun,W1,W2),theta0,[],[],[],[],[-Inf; -Inf; Inf; -Inf;-0.999],[+Inf; +Inf; +Inf; +Inf; 0.999],[],options);
L_nstar(j)=-fval;
Exitflag(j)=exitflag;
end
L_nstar=max(L_nstar);