R/RealRandVariable.R

Defines functions RealRandVariable

Documented in RealRandVariable

## generating function
RealRandVariable <- function(Map = list(function(x){1}), Domain = NULL, Range) {
    nrvalues <- length(Map)
    for(i in 1:nrvalues){
        if(!is.function(Map[[i]])) 
            stop("element ", i, " of 'Map' contains no function")
        if(length(formals(Map[[i]])) != 1)
            stop("element ", i, " of 'Map' has to be a function of one argument")
        if(names(formals(Map[[i]])) != "x")
            stop("element ", i, " of 'Map' contains a function with argument name != 'x'")
    }

    if(missing(Range)) Range <- Reals()
    if(!is(Range, "Reals"))
        stop("'Range' has to be of class 'Reals'")

    R <- new("RealRandVariable")
    R@Map <- Map
    R@Domain <- Domain
    R@Range <- Range
    
    return(R)
}

## replace method
setReplaceMethod("Range", "RealRandVariable", 
    function(object, value){ 
        object@Range <- value 
        if(!is(value, "Reals"))
            stop("'Range' of 'value' is not the Real space")
        object
    })

Try the RandVar package in your browser

Any scripts or data that you put into this service are public.

RandVar documentation built on Jan. 20, 2020, 1:14 a.m.