log_lik: Calculate log likelihood

View source: R/lik_profile.R

log_likR Documentation

Calculate log likelihood

Description

Calculates the sum of log likelihoods of each observation given the model parameterization (considering a normal distribution around the prediction for each datapoint)

Usage

log_lik(npars, obs, pred)

Arguments

npars

named numeric vector of parameters that the model was calibrated on

obs

numeric vector of observed values

pred

numeric vector of predicted values

Value

the log likelihood value

Examples


# observations
obs <- c(12, 38, 92, 176, 176, 627, 1283, 2640)
# intercept, a, and slope, b, of a Poisson regression fitted through obs
pars <- c(a = 2, b = 0.73)
# predictions with the Poisson regression
pred <- c(15.43, 32.15, 66.99, 139.57, 290.82, 605.94, 1262.52, 2630.58)
# example plot
plot(seq(1:length(obs)), obs)
lines(seq(1:length(obs)), pred)
log_lik(
  npars = length(pars),
  obs = obs,
  pred = pred
)


cvasi documentation built on Sept. 23, 2024, 9:08 a.m.