5 views (last 30 days)
Basically I need to ensure for all rows in the variable t1, that they are resampled in the same way.
That means that if the first draw is observation 2, then for all t1, I need observation 2 to be the first draw. This continues, such that I will have b resamples that resamples so that the samples are reordered, but for all t1 they has to be re-ordered the same way. By using rng I achieve this. I also need the variable "carhartt" to follow the same procedure.
However, I am questioning whether there is a better method for doing this? It is very important that i resample all t1 in the same way.
It is also important that each bootstrap/datasample is random.
Do any of you experts have a better solution, or do you approve of the one I use here?
I am trying to bootstrap/resample the best appropriate way:
nans = any(isnan(t1),1);
for i =1:size(t1,2)
Guillaume on 14 Mar 2020
In the following, I'm assuming that residuals and carhartt are both matrices. It looks like they are from your code. If not the code should be slightly different but the principle still stands.
However, I find it a bit strange that you're drawing K rows with replacement from a matrix with K rows. I would have expected the 2 K to be different.
Anyway, instead of drawing the samples directly, draw their row indices. You can then use the indices for both matrices:
samplerows = datasample(1:size(residuals, 1), size(residuals, 1));
%or without any need of the stat toolbox:
%sampleindices = randi(size(residuals, 1), size(residuals, 1)); %1st size is the size of the input, 2nd size is the number of samples
bootresiduals = residuals(samplerows, :);
bootcarhart = carhartt(samplerows, :);