You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: psrf.m
    path of file: ./repos/mcmcstat
    
    the code of the file until where you have to start completion: function [R,y1,y2]=psrf(chain,a,s,e)
%PSRF  Gelman-Rubin-Brooks psrf MCMC convergence diagnostic
% Gelman-Rubin-Brooks potential scale reduction factor MCMC convergence diagnostic
% Returns (length of total sequence (1-a)% interval)/
%         (average length of within sequence intervals)
% This is Brooks - Gelman modification of the original psrf
% of Gelman and Rubin.
%

    
function [R,y1,y2]=psrf(chain,a,s,e)
%PSRF  Gelman-Rubin-Brooks psrf MCMC convergence diagnostic
% Gelman-Rubin-Brooks potential scale reduction factor MCMC convergence diagnostic
% Returns (length of total sequence (1-a)% interval)/
%         (average length of within sequence intervals)
% This is Brooks - Gelman modification of the original psrf
% of Gelman and Rubin.
%
% Reference:  S. Brooks and G. Roberts, Assessing Convergence of 
%             Markov Chain Monte Carlo Algorithms,
%             Statistics and Computing 8, 319-335, 1998.
%
% Parallel chains must be given in chain{1}, chain{2}, ...
% or as 3 dimensional array: chain(nsimu,npar,nchain).

% ML, 2002
% $Revision: 1.3 $  $Date: 2003/05/07 12:22:19 $

nchain = 0;
if iscell(chain)
  nchain = length(chain);
  [nsimu,npar1] = size(chain{1});
elseif isnumeric(chain)
  [nsimu,npar1,nchain] = size(chain);
end