Learn R Programming

lax (version 1.2.3)

bernoulli: Inference for the Bernoulli distribution

Description

Functions involved in making inferences about the probability of success in a Bernoulli distribution.

Usage

fit_bernoulli(data)

# S3 method for bernoulli logLikVec(object, pars = NULL, ...)

# S3 method for bernoulli nobs(object, ...)

# S3 method for bernoulli coef(object, ...)

# S3 method for bernoulli vcov(object, ...)

# S3 method for bernoulli logLik(object, ...)

# S3 method for bernoulli alogLik(x, cluster = NULL, use_vcov = TRUE, ...)

Value

fit_bernoulli returns an object of class "bernoulli", a list with components: logLik, mle, nobs, vcov, data, obs_data, where data are the input data and obs_data are the input data after any missing values have been removed, using na.omit.

logLikVec.bernoulli returns an object of class "logLikVec", a vector length length(data) containing the likelihood contributions from the individual observations in data.

Arguments

data

A numeric vector of outcomes from Bernoulli trials: 0 for a failure, 1 for a success. Alternatively, a logical vector with FALSE for a failure and TRUE for a success.

pars

A numeric parameter vector of length 1 containing the value of the Bernoulli success probability.

...

Further arguments to be passed to the functions in the sandwich package meat (if cluster = NULL), or meatCL (if cluster is not NULL).

x, object

A fitted model object returned from fit_bernoulli().

cluster

A vector or factor indicating from which cluster each observation in data originates.

use_vcov

A logical scalar. Should we use the vcov S3 method for x (if this exists) to estimate the Hessian of the independence loglikelihood to be passed as the argument H to adjust_loglik? Otherwise, H is estimated inside adjust_loglik using optimHess.

Details

fit_bernoulli: fit a Bernoulli distribution

logLikVec.bernoulli: calculates contributions to a loglikelihood based on the Bernoulli distribution. The loglikelihood is calculated up to an additive constant.

nobs, coef, vcov and logLik methods are provided.

See Also

Binomial. The Bernoulli distribution is the special case where size = 1.

Examples

Run this code
# Set up data
x <- exdex::newlyn
u <- quantile(x, probs = 0.9)
exc <- x > u

# Fit a Bernoulli distribution
fit <- fit_bernoulli(exc)

# Calculate the loglikelihood at the MLE
res <- logLikVec(fit)

# The logLik method sums the individual loglikelihood contributions.
logLik(res)

# nobs, coef, vcov, logLik methods for objects returned from fit_bernoulli()
nobs(fit)
coef(fit)
vcov(fit)
logLik(fit)

# Adjusted loglikelihood
# Create 5 clusters each corresponding approximately to 1 year of data
cluster <- rep(1:5, each = 579)[-1]
afit <- alogLik(fit, cluster = cluster, cadjust = FALSE)
summary(afit)

Run the code above in your browser using DataLab