Skip to content

Instantly share code, notes, and snippets.

@mutolisp
Created March 17, 2010 12:51
Show Gist options
  • Save mutolisp/335189 to your computer and use it in GitHub Desktop.
Save mutolisp/335189 to your computer and use it in GitHub Desktop.
% mybootstrap function
% psilotum 2010/03/13
% for GNU Octave
%% obj is the object, n is the final number
% and i is the bootstrapping repeat time
function[bootstrp] = mybootstrap(obj,n,i)
if columns(obj)==1
% create i by n random numbers
rseed=ceil(n*rand(n,i));
bootstrp=obj(rseed);
else
% Original method to create a n by i*2 matrix (obsoleted)
% bootstrp=[];
% for k=1:i
% rseed=ceil(n*rand(1,n));
% bootstrp=[bootstrp, obj(rseed,:)];
% end
%% Grouped bootstrapping
% This will create a grouped multidimensional matrix
bootstrp=[];
for j=1:i
rseed=ceil(n*rand(1,n)) ;
for k=1:columns(obj)
% Create a kth column boostrapped matrix
objbst=obj(rseed,k);
% Append all of the columns into a single
% multidimensional matrix
objbst_append(:,:,k)=objbst;
end
bootstrp=[bootstrp, objbst_append];
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment