# isFunctionDensity: Check if a function is a (non-discrete) probability density... In RVCompare: Compare Real Valued Random Variables

 isFunctionDensity R Documentation

## Check if a function is a (non-discrete) probability density function in a given domain.

### Description

This function checks if an input function f is a non-discrete probability density function. For this to be the case, the function needs to only return real values. The function also needs to be bounded, positive, and its integral in the domain of definition needs to be 1.

### Usage

``````isFunctionDensity(f, xlims, tol = 0.001)
``````

### Arguments

 `f` the function to be checked. `xlims` an interval that represents the domain of definition of f. `tol` (optional parameter, default = 0.001) the integral of f is allowed to be in the interval (1-tol, 1+tol), to account for some reasonable error in the integration.

### Value

Returns True if the function is a non discrete probability density function. Otherwise, returns False.

### Examples

``````dist1 <- normalDensity(0,1)
# the integral of the density of the normal distribution is too low in the interval (-2,2)
isFunctionDensity(dist1, c(-2,2))
isFunctionDensity(dist1, c(-5,5)) # it is close enough from 1 in the interval (-5,5)
dist2 <- uniformDensity(c(0,1))
isFunctionDensity(dist2, xlims=c(-2,2))
isFunctionDensity(dist2, xlims=c(0.5,2)) # the integral is not 1

dist3 <- function(x) 0.5/sqrt(x)
# The integral of the function being 1 is not enough to be considered a density function.
# It also needs to be boounded.
isFunctionDensity(dist3, c(1e-14,1))

``````

RVCompare documentation built on Aug. 21, 2023, 5:13 p.m.