Question: 3.16 Study the Matlab code below, provided by Paul Terrill, to calculate an approximate covariance matrix, following use of the Matlab routine fminsearch. % Code

3.16∗ Study the Matlab code below, provided by Paul Terrill, to calculate an approximate covariance matrix, following use of the Matlab routine fminsearch.

% Code to be added to ‘fminsearch.m’ in order to also

% calculate an approximate variance-covariance matrix after minimising

% minus a log-likelihood

% Code due to Paul Terrill.

%_______________________________________________________________________ xestimate=x; % Store parameter estimates vbar = (sum(v(:,1:n+1)’)/(n+1))’; % Centroid x(:)=vbar;

fvbar=eval(evalstr); % Function value at centroid for i=1:n+1;

exceed=abs(fv(i)-fvbar; % Check simplex ‘large’enough while exceed

disp(‘Note: Simplex point expanded to allow ...

for machine precision’);

v(:,i)=2*(v(:,i)-vbar)+vbar, % Double the distance x(:)=v(:,i);

fv(i)=eval(evalstr);

exceed=abs(fv(i)-fbar);

end end t=0; Q=v(:,ot)-(v(:,1))*onesn; Y=zeros(n+1,n+1); for i=1:n for j=1+i:n+1 x(:)=(v(:,i)+v(:,j))/2;

Y(i,j)=eval(evalstr); % calculate Pij end end Y+Y+flipud(rot90(Y))+diag(fv); % Y is symmetric

% See Hunt et al (2006, p.75)

B=zeros(n,n);

for i=1:n for j=1:n B(i,j}=4*(Y(i+1,j+1)+Y(1,1)-Y(1,i+1)-Y(1,j+1));

end end vc=Q*inv(B)*Q’; % variance-covariance matrix x=xestimate; % parameter estimates

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Probability And Stochastic Modeling Questions!