What is the relationship between StatsAPI.loglikelihood(d, x) and Distributions.logpdf(d, x) where d::Distribution and x is a draw from it?
In the examples I’ve tried, they give the same results.
let d = Normal(0,1)
x = .3
logpdf(d, x) == loglikelihood(d,x) # true
end
Are they the same? When should I use each? For instance, should I call loglikelihood(d,x) inside of my own composite log-likelihood functions, and use logpdf(d,x) inside of prior-probability functions?
The main difference is that loglikelihood computes the sum of the log likelihoods and logpdf computes the log likelihood of a single observation. Your example is a special case in which the outputs are the same.
using Distributions
dist = Normal(0, 1)
x = rand(dist, 10)
In statistics, when estimating parameters, the term likelihood is used to speak of the distribution of the data, but evaluated at some point in the parameter space, which is the set of parameter values under consideration. The actual distribution is simply the likelihood, but evaluated at the point in the parameter space that corresponds to the true, often unknown, parameter vector. So, the distinction is one of the name only. When doing statistics, it is called the likelihood. When doing probability theory, it is called the pdf.