randomly sampling with replacement from a sample.

1 Ansicht (letzte 30 Tage)
Paraic Hickey
Paraic Hickey am 3 Apr. 2014
Beantwortet: Jos (10584) am 4 Apr. 2014
Hi,
I am simulating traffic data on a highway bridge.
I want to generate 1000 trucks a day for a total of 2500 days and find the max for each day.
This means sampling with replacement 1000 trucks from the 113,000 in the data 2500 times and finding the max each time.
As far as I am aware I cannot change the size of a bootstrap sample so I have being trying to use datasample.
The code I have tried is:
myStatistic=@max
nreps=2500
y=datasample(data,1000);
for i=1:nreps; populationStat(i)=myStatistic(data(;,i));
This does not work. What code or method should I be using.
Thanks in advance
  2 Kommentare
Jan
Jan am 4 Apr. 2014
"Does not work" is not useful to explain a problem. What happens? Do you get an error message or do the results differ from your expectations?
Paraic Hickey
Paraic Hickey am 4 Apr. 2014
I got an error message : index exceeds the matrix size. I think I have it working now though. Thanks for your help

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

dpb
dpb am 3 Apr. 2014
...sampling with replacement 1000 trucks from the 113,000 in the data...
y=truckdata(randi(113000,1000,1));
  2 Kommentare
Paraic Hickey
Paraic Hickey am 3 Apr. 2014
Thanks
how do I loop this to create 2500 samples of 1000 and find the max of each sample set?
Joseph Cheng
Joseph Cheng am 3 Apr. 2014
probably reading up on randi. reading the documentation on randi will give you an idea that you can go randi(maxpossiblenumber,2500,1000). then use max(answer,[],2) to get the max of each row.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Jos (10584)
Jos (10584) am 4 Apr. 2014
You can use BOOTSTRP. An example:
% data
Data = 1:20 ; % 113,000 values in your data
Nreps = 5 % 2500 in your case
Nselected = 3 % 1000 in your case
FH = @(X) max(X(1:Nselected)) ; % statistics function, max of first values
% engine
popStat = bootstrp(Nreps, FH, Data)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by