Chapter 5: multinomial rate measurement
n=[6 11 21 29 33]; N=61;
thetas=linspace(0,1,N); %theta list
lmat=-inf(N,N,N,N,N); %initialize likelihood matrix
Lf=@(tin) sum(n.*log(tin)); %n (data vec) is fixed
%%%%%%%%%%%%%%%%%%%%%%
%%% main comp loop %%%
for i5=1:N, imax4=findnearestN(thetas,1-thetas(i5),1);
for i4=1:imax4, imax3=findnearestN(thetas,1-sum(thetas([i5 i4])));
for i3=1:imax3, imax2=findnearestN(thetas,1-sum(thetas([i5 i4 i3])));
for i2=1:imax2, i1=findnearestN(thetas,1-sum(thetas([i5 i4 i3 i2])));
tvec=thetas([i5 i4 i3 i2 i1]);
lmat(i1,i2,i3,i4,i5)=Lf(tvec/sum(tvec)); end, end, end, end
L1=logsum(lmat,[2:5],diff(thetas(1:2))*[1 1 1 1]);
L2=logsum(lmat,[1 3:5],diff(thetas(1:2))*[1 1 1 1]);
L3=logsum(lmat,[1:2 4:5],diff(thetas(1:2))*[1 1 1 1]);
L4=logsum(lmat,[1:3 5],diff(thetas(1:2))*[1 1 1 1]);
L5=logsum(lmat,[1:4],diff(thetas(1:2))*[1 1 1 1]);
figure; subplot(2,1,1); hold on
plot(thetas,exp(L1-max(L1)),'k-','LineWidth',2);
plot(thetas,exp(L2-max(L2)),'-','Color',[0 .45 .74],'LineWidth',2);
plot(thetas,exp(L3-max(L3)),'k--','LineWidth',2);
plot(thetas,exp(L4-max(L4)),'--','Color',[0 .45 .74],'LineWidth',2);
plot(thetas,exp(L5-max(L5)),'k:','LineWidth',2);