log_user_mixture: Define a finite mixture of a given family of distributions.

View source: R/bayesian_cure_rate_model.R

log_user_mixtureR Documentation

Define a finite mixture of a given family of distributions.

Description

This function computes the logarithm of the probability density function and cumulative density function per observation for each observation under a user-defined mixture of a given family of distributions. The parameters of the given family of distributions should belong to (0, inf).

Usage

log_user_mixture(user_f, y, a, p, c_under = 1e-09)

Arguments

user_f

a user defined function that returns the logarithm of a given probability density and the corresponding logarithm of the cumulative distribution function. These arguments should be returned in the form of a list with two entries: log_f and log_F, containing the logarithm of the pdf and cdf values of y, respectively, for a given set of parameter values.

y

observed data

a

a matrix where each column corresponds to component specific parameters and the columns to different components. All parameters should be positive. The number of columns should be the same with the number of mixture components.

p

vector of mixing proportions

c_under

threshold for underflows.

Value

A list containing the following entries

log_f

natural logarithm of the pdf, evaluated at each datapoint.

log_F

natural logarithm of the CDF, evaluated at each datapoint.

Author(s)

Panagiotis Papastamoulis

Examples

# We will define a mixture of 2 exponentials distributions.
# First we pass the exponential distribution at user_f
user_f <- function(y, a){
	log_f <- dexp(y, rate = a, log = TRUE)
	log_F <- pexp(y, rate = a, log.p = TRUE)
	result <- vector('list', length = 2)
	names(result) <- c('log_f', 'log_F')
	result[["log_f"]] = log_f
	result[["log_F"]] = log_F
	return(result)
}
#	simulate some date
y <- runif(10)
# Now compute the log of pdf and cdf for a mixture of K=2 exponentials
p <- c(0.9,0.1)
a <- matrix(c(0.1, 1.5), nrow = 1, ncol = 2)
log_user_mixture(user_f = user_f, y = y, a = a, p = p)

bayesCureRateModel documentation built on Oct. 4, 2024, 1:07 a.m.