Boundaries of (probability distribution) function parameters in R?

30 Views Asked by At

I would like to know without checking the documentation, what values a probability distribution accepts as arguments.

A single parameter can be a:

  1. double between -Inf and Inf
  2. double between 0 and Inf
  3. positive integer
  4. double between 0 and 1

(I know, for example, multinomial distribution has vector arguments, but let's concentrate now on the distribution having scalar arguments.)

library(dplyr)

checkArgBoundaries <- function(distribution) {

    #The number of parameters the distribution has
    nparams <- formals(get(paste0("r",distribution))) %>% names %>% {.[!(. %in% c("n","ncp"))]} %>% length
    
    while(TRUE) {
        canWeBreak <- tryCatch({
            #This is problematic, since we should generate value candidates representing the boundaries here. 
            do.call(get(paste0("r",distribution)), valuecandidates)
            TRUE
        }, warning = \(w) {
            FALSE
        }

        if(canWeBreak) {break}
    }

}

And for binomial distribution, for example, we should get a result that the size argument should be a positive integer and the prob argument should be between 0 and 1.

0

There are 0 best solutions below