⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jknife.m

📁 Jacknife method, very good
💻 M
字号:
function[res] = jknife(fun,x,varargin)  %#ok
% JKNIFE     Leave-one-out jackknife
% INPUTS   : fun - function computing desired statistics, with output
%                  placed in p*q array or structure
%            x   - n*k data matrix, with observations in rows
%            y.. - (optional) additional vectors/matrices, referenced 
%                  by fun, in the order they appear in fun
% OUTPUTS  : res - statistic values in full and leave-one-out samples 
%                  (Note  that all  rows of y, z, etc.  are retained; 
%                  leave-one-out  affects x only). res is a p*q*(n+1) 
%                  array if fun  outputs  a p*q array, and a  1*(n+1)
%                  structure  array if fun outputs a structure, where
%                  element 1 stores value in full sample
% EXAMPLE  : See JKNIFEDEMO 
% SEE ALSO : JSTATS, BSTRAP; JACKKNIFE, BOOTSTRP (Statistics Toolbox)
% AUTHOR   : Dimitri Shvorob, dimitri.shvorob@vanderbilt.edu, 4/15/07

if nargin < 1
   error('Input argument "fun" is undefined')
end
if nargin < 2
   error('Input argument "x" is undefined')
end
if ~ischar(fun)
   error('Input argument "fun" must be a string')
end  
if ~isnumeric(x)
   error('Input argument "x" must be numeric')
end  

n = size(x,1);
I = (1:n)';
evalString = 'resi = feval(fun,xjack';
for j = 1:(nargin - 2)
    evalString = [evalString ',varargin{' num2str(j) '}'];
end
for i = 0:n
    xjack = x(i ~= I,:);      %#ok
    try
       eval([evalString ');'])
    catch
       error('Function "fun" could not be evaluated')  
    end
    if ~i
       if isstruct(resi) 
          outputStructure = true;
          f = fieldnames(resi);
          r = length(f);
       else
          outputStructure = false; 
          res = repmat(resi,[1 1 n+1]);
       end    
    end
    if outputStructure
       for j = 1:r
           eval(['res(i+1).' f{j} ' = resi.' f{j} ';']);
       end
    else
       res(:,:,i+1) = resi;
    end
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -