Hello, All:
????? Consider:
Browse[2]> set.seed(1)
Browse[2]> rpois(9, 1e10)
NAs produced[1] NA NA NA NA NA NA NA NA NA
????? Should this happen?
????? I think that for, say, lambda>1e6, rpois should return rnorm(.,
lambda, sqrt(lambda)).
????? For my particular Monte Carlo, I have replaced my call to rpois
with a call to the following:
?rpois. <- function(n, lambda){
????? n2 <- max(length(n), length(lambda))
????? n <- rep_len(n, n2)
????? lambda <- rep_len(lambda, n2)
#
????? big <- (lambda>1e6)
????? out <- rep(NA, n2)
????? out[big] <- rnorm(sum(big), lambda[big], sqrt(lambda[big]))
????? out[!big] <- rpois(sum(!big), lambda[!big])
????? out
? }
????? Comments?
????? Thanks,
????? Spencer Graves
> ------------------------------------------------------------------------ > Hello, All: > > > ????? Consider: > > > Browse[2]> set.seed(1) > Browse[2]> rpois(9, 1e10) > NAs produced[1] NA NA NA NA NA NA NA NA NA > > > ????? Should this happen? > > > ????? I think that for, say, lambda>1e6, rpois should return rnorm(., > lambda, sqrt(lambda)).But need to implement carefully; rpois should always return a non-negative integer, whereas rnorm always returns numeric...
On 2020-01-19 09:34, Benjamin Tyner wrote:>> ------------------------------------------------------------------------ >> Hello, All: >> >> >> ? ????? Consider: >> >> >> Browse[2]> set.seed(1) >> Browse[2]> rpois(9, 1e10) >> NAs produced[1] NA NA NA NA NA NA NA NA NA >> >> >> ? ????? Should this happen? >> >> >> ? ????? I think that for, say, lambda>1e6, rpois should return rnorm(., >> lambda, sqrt(lambda)). > But need to implement carefully; rpois should always return a > non-negative integer, whereas rnorm always returns numeric... >????? Thanks for the reply. ????? However, I think it's not acceptable to get an NA from a number that cannot be expressed as an integer.? Whenever a randomly generated number would exceed .Machine$integer.max, the choice is between returning NA or a non-integer numeric.? Consider: > 2*.Machine$integer.max [1] 4294967294 > as.integer(2*.Machine$integer.max) [1] NA Warning message: NAs introduced by coercion to integer range ????? I'd rather have the non-integer numeric. ????? Spencer