Learn R Programming

FAmle (version 1.3.7)

distr: 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

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.

Value

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

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.

Examples

Run this code
# NOT RUN {
## 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')

# }

Run the code above in your browser using DataLab