Error message

  • Deprecated function: The each() function is deprecated. This message will be suppressed on further calls in book_prev() (line 775 of /home3/gardeoi3/public_html/iamrandom/modules/book/book.module).
  • Deprecated function: implode(): Passing glue string after array is deprecated. Swap the parameters in drupal_get_feeds() (line 394 of /home3/gardeoi3/public_html/iamrandom/includes/common.inc).

Sample or Rmultinom (sampling)

 Draw one of {1,..,K} with probabilities "probf"

 Needs function: sumv

   int Rmultinom(Rcpp::NumericVector probs )
    {   int Kf = probs.size();
        int v;
        double x( 1 );
        x=runif(1)(0);  
        Rcpp::NumericVector probsum( Kf ); //cumsum of normalized probs
        double sprob=rcpp_sumv(probs);  //sum of the probs vector
        probs(0)=probs(0)/sprob;
        probsum( 0 )= probs( 0 );
        for( int k = 1; k < Kf; k++ )
        {  probs(k)=probs(k)/sprob;    // Normalize the probs vector
           probsum(k)=probs(k)+probsum(k-1);
        }
        if( x < probsum(0) ){ v=0; }
        for( int k = 0; k < (Kf-1); k++ )
        {  if(x > probsum(k) & x< probsum(k+1)){v=k+1;}
        }
        if(x > probsum(Kf-1)){v=Kf-1;}
        return v+1;
   }