Re: help on bootstrap sample
- To: mathgroup at smc.vnet.net
- Subject: [mg37383] Re: [mg37338] help on bootstrap sample
- From: "Johannes Ludsteck" <johannes.ludsteck at wiwi.uni-regensburg.de>
- Date: Sat, 26 Oct 2002 02:03:03 -0400 (EDT)
- Organization: Universitaet Regensburg
- Sender: owner-wri-mathgroup at wolfram.com
Soren, the very simple code here speeds up your procedure by a factor of about 150 for a data set of length 10000 and subsample length of 5000 (i.e. my code takes 0.06 seconds where yours takes 9.6 seconds). <<DiscreteMath`Combinatorica` SampleNoReplace[data_,n_]:= data[[Take[RandomPermutation[Length[data]],n]]] To see why it works note that a random permutation of N={1,...,Length[data]} contains every element of N at least one time. If you take the first n elements of it, you have a subsample without replacement. Best regards, Johannes Ludsteck On 24 Oct 2002 at 2:55, Søren Merser wrote: > Hi Mathematica freeks > I've made two small rutines for sampling (bootstrap statistics) > They are working , but at least 'SampleNoReplace' is rather slow > I was wondering if any of you know of a faster way to do this > Regards soren > > SampelReplace[data_List:{0, 1}, n_:1] := > Module[{}, data[[Table[Random[Integer, {1, Length@data} ], {n}]]]] > > SampelNoReplace[data_List, n_] := Module[{idx, len, res, d, hi, i}, > d = data; > res = {}; > len = hi = Length@d; > > For[i = 1, i <= n && i <= len, i++, > idx = Random[Integer, {1, hi--} ]; > AppendTo[res, d[[idx]]]; > d = Drop[d, {idx}]; > ]; > res > ] > > > <><><><><><><><><><><><> Johannes Ludsteck Economics Department University of Regensburg Universitaetsstrasse 31 93053 Regensburg Phone +49/0941/943-2741