Please reply on list for the archives (and so others who know more about zipfR can help):
Your immediate problem is that rlnre produces factors not integers and so there's no way to order them (and hence no idea of being "less" than 6000) -- if you want you can coerce to integer with as.integer() and then max at 6000 like I suggested. Whether this is reasonable for your problem,I don't know: I'm not particularly familiar with the zipfR package. Michael On Tue, Apr 24, 2012 at 10:46 AM, meh L <iamrutab...@gmail.com> wrote: > Hi Michael, > > I only want the random generated be within the range of 1 to 6000. So yes > 6000 is the upper bound. pmin(zmsample, 6000) is not working for me > though. I am starting to think maybe I will need to use fzm instead of zm > because zm by nature is infinite population size? > > Thanks. > >> pmin(zmsample,6500) > [1] 23 94 14 23 2 60 5 7 163266 8 > [11] 3397 13 321 68 204 3 25 2 4 8 > [21] 2 8 16 3 461 34 39 4 29 92 > [31] 20 54 13 1 273 18 1665 66 59 596 > [41] 56 8820 228 22 13 2097 17111 2 5 10 > [51] 12 9 1 5 5 37 14 10 8 2324 > [61] 2 138 18 90 7 852 16 15 16 94622 > [71] 51 239 1 23 9 7 875 10 18 14489 > [81] 2 8 1 5 5 330 4 1 26 17 > [91] 26 10 2 1 605 1 2 97 32 51 > [101] 12 2 21 55 2 6 103 510 4 5 > [111] 6 7 6 7 52 53 2 88 8 5 > [121] 22 127 3 7 1389 2 3 4 8 2 > [131] 2 1 36 21 474 12 85 2 3 3 > [141] 64 22 36 10969 9 2 1 236 42 149 > [151] 22 19 50 2 2 7 372017 6 11 39 > [161] 418 19 26 376 1 1 5 57 100 3 > [171] 25 26 8 263 6 60 3 52 41 4 > [181] 1503 2 1 41945 3 1 465 25 16 318 > [191] 109 13 375 69493 1 21 167 1 4 22 > [201] 50 1 1 7 43 10 11 2 8 7 > [211] 2 7 4 2 2294 982 45 4 67 4 > [221] 10 1 27 250539 5 104 3 1 9 1 > [231] 12 1 8 415 297 25 51 3 2 1 > [241] 8 6 7 6 17 1643 215 10 11 4 > [251] 9 1 28 73 12 47 135 51 9 162 > [261] 3 3 7 7438 3 12281 2 1 6 3 > [271] 2 722 5 25 8117 11 2 5 49 9 > [281] 49 3 94 119 1 6 1 52 7 2344 > [291] 25 13 21 8 3 14 4 42 51 29 > [301] 1490 21 10 12 6 226 38 3 2 94 > [311] 7 1085 27 28 2 999 4 1 356 6 > [321] 135 5 999 2 2 6345 9 32 2 6 > [331] 2 10 601 5 15 136 22 161852 24 2 > [341] 154 23 9 26125 3 1 177 1 32 69 > [351] 1 108 23 2 1 1 1 17 34 3 > [361] 23 222 1 43 748 1 3 5 53 2 > [371] 188 2 585 4 357 9 190 21 15 6 > [381] 32 74 9 142 25 3 4 92 54 47 > [391] 35 1 28 40 84 120 1 32 4 146598 > [401] 2562 80 751821 201 4 22 147 8 3 15 > [411] 28 63 28 4 15 14 1 15 33 6 > [421] 78 63 15 10 7 11 2 21 7 144 > [431] 2 1687 40202 10 17781 163 12 1 107 823 > [441] 11 2 6 2468 11 399 134 154 6 1 > [451] 6 2 202 213 9 556 25 4 15 30 > [461] 45 30 200 191 9 8 64 15 27 381 > [471] 1 6 6 47 341 3 19 6 2 62 > [481] 2761 196 19 49 100 7 10 40 22 5 > [491] 2040 8 68 41 17 4 44 3 2554 81 > 180 Levels: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ... > 751821 > Warning message: > In Ops.factor(mmm, each) : > not meaningful for factors > > > On Mon, Apr 23, 2012 at 8:14 PM, R. Michael Weylandt > <michael.weyla...@gmail.com> wrote: >> >> It depends how you want to ensure that condition -- if you just want >> to censor at an upper bound of 6k, this is easy: >> >> pmin(zmsample, 6000) >> >> If you want to sample "as before" but it just happens to all be less >> than 6000 -- that's not really a rigorous statement, but just go with >> it -- intuitively, you can draw more samples and just take enough that >> satisfy your condition. There are perhaps different thoughts on the >> most efficient way to do it efficiently. It's probably better, >> however, to do it using an inverse transform -- I'll work it out here >> for an easy distribution and you can adopt it to yours. >> >> # 100 samples from X ~ Exp(lambda = 2) conditioned on X <=1 [Again, >> this isn't really X ~ Exp(2) ....] >> >> maxU <- pexp(1, 2) >> rU <- runif(100, max = maxU) >> samp <- qexp(rU, 2) >> >> Michael >> >> On Mon, Apr 23, 2012 at 6:29 PM, meh L <iamrutab...@gmail.com> wrote: >> > Hi, >> > >> > I have a question on generating random variables based on >> > zipf-mandelbrot >> > distribution. >> > >> > So when I execute the following lines: >> > >> > ZM = lnre ("zm", alpha = 2/3, B=0.1) >> > zmsample = rlnre (ZM, n =100) >> > zmsample >> > >> > It generates 100 random values based on a zipf-mandelbrot distribution >> > as >> > below. But how do I make sure the generated random number is within the >> > range of 1 - 6000 only? Can I include that as one of the parameters in >> > rlnre? >> > >> > Thank you for your help! >> > >> > >> > [1] 5 9 4 396 1435 2 2 4 >> > [9] 6 11 11 5 18 8 2 >> > 13 >> > [17] 3 5 33 10 1 3 6 >> > 17 >> > [25] 2 18 44438 141 155 740009 12 >> > 2 >> > [33] 7977 17 10 68 90 25 27 >> > 2 >> > [41] 5 37 107 7330 6 119 2 >> > 102 >> > [49] 1 30 6 5 4 2 28 >> > 7 >> > [57] 6 8396 1169 66 361 2 2 >> > 665 >> > [65] 20 1825 9 25 141 7 31 >> > 56 >> > [73] 24135 20 20 29 5 13 6 >> > 7 >> > [81] 2579 4 21 1 1 12 67800 >> > 4 >> > [89] 3 154573 13 29 1 11 48 >> > 120 >> > [97] 550 13 15 305 41 1 133 >> > 178 >> > [105] 24 476 6 12 1 16 27 >> > 22 >> > [113] 20 19 17 75 14 1137 3 >> > 36 >> > [121] 7 9 14 14 1 19 257 >> > 69 >> > [129] 230 7 1 84 9 11 2 >> > 82 >> > [137] 343 193 4 2 47 817 40 >> > 4 >> > [145] 37 10 4 39 15 3 97 >> > 69 >> > [153] 186 5 52 36 9 9 119 >> > 310 >> > [161] 5 777 4 1 2212 1456 38 >> > 11 >> > [169] 8 6 20 46 362 1407 5 >> > 10 >> > [177] 5940 16822 3 4 5737 59 13 >> > 329 >> > [185] 96 379 55 86 16 568 9 >> > 23 >> > [193] 3 4 188 20 1 2 292 >> > 7 >> > [201] 9 2 17 10465 3 1 15 >> > 1040 >> > [209] 350 72 5 2 7 11 57 >> > 16 >> > [217] 18 6666278 31 17 80 11 5 >> > 211 >> > [225] 3 2 137 7 5 160 4 >> > 47 >> > [233] 6 23 104 13 83 62 12 >> > 178 >> > [241] 2 16 4 6 1 15 7 >> > 5 >> > [249] 2 6 26 241 5 5 2 >> > 1 >> > [257] 18 40 8 17 2 94 122 >> > 2 >> > [265] 2 27 76 263 2 2515 232 >> > 441 >> > [273] 3 20 6 132 191 48 12 >> > 57 >> > [281] 13 6 46 3 19 45 5 >> > 34 >> > [289] 7 15 50 153 4949 5 2 >> > 8 >> > [297] 44 2 3 12 281 4 125 >> > 1 >> > [305] 4 9 1294 28 1 126 4 >> > 9 >> > [313] 183 805 9 3 37 10874 31 >> > 12741 >> > [321] 21 58 2 2 4 94 1 >> > 3 >> > [329] 93 216 15 1575 22 20 1 >> > 1 >> > [337] 10 26 4 3 13 50 76 >> > 93 >> > [345] 10 28 140 4 1906 15 30 >> > 1 >> > [353] 2 15 2 4704 8 25 14 >> > 7 >> > [361] 159 6 191 6 3 8 12 >> > 14 >> > [369] 13 53 11 9 109 39 3 >> > 1 >> > [377] 20 91 13 1 1917 222 19 >> > 1 >> > [385] 19 9 40 54 2 67 5 >> > 1 >> > [393] 18 28 103090 3024 1601 1 5 >> > 1 >> > [401] 12 4 22 2 2 260 11 >> > 25004832 >> > [409] 7 4 55 1249 5 168 115 >> > 11 >> > [417] 7 2 3332 3796 38 2 28 >> > 12 >> > [425] 2 35079 295 58 3 84 12 >> > 78057 >> > [433] 2 2 178 11 352 1 3 >> > 23 >> > [441] 117 148 10 91 10 12 2 >> > 79 >> > [449] 67 4 6 47 4 395 10 >> > 21 >> > [457] 26 7 3399 4 1 3 13 >> > 33 >> > [465] 8 70 13 15 201 18 1623 >> > 140 >> > [473] 2658 40 13 9 6 1 27 >> > 605 >> > [481] 26 4 248 663 4 2 307 >> > 67 >> > [489] 3 4740 129 2466 136 14 144 >> > 1 >> > [497] 21 16 3 271 >> > >> > [[alternative HTML version deleted]] >> > >> > ______________________________________________ >> > R-help@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. > > ______________________________________________ R-help@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.