>>>>> Christophe Dutang 
>>>>>     on Sat, 8 Apr 2023 14:21:53 +0200 writes:

    > Dear all,

    > Using rmultinom() in a stochastic model, I found this function returns an 
error message 'NA in probability' for an infinite probability. 

    > Maybe, a more precise message will be helpful when debugging. 

    >> rmultinom(1, 3:5, c(1/2, 1/3, Inf))
    > Error in rmultinom(1, 3:5, c(1/2, 1/3, Inf)) : NA in probability vector
    >> rmultinom(1, 3:5, c(1/2, 1/3, NA))
    > Error in rmultinom(1, 3:5, c(1/2, 1/3, NA)) : NA in probability vector

Thank you.

I agree the first ('Inf') should not do what it currently does,
and probably the 2nd one should neither give an error.


Note that in rmultinom,  the 'prob' is allowed to be *NOT*
scaled to sum(.) = 1.

Therefore 'Inf' makes sense as the limit (of a sequence) of (a)
very large number(s).

I claim that 

  rmultinom(1, 3, c(1/2, 1/3, Inf))

should give the same as 

  rmultinom(1, 3, c(1/2, 1/3, 1e300))

even without a warning,
and OTOH,  an NA in prob may return NA (and signal a warning)
instead of an error.


    > For rgeom() or rbinom(), we got a warning for infinite probability :

Yes, but there, prob must be in [0,1] ... so that's somewhat differnt.

    >> rbinom(1, 3, Inf)
    > [1] NA
    > Warning message:
    > In rbinom(1, 3, Inf) : NAs produced
    >> rbinom(1, 3, NA)
    > [1] NA
    > Warning message:
    > In rbinom(1, 3, NA) : NAs produced
    >> rgeom(1, Inf)
    > [1] NA
    > Warning message:
    > In rgeom(1, Inf) : NAs produced
    >> rgeom(1, NA)
    > [1] NA
    > Warning message:
    > In rgeom(1, NA) : NAs produced


    > Maybe, it could be better to harmonize the behavior for infinite 
probability.

    > Kind regards, Christophe


    >> sessionInfo()
    > R version 4.2.3 (2023-03-15)
    > Platform: aarch64-apple-darwin20 (64-bit)
    > Running under: macOS Ventura 13.2.1

    > Matrix products: default
    > BLAS:   
/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRblas.0.dylib
    > LAPACK: 
/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib

    > locale:
    > [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

    > attached base packages:
    > [1] stats     graphics  grDevices utils     datasets  methods   base     

    > loaded via a namespace (and not attached):
    > [1] compiler_4.2.3 tools_4.2.3   

    > -------------------------------------------------
    > Christophe DUTANG
    > LJK, Ensimag, Grenoble INP, UGA, France
    > Web: http://dutangc.free.fr

    > ______________________________________________
    > R-devel@r-project.org mailing list
    > https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to