[R] zipfR help
R. Michael Weylandt
michael.weylandt at gmail.com
Tue Apr 24 02:14:33 CEST 2012
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 <iamrutabaga at 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 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.
More information about the R-help
mailing list