Distribution functions 4-in-1

Description

This function can be used to call any of the 4 functions specific to a given probability distribution available in R.

Usage

1
distr(x, dist, param, type = "d", model = NULL, ...)

Arguments

x

Vector (or array) of quantiles, vector (or array) of probabilities, or number of observations.

dist

Distribution name.

param

Vector (or array) of parameters.

type

Type of function to be called ('d', 'p', 'q', or 'r').

model

Object from the class mle - may be specified instead of param and dist.

...

Additional arguments log, lower.tail, and log.p, depending on type.

Details

For each distribution available in R, 4 functions can be called. For example, for the normal distribution, the following 4 functions are available: dnorm, pnorm, qnorm, and rnorm. For the normal distribution, based on the argument type, distr may be used to call any one of the previous four functions.

Value

Returns the density, the distribution function, the quantile function, or random variates.

Note

Most functions in FAmle rely upon distr.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## Example 1
dnorm(-4:4,0,1,log=TRUE)
distr(-4:4,'norm',c(0,1),type='d',log=TRUE)

## Example 2
mu.vec <- c(1,100,100)
sigma.vec <- c(1,11,111)
n <- 3
set.seed(123)
rnorm(n,mu.vec,sigma.vec)
set.seed(123)
distr(n,'norm',cbind(mu.vec,sigma.vec),'r')

## Example 3
qnorm(.9,mu.vec,sigma.vec)
distr(.9,'norm',cbind(mu.vec,sigma.vec),'q')