Bern {joker}R Documentation

Bern Distribution

Description

The Bernoulli distribution is a discrete probability distribution which takes the value 1 with probability p and the value 0 with probability 1 - p, where 0 \leq p \leq 1.

Usage

Bern(prob = 0.5)

dbern(x, prob, log = FALSE)

pbern(q, prob, lower.tail = TRUE, log.p = FALSE)

qbern(p, prob, lower.tail = TRUE, log.p = FALSE)

rbern(n, prob)

## S4 method for signature 'Bern,numeric'
d(distr, x, log = FALSE)

## S4 method for signature 'Bern,numeric'
p(distr, q, lower.tail = TRUE, log.p = FALSE)

## S4 method for signature 'Bern,numeric'
qn(distr, p, lower.tail = TRUE, log.p = FALSE)

## S4 method for signature 'Bern,numeric'
r(distr, n)

## S4 method for signature 'Bern'
mean(x)

## S4 method for signature 'Bern'
median(x)

## S4 method for signature 'Bern'
mode(x)

## S4 method for signature 'Bern'
var(x)

## S4 method for signature 'Bern'
sd(x)

## S4 method for signature 'Bern'
skew(x)

## S4 method for signature 'Bern'
kurt(x)

## S4 method for signature 'Bern'
entro(x)

## S4 method for signature 'Bern'
finf(x)

llbern(x, prob)

## S4 method for signature 'Bern,numeric'
ll(distr, x)

ebern(x, type = "mle", ...)

## S4 method for signature 'Bern,numeric'
mle(distr, x, na.rm = FALSE)

## S4 method for signature 'Bern,numeric'
me(distr, x, na.rm = FALSE)

vbern(prob, type = "mle")

## S4 method for signature 'Bern'
avar_mle(distr)

## S4 method for signature 'Bern'
avar_me(distr)

Arguments

prob

numeric. Probability of success.

x

For the density function, x is a numeric vector of quantiles. For the moments functions, x is an object of class Bern. For the log-likelihood and the estimation functions, x is the sample of observations.

log, log.p

logical. Should the logarithm of the probability be returned?

q

numeric. Vector of quantiles.

lower.tail

logical. If TRUE (default), probabilities are P(X \leq x), otherwise P(X > x).

p

numeric. Vector of probabilities.

n

number of observations. If length(n) > 1, the length is taken to be the number required.

distr

an object of class Bern.

type

character, case ignored. The estimator type (mle or me).

...

extra arguments.

na.rm

logical. Should the NA values be removed?

Details

The probability mass function (PMF) of the Bernoulli distribution is given by:

f(x; p) = p^x (1 - p)^{1 - x}, \quad p \in (0, 1), \quad x \in \{0, 1\}.

Value

Each type of function returns a different type of object:

See Also

Functions from the stats package: dbinom(), pbinom(), qbinom(), rbinom()

Examples

# -----------------------------------------------------
# Bernoulli Distribution Example
# -----------------------------------------------------

# Create the distribution
p <- 0.7
D <- Bern(p)

# ------------------
# dpqr Functions
# ------------------

d(D, c(0, 1)) # density function
p(D, c(0, 1)) # distribution function
qn(D, c(0.4, 0.8)) # inverse distribution function
x <- r(D, 100) # random generator function

# alternative way to use the function
df <- d(D) ; df(x) # df is a function itself

# ------------------
# Moments
# ------------------

mean(D) # Expectation
median(D) # Median
mode(D) # Mode
var(D) # Variance
sd(D) # Standard Deviation
skew(D) # Skewness
kurt(D) # Excess Kurtosis
entro(D) # Entropy
finf(D) # Fisher Information Matrix

# List of all available moments
mom <- moments(D)
mom$mean # expectation

# ------------------
# Point Estimation
# ------------------

ll(D, x)
llbern(x, p)

ebern(x, type = "mle")
ebern(x, type = "me")

mle(D, x)
me(D, x)
e(D, x, type = "mle")

mle("bern", x) # the distr argument can be a character

# ------------------
# Estimator Variance
# ------------------

vbern(p, type = "mle")
vbern(p, type = "me")

avar_mle(D)
avar_me(D)

v(D, type = "mle")

[Package joker version 0.14.2 Index]