metric_nloglik: metric_nloglik

Description Usage Arguments Value See Also Examples

View source: R/metric_nloglik.R

Description

Returns the negative log likelihood for the predictions. Note: Predictions should be annualized (independent of exposure) Note: Large negative values are good. (function should be minimised)

Usage

1
2
3
4
5
6
7
8
9
metric_nloglik(
  actual,
  predicted,
  weight = NULL,
  family = "gaussian",
  na.rm = FALSE,
  rebase = FALSE,
  tweedie_power = NULL
)

Arguments

actual

Array[Numeric] - Values we are aiming to predict.

predicted

Array[Numeric] - Values that we have predicted.

weight

Optional: Array[Numeric] - Weighting of predictions. If NULL even weighting is used

family

String - family of distribution. Must be in c("gaussian", "poisson", "gamma", "tweedie", "binomial")

na.rm

Optional: boolean - If FALSE function will return NA is any value in NA

rebase

Optional: boolean - If TRUE predictions weighted mean will be rebased to match actual mean

tweedie_power

Numeric - power of tweedie distribution if chosen in family

Value

Numeric: negative log likelihood

See Also

Other Metrics: metric_deviance(), metric_mae(), metric_pode(), metric_pove(), metric_rmse()

Examples

1
2
3
4
5
6
7
8
9
set.seed(666)
actual <- pmax(rep(10, 10), 0)
predicted <- pmax(rnorm(n = 10, mean = 10, sd = 1), 0)
weight <- pmax(rnorm(n = 10, mean = 10, sd = 1), 0)

metric_nloglik(actual, predicted, family="poisson")
metric_nloglik(actual, predicted, weight, family="poisson")
metric_nloglik(actual, predicted, weight, family="gamma")
metric_nloglik(actual=c(rep(0,5), rep(1,5)), predicted=seq(0.01,0.99,length.out=10), weight, family="binomial")

gloverd2/admr documentation built on Dec. 2, 2020, 11:16 p.m.