View source: R/bayesian_cure_rate_model.R
log_user_mixture | R Documentation |
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).
log_user_mixture(user_f, y, a, p, c_under = 1e-09)
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: |
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. |
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. |
Panagiotis Papastamoulis
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.