Skip to content
Prev 42037 / 63435 Next

Rcpp too good to be true?

On 12/13/2011 03:48 PM, Jeffrey Pollock wrote:
Hi Jeff

Not really what you're asking about, but looks like you're sampling with 
replacement from the sequence 0:(dist-1) n times with probability dist, so

Rrcomp.1 <-
     function(n, lam, nu, max = 100L)
{
     dist <- dcomp(0:max, lam, nu, max)
     sample(seq_along(dist) - 1L, n, TRUE, prob=dist)
}

and

 > system.time(res <- table(Rrcomp(n, lam, nu))); res
    user  system elapsed
   1.493   0.000   1.495

    0    1    2    3    4    5    6    7    8    9   10   11   12   13
  355 1656 4070 6976 8745 8861 7275 5214 3357 1892  926  399  165   69
   14   15   16   17
   24   11    2    3
 > system.time(res <- table(Rrcomp.1(n, lam, nu))); res
    user  system elapsed
   0.029   0.000   0.028

    0    1    2    3    4    5    6    7    8    9   10   11   12   13
  333 1754 4096 6876 8964 8799 7399 5030 3215 1877  951  432  184   61
   14   15   16
   23    5    1

Martin