Hello there, I have a problem concerning bootstrapping in R - especially focusing on the resampling part of it. I try to sum it up in a simplified way so that I would not confuse anybody. I have a small database consisting of 20 observations (basically numbers from 1 to 20, I mean: 1, 2, 3, 4, 5, ... 18, 19, 20). I would like to resample this database many times for the bootstrap process with the following two conditions. The resampled databases should also have 20 observations and you can select each of the previously mentioned 20 numbers with replacement. I guess it is obvious so far. Now the more difficult second condition is that one number can be selected only maximum 5 times. In order to make this clear I try to show you an example. So there can be resampled databases like the following ones: (1st database) 1,2,1,2,1,2,1,2,1,2,3,3,3,3,3,4,4,4,4,4 (4 different numbers are chosen, each selected 5 times) (2nd database) 1,8,8,6,8,8,8,2,3,4,5,6,6,6,6,7,19,1,1,1 (Two numbers - 8 and 6 - selected 5 times, number "1" selected four times, the others selected less than 4 times) My very first guess that came to my mind whilst thinking about the problem was the sample function where there are settings like replace=TRUE and prob=... where you can create a probability vector i.e. how much should be the probability of selecting a number. So I tried to calculate probabilities first. I thought the problem can basically described as a k-combination with repetitions. Unfortunately the only thing I could calculate so far is the total number of all possible selections which amounts to 137 846 527 049. Anybody knows how to implement my second "tricky" condition into one of the R functions? Are 'boot' and 'bootstrap' packages capable of managing this? I guess they are, I just couldn't figure it out yet... Thanks very much! Best regards, Laszlo Bodnar ____________________________________________________________________________________________________ Ez az e-mail és az összes hozzá tartozó csatolt melléklet titkos és/vagy jogilag, szakmailag vagy más módon védett információt tartalmazhat. Amennyiben nem Ön a levél címzettje akkor a levél tartalmának közlése, reprodukálása, másolása, vagy egyéb más úton történő terjesztése, felhasználása szigorúan tilos. Amennyiben tévedésből kapta meg ezt az üzenetet kérjük azonnal értesítse az üzenet küldőjét. Az Erste Bank Hungary Zrt. (EBH) nem vállal felelősséget az információ teljes és pontos - címzett(ek)hez történő - eljuttatásáért, valamint semmilyen késésért, kapcsolat megszakadásból eredő hibáért, vagy az információ felhasználásából vagy annak megbízhatatlanságából eredő kárért. Az üzenetek EBH-n kívüli küldője vagy címzettje tudomásul veszi és hozzájárul, hogy az üzenetekhez más banki alkalmazott is hozzáférhet az EBH folytonos munkamenetének biztosítása érdekében. This e-mail and any attached files are confidential and/...{{dropped:19}}
A simple way of sampling with replacement from 1:20, with the additional constraint that each number can be selected at most five times is> sample(rep(1:20, 5), 20)HTH, Giovanni On Tue, 2011-03-01 at 11:30 +0100, Bodnar Laszlo EB_HU wrote:> Hello there, > > I have a problem concerning bootstrapping in R - especially focusing on the resampling part of it. I try to sum it up in a simplified way so that I would not confuse anybody. > > I have a small database consisting of 20 observations (basically numbers from 1 to 20, I mean: 1, 2, 3, 4, 5, ... 18, 19, 20). > > I would like to resample this database many times for the bootstrap process with the following two conditions. The resampled databases should also have 20 observations and you can select each of the previously mentioned 20 numbers with replacement. I guess it is obvious so far. Now the more difficult second condition is that one number can be selected only maximum 5 times. In order to make this clear I try to show you an example. So there can be resampled databases like the following ones: > > (1st database) 1,2,1,2,1,2,1,2,1,2,3,3,3,3,3,4,4,4,4,4 > (4 different numbers are chosen, each selected 5 times) > > (2nd database) 1,8,8,6,8,8,8,2,3,4,5,6,6,6,6,7,19,1,1,1 > (Two numbers - 8 and 6 - selected 5 times, number "1" selected four times, the others selected less than 4 times) > > My very first guess that came to my mind whilst thinking about the problem was the sample function where there are settings like replace=TRUE and prob=... where you can create a probability vector i.e. how much should be the probability of selecting a number. So I tried to calculate probabilities first. I thought the problem can basically described as a k-combination with repetitions. Unfortunately the only thing I could calculate so far is the total number of all possible selections which amounts to 137 846 527 049. > > Anybody knows how to implement my second "tricky" condition into one of the R functions? Are 'boot' and 'bootstrap' packages capable of managing this? I guess they are, I just couldn't figure it out yet... > > Thanks very much! Best regards, > Laszlo Bodnar > > ____________________________________________________________________________________________________ > Ez az e-mail ?s az ?sszes hozz? tartoz? csatolt mell?klet titkos ?s/vagy jogilag, szakmailag vagy m?s m?don v?dett inform?ci?t tartalmazhat. Amennyiben nem ?n a lev?l c?mzettje akkor a lev?l tartalm?nak k?zl?se, reproduk?l?sa, m?sol?sa, vagy egy?b m?s ?ton t?rt?n? terjeszt?se, felhaszn?l?sa szigor?an tilos. Amennyiben t?ved?sb?l kapta meg ezt az ?zenetet k?rj?k azonnal ?rtes?tse az ?zenet k?ld?j?t. Az Erste Bank Hungary Zrt. (EBH) nem v?llal felel?ss?get az inform?ci? teljes ?s pontos - c?mzett(ek)hez t?rt?n? - eljuttat?s??rt, valamint semmilyen k?s?s?rt, kapcsolat megszakad?sb?l ered? hib??rt, vagy az inform?ci? felhaszn?l?s?b?l vagy annak megb?zhatatlans?g?b?l ered? k?r?rt. > > Az ?zenetek EBH-n k?v?li k?ld?je vagy c?mzettje tudom?sul veszi ?s hozz?j?rul, hogy az ?zenetekhez m?s banki alkalmazott is hozz?f?rhet az EBH folytonos munkamenet?nek biztos?t?sa ?rdek?ben. > > > This e-mail and any attached files are confidential and/...{{dropped:19}} > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Giovanni Petris <GPetris at uark.edu> Associate Professor Department of Mathematical Sciences University of Arkansas - Fayetteville, AR 72701 Ph: (479) 575-6324, 575-8630 (fax) http://definetti.uark.edu/~gpetris/
Here are a couple of thoughts. If you want to use the boot package then the statistic function you give it just receives the bootstrapped indexes, you could test the indexes for your condition of not more than 5 of each and if it fails return an NA instead of computing the statistic. Then in your output just remove the NAs (you should increase the total number of samples tried so that you have a reasonable number after deletion). If you want to do it by hand, just use the rep function to create 5 replicates of your data, then sample from that without replacement. You can get up to 5 copies of each value (from the hand replication), but no more since it samples without replacement. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Bodnar Laszlo EB_HU > Sent: Tuesday, March 01, 2011 3:31 AM > To: 'r-help at r-project.org' > Subject: [R] bootstrap resampling question > > Hello there, > > > > I have a problem concerning bootstrapping in R - especially focusing on > the resampling part of it. I try to sum it up in a simplified way so > that I would not confuse anybody. > > > > I have a small database consisting of 20 observations (basically > numbers from 1 to 20, I mean: 1, 2, 3, 4, 5, ... 18, 19, 20). > > > > I would like to resample this database many times for the bootstrap > process with the following two conditions. The resampled databases > should also have 20 observations and you can select each of the > previously mentioned 20 numbers with replacement. I guess it is obvious > so far. Now the more difficult second condition is that one number can > be selected only maximum 5 times. In order to make this clear I try to > show you an example. So there can be resampled databases like the > following ones: > > > > (1st database) 1,2,1,2,1,2,1,2,1,2,3,3,3,3,3,4,4,4,4,4 > > (4 different numbers are chosen, each selected 5 times) > > > > (2nd database) 1,8,8,6,8,8,8,2,3,4,5,6,6,6,6,7,19,1,1,1 > > (Two numbers - 8 and 6 - selected 5 times, number "1" selected four > times, the others selected less than 4 times) > > > > My very first guess that came to my mind whilst thinking about the > problem was the sample function where there are settings like > replace=TRUE and prob=... where you can create a probability vector > i.e. how much should be the probability of selecting a number. So I > tried to calculate probabilities first. I thought the problem can > basically described as a k-combination with repetitions. Unfortunately > the only thing I could calculate so far is the total number of all > possible selections which amounts to 137 846 527 049. > > > > Anybody knows how to implement my second "tricky" condition into one of > the R functions? Are 'boot' and 'bootstrap' packages capable of > managing this? I guess they are, I just couldn't figure it out yet... > > > > Thanks very much! Best regards, > > Laszlo Bodnar > > > > _______________________________________________________________________ > _____________________________ > > Ez az e-mail ?s az ?sszes hozz? tartoz? csatolt mell?klet titkos > ?s/vagy jogilag, szakmailag vagy m?s m?don v?dett inform?ci?t > tartalmazhat. Amennyiben nem ?n a lev?l c?mzettje akkor a lev?l > tartalm?nak k?zl?se, reproduk?l?sa, m?sol?sa, vagy egy?b m?s ?ton > t?rt?n? terjeszt?se, felhaszn?l?sa szigor?an tilos. Amennyiben > t?ved?sb?l kapta meg ezt az ?zenetet k?rj?k azonnal ?rtes?tse az ?zenet > k?ld?j?t. Az Erste Bank Hungary Zrt. (EBH) nem v?llal felel?ss?get az > inform?ci? teljes ?s pontos - c?mzett(ek)hez t?rt?n? - eljuttat?s??rt, > valamint semmilyen k?s?s?rt, kapcsolat megszakad?sb?l ered? hib??rt, > vagy az inform?ci? felhaszn?l?s?b?l vagy annak megb?zhatatlans?g?b?l > ered? k?r?rt. > > > > Az ?zenetek EBH-n k?v?li k?ld?je vagy c?mzettje tudom?sul veszi ?s > hozz?j?rul, hogy az ?zenetekhez m?s banki alkalmazott is hozz?f?rhet az > EBH folytonos munkamenet?nek biztos?t?sa ?rdek?ben. > > > > > > This e-mail and any attached files are confidential > and/...{{dropped:19}}