# 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)
Run the code above in your browser using DataLab