Chapter 5: temperature from multiple thermometers
Chapter 5: temperature from multiple thermometers
%LOAD (un-comment and run one of the following two lines)
%clear; load multitemp1.mat
%clear; load multitemp2.mat
N=size(D,1);
%normal likelihood function
Ln=@(Dbar,SDbar,Nd) -(Nd+1)*log(Slist)-(Nd/2)*(((Dbar-Mlist)./Slist).^2+(SDbar./Slist).^2);
%Analysis loop & plotting
L2=zeros(1401,201); L=zeros(1401,1); figure; hold on
for s=1:size(D,2),
%for n=1:size(D,1), tmp=-2*log(Slist)-.5*((D(n,s)-Mlist).^2./Slist.^2); end;
tmp=Ln(mean(D(:,s)),std(D(:,s)),N);
L2=L2+tmp;
LS=logsum(tmp,2,diff(Slist(1,1:2))); L=L+LS;
plot(Mlist(:,1),exp(LS-max(LS)),'k-','LineWidth',4); end %plot marginal likelihoods
axis([95 105 0 1]); box off
%plot the posteriors
figure; hold on
plot(Mlist(:,1),exp(L-max(L)),'k-','LineWidth',4); axis([95 105 0 1]); box off %combine correctly
%combine across Ss (supersource)
LS=logsum(L2,2,diff(Slist(1,1:2)));
plot(Mlist(:,1),exp(LS-max(LS)),'--','Color',[.2 .4 .7],'LineWidth',4)