Package 'likelihoodExplore'

Title: Likelihood Exploration
Description: Provides likelihood functions as defined by Fisher (1922) <doi:10.1098/rsta.1922.0009> and a function that creates likelihood functions from density functions. The functions are meant to aid in education of likelihood based methods.
Authors: Ben Barnard [aut, cre]
Maintainer: Ben Barnard <[email protected]>
License: GPL-2
Version: 0.1.1
Built: 2026-05-29 11:23:30 UTC
Source: https://github.com/benbarnard/likelihoodexplore

Help Index


Beta Log Likelihood Function

Description

The log likelihood of a beta density with data, x, shape1, shape2 and ncp parameters.

Usage

likbeta(shape1, shape2, ncp = 0, x, log = FALSE)

Arguments

shape1

non-negative parameters of the Beta distribution.

shape2

non-negative parameters of the Beta distribution.

ncp

non-centrality parameter.

x

vector of quantiles.

log

logical; if TRUE, probabilities p are given as log(p).

Details

The log likelihood is the log of a function of parameters given the data.

Value

A numeric scalar for the log likelihood of the beta density given the data where shape1, shape2, and ncp can be held constant or if vector were given vector will be returned.

Examples

likbeta(x = rbeta(n = 2, shape1 = 3, shape2 = 4),
        shape1 = 3, shape2 = 4)

Binomial Log Likelihood Function

Description

The log likelihood of a binomial density with data, x, size and prob parameters.

Usage

likbinom(size, prob, x, log = FALSE)

Arguments

size

number of trials (zero or more).

prob

probability of success on each trial.

x

vector of quantiles.

log

logical; if TRUE, probabilities p are given as log(p).

Details

The log likelihood is the log of a function of parameters given the data.

Value

A numeric scalar for the log likelihood of the binomial density given the data where size and prob can be held constant or if vector were given vector will be returned.

Examples

likbinom(x = rbinom(n = 2, size = 3, prob = .4),
        size = 3, prob = .4)

Cauchy Log Likelihood Function

Description

The log likelihood of a Cauchy density with data, x, location and scale parameters.

Usage

likcauchy(location = 0, scale = 1, x, log = FALSE)

Arguments

location

location and scale parameters.

scale

location and scale parameters.

x

vector of quantiles.

log

logical; if TRUE, probabilities p are given as log(p).

Details

The log likelihood is the log of a function of parameters given the data.

Value

A numeric scalar for the log likelihood of the Cauchy density given the data where location and scale can be held constant or if vector were given vector will be returned.

Examples

likcauchy(x = rcauchy(n = 2))

Chi-Squared Log Likelihood Function

Description

The log likelihood of a chi-squared density with data, x, df and ncp parameters.

Usage

likchisq(df, ncp = 0, x, log = FALSE)

Arguments

df

degrees of freedom (non-negative, but can be non-integer).

ncp

non-centrality parameter (non-negative).

x

vector of quantiles.

log

logical; if TRUE, probabilities p are given as log(p).

Details

The log likelihood is the log of a function of parameters given the data.

Value

A numeric scalar for the log likelihood of the chi-squared density given the data where df and ncp can be held constant or if vector were given vector will be returned.

Examples

likchisq(x = rchisq(n = 2, df = 4),
        df = 4)

Likelihood Function Maker

Description

Function that creates a log likelihood function given a density function density.

Usage

likelihood(density, ...)

Arguments

density

density function used

...

other options

Details

The log likelihood is the log of a function of parameters given the data.

Value

A function that is the log likelihood function from density function density.

Examples

likelihood(dnorm, x = rnorm(100))

Likelihood Exploration

Description

A package of likelihood functions as defined by Fisher <doi:10.1098/rsta.1922.0009> and a function that creates likelihood functions from density functions. The functions are meant to aid in education of likelihood based methods.


Exponential Log Likelihood Function

Description

The log likelihood of a exponential density with data, x, rate parameter.

Usage

likexp(rate = 1, x, log = FALSE)

Arguments

rate

vector of rates.

x

vector of quantiles.

log

logical; if TRUE, probabilities p are given as log(p).

Details

The log likelihood is the log of a function of parameters given the data.

Value

A numeric scalar for the log likelihood of the exponential density given the data where rate can be held constant or if vector were given vector will be returned.

Examples

likexp(x = rexp(n = 2))

F Log Likelihood Function

Description

The log likelihood of a F density with data, x, df1, df2 and ncp parameters.

Usage

likf(df1, df2, ncp, x, log = FALSE)

Arguments

df1

degrees of freedom. Inf is allowed.

df2

degrees of freedom. Inf is allowed.

ncp

non-centrality parameter. If omitted the central F is assumed.

x

vector of quantiles.

log

logical; if TRUE, probabilities p are given as log(p).

Details

The log likelihood is the log of a function of parameters given the data.

Value

A numeric scalar for the log likelihood of the f density given the data where df1, df2, and ncp can be held constant or if vector were given vector will be returned.

Examples

likf(x = rf(n = 2, df1 = 3, df2 = 4),
        df1 = 3, df2 = 4, ncp = 0)

Gamma Log Likelihood Function

Description

The log likelihood of a gamma density with data, x, shape, rate and scale parameters.

Usage

likgamma(shape, rate = 1, scale = 1/rate, x, log = FALSE)

Arguments

shape

shape and scale parameters. Must be positive, scale strictly.

rate

an alternative way to specify the scale.

scale

shape and scale parameters. Must be positive, scale strictly.

x

vector of quantiles.

log

logical; if TRUE, probabilities/densities pp are returned as log(p)log(p).

Details

The log likelihood is the log of a function of parameters given the data.

Value

A numeric scalar for the log likelihood of the gamma density given the data where shape, scale, and rate can be held constant or if vector were given vector will be returned.

Examples

likgamma(x = rgamma(n = 2, shape = 3),
        shape = 3)

Geometric Log Likelihood Function

Description

The log likelihood of a geometric density with data, x, prob parameter.

Usage

likgeom(prob, x, log = FALSE)

Arguments

prob

probability of success in each trial. 0 < prob <= 1.

x

vector of quantiles representing the number of failures in a sequence of Bernoulli trials before success occurs.

log

logical; if TRUE, probabilities p are given as log(p).

Details

The log likelihood is the log of a function of parameters given the data.

Value

A numeric scalar for the log likelihood of the geometric density given the data where prob can be held constant or if vector were given vector will be returned.

Examples

likgeom(x = rgeom(n = 2, prob = .4),
        prob = .4)

Hypergeometric Log Likelihood Function

Description

The log likelihood of a hypergeometric density with data, x, m, n and k parameters.

Usage

likhyper(m, n, k, x, log = FALSE)

Arguments

m

the number of white balls in the urn.

n

the number of black balls in the urn.

k

the number of balls drawn from the urn.

x

vector of quantiles representing the number of white balls drawn without replacement from an urn which contains both black and white balls.

log

logical; if TRUE, probabilities p are given as log(p).

Details

The log likelihood is the log of a function of parameters given the data.

Value

A numeric scalar for the log likelihood of the hypergeometric density given the data where m, n, and k can be held constant or if vector were given vector will be returned.

Examples

likhyper(x = rhyper(nn = 2, m = 3, n = 4, k = 2),
        m = 3, n = 4, k = 2)

Log Normal Log Likelihood Function

Description

The log likelihood of a log normal density with data, x, meanlog and sdlog parameters.

Usage

liklnorm(meanlog = 0, sdlog = 1, x, log = FALSE)

Arguments

meanlog

mean and standard deviation of the distribution on the log scale with default values of 0 and 1 respectively.

sdlog

mean and standard deviation of the distribution on the log scale with default values of 0 and 1 respectively.

x

vector of quantiles.

log

logical; if TRUE, probabilities p are given as log(p).

Details

The log likelihood is the log of a function of parameters given the data.

Value

A numeric scalar for the log likelihood of the log normal density given the data where meanlog and sdlog can be held constant or if vector were given vector will be returned.

Examples

liklnorm(x = rlnorm(n = 2))

Logistic Log Likelihood Function

Description

The log likelihood of a logistic density with data, x, location and scale parameters.

Usage

liklogis(location = 0, scale = 1, x, log = FALSE)

Arguments

location

location and scale parameters.

scale

location and scale parameters.

x

vector of quantiles.

log

logical; if TRUE, probabilities p are given as log(p).

Details

The log likelihood is the log of a function of parameters given the data.

Value

A numeric scalar for the log likelihood of the logistic density given the data where location and scale can be held constant or if vector were given vector will be returned.

Examples

liklogis(x = rlogis(n = 2))

Multinomial Log Likelihood Function

Description

The log likelihood of a multinomial density with data, x, size and prob parameters.

Usage

likmultinom(size = NULL, prob, x, log = FALSE)

Arguments

size

integer, say NN, specifying the total number of objects that are put into KK boxes in the typical multinomial experiment. For dmultinom, it defaults to sum(x).

prob

numeric non-negative vector of length KK, specifying the probability for the KK classes; is internally normalized to sum 1. Infinite and missing values are not allowed.

x

vector of length KK of integers in 0:size.

log

logical; if TRUE, log probabilities are computed.

Details

The log likelihood is the log of a function of parameters given the data.

Value

A numeric scalar for the log likelihood of the multinomial density given the data where size and prob can be held constant or if vector were given vector will be returned.

Examples

likmultinom(x = rmultinom(n = 2, size = 3, prob = .4),
        size = 3, prob = .4)

Negative Binomial Log Likelihood Function

Description

The log likelihood of a negative binomial density with data, x, size, prob and mu parameters.

Usage

liknbinom(size, prob, mu, x, log = FALSE)

Arguments

size

target for number of successful trials, or dispersion parameter (the shape parameter of the gamma mixing distribution). Must be strictly positive, need not be integer.

prob

probability of success in each trial. 0 < prob <= 1.

mu

alternative parametrization via mean: see ‘Details’.

x

vector of (non-negative integer) quantiles.

log

logical; if TRUE, probabilities p are given as log(p).

Details

The log likelihood is the log of a function of parameters given the data.

Value

A numeric scalar for the log likelihood of the negative binomial density given the data where size, prob, and mu can be held constant or if vector were given vector will be returned.

Examples

liknbinom(x = rnbinom(n = 2, size = 3, prob = .4),
        size = 3, prob = .4, mu = NULL)

Normal Log Likelihood Function

Description

The log likelihood of a normal density with data, x, mean and sd parameters.

Usage

liknorm(mean = 0, sd = 1, x, log = FALSE)

Arguments

mean

vector of means.

sd

vector of standard deviations.

x

vector of quantiles.

log

logical; if TRUE, probabilities p are given as log(p).

Details

The log likelihood is the log of a function of parameters given the data.

Value

A numeric scalar for the log likelihood of the normal density given the data where mean and sd can be held constant or if vector were given vector will be returned.

Examples

liknorm(x = rnorm(n = 2))

Poisson Log Likelihood Function

Description

The log likelihood of a Poisson density with data, x, lambda parameter.

Usage

likpois(lambda, x, log = FALSE)

Arguments

lambda

vector of (non-negative) means.

x

vector of (non-negative integer) quantiles.

log

logical; if TRUE, probabilities p are given as log(p).

Details

The log likelihood is the log of a function of parameters given the data.

Value

A numeric scalar for the log likelihood of the Poisson density given the data where lambda can be held constant or if vector were given vector will be returned.

Examples

likpois(x = rpois(n = 2, lambda = 4),
        lambda = 4)

Student's t Log Likelihood Function

Description

The log likelihood of a Student's t density with data, x, df and ncp parameters.

Usage

likt(df, ncp, x, log = FALSE)

Arguments

df

degrees of freedom (>0> 0, maybe non-integer). df = Inf is allowed.

ncp

non-centrality parameter δ\delta; currently except for rt(), only for abs(ncp) <= 37.62. If omitted, use the central t distribution.

x

vector of quantiles.

log

logical; if TRUE, probabilities p are given as log(p).

Details

The log likelihood is the log of a function of parameters given the data.

Value

A numeric scalar for the log likelihood of the Student's t density given the data where df and ncp can be held constant or if vector were given vector will be returned.

Examples

likt(x = rt(n = 2, df = 4),
        df = 4)

Uniform Log Likelihood Function

Description

The log likelihood of a uniform density with data, x, min and max parameters.

Usage

likunif(min = 0, max = 1, x, log = FALSE)

Arguments

min

lower and upper limits of the distribution. Must be finite.

max

lower and upper limits of the distribution. Must be finite.

x

vector of quantiles.

log

logical; if TRUE, probabilities p are given as log(p).

Details

The log likelihood is the log of a function of parameters given the data.

Value

A numeric scalar for the log likelihood of the uniform density given the data where min and max can be held constant or if vector were given vector will be returned.

Examples

likunif(x = runif(n = 2))

Weibull Log Likelihood Function

Description

The log likelihood of a Weibull density with data, x, shape and scale parameters.

Usage

likweibull(shape, scale = 1, x, log = FALSE)

Arguments

shape

shape and scale parameters, the latter defaulting to 1.

scale

shape and scale parameters, the latter defaulting to 1.

x

vector of quantiles.

log

logical; if TRUE, probabilities p are given as log(p).

Details

The log likelihood is the log of a function of parameters given the data.

Value

A numeric scalar for the log likelihood of the Weibull density given the data where shape and scale can be held constant or if vector were given vector will be returned.

Examples

likweibull(x = rweibull(n = 2, shape = 3),
        shape = 3)

Wilcoxon Rank Sum Log Likelihood Function

Description

The log likelihood of a Wilcoxon rank sum density with data, x, m and n parameters.

Usage

likwilcox(m, n, x, log = FALSE)

Arguments

m

numbers of observations in the first and second sample, respectively. Can be vectors of positive integers.

n

numbers of observations in the first and second sample, respectively. Can be vectors of positive integers.

x

vector of quantiles.

log

logical; if TRUE, probabilities p are given as log(p).

Details

The log likelihood is the log of a function of parameters given the data.

Value

A numeric scalar for the log likelihood of the Wilcoxon rank sum density given the data where m and n can be held constant or if vector were given vector will be returned.

Examples

likwilcox(x = rwilcox(nn = 2, m = 3, n = 4),
        m = 3, n = 4)