Learn R Programming

bayescount (version 0.8.2)

likelihood: CALCULATE THE (LOG) LIKELIHOOD OF OBTAINING DATA FROM A DISTRIBUTION

Description

Function to calculate the (log) likelihood of obtaining a set of data from one of the following distributions: Poisson (P), gamma (G), lognormal (L), Weibull (W), gamma Poisson (GP), lognormal Poisson (LP), Weibull Poisson (WP), all with or without zero-inflation (ZI). For mixture models, the likelihood is calculated for the data by integrating over each possible value of lambda for each data point, which may take some time for large datasets. Note: the likelihoods are proportional to, not equal to, the probability of obtaining the data, with a proportionality that is unique to each distribution. It is therefore impossible to compare the likelihood between distributions, or even with the same distribution if zero-inflation is present in differing amounts. *THIS SOFTWARE IS INTENDED FOR EDUCATIONAL PURPOSES ONLY AND SHOULD NOT BE RELIED UPON FOR REAL WORLD APPLICATIONS*

Usage

likelihood(model, data, mean=NA, variance=NA, 
   zi=NA, shape=NA, scale=NA, 
   iterations=min(1000, (length(as.matrix(mean)[,1])*length(shape))),
   log=TRUE, silent=FALSE, raw.output=FALSE)

Arguments

Value

The (log) likelihood is returned either as a vector of length equal to the number of iterations representing the likelihood at each iteration if raw.output==TRUE, or a summary of the results (median and 95

See Also

bayescount bayescount.single maximise.likelihood for a simple maximum likelihood solution using likelihood()

Examples

Run this code
# calculate the likelihood of obtaining a set of count data from a zero-inflated Poisson distribution with set mean and zero-inflation values

data <- rpois(100, 10)
data[1:15] <- 0

likelihood('ZIP', data, mean=10, zi=15)

# now calculate the likelihood for the same data using an MCMC object to provide the values for mean and zero-inflation

values <- bayescount.single(data, model='ZISP', raw.output=TRUE)
means <- c(values[,'mean'][[1]], values[,'mean'][[2]])
zis <- (1-c(values[,'prob'][[1]], values[,'prob'][[2]]))*100  # The function outputs the prevalence of disease when raw.ouput is TRUE, so zero-inflation must be calculated from this

likes <- likelihood('ZIP', data, mean=means, zi=zis, raw.output=TRUE)$likelihood
hist(likes, breaks='fd', col='red')

Run the code above in your browser using DataLab