loss: Loss function

View source: R/MPMutils.R

lossR Documentation

Loss function

Description

Compute the loss function needed for prediction error estimation.

Usage

loss(p, y, method = "log", ...)

Arguments

p

A vector of predicted outcome values.

y

A vector of observed outcome values.

method

Loss function definition. One between "log" (default) and "sqerror".

...

Currently ignored.

Details

The subject-level prediction error, calculated through the topsim function, is strongly correlated with the loss function values. However, while the former can be only calculated for the entire training set, the latter can be computed for the new input profile(s). Therefore, the prediction error (E) for the input is calculated as: E = b0 + b*L, where L is the loss function value. L can be currently defined as either "log": L = -1*(y*log(p) + (1 - y)*log(1 - p)) (default), or "sqerror": L = (p - y)^2. Additionally, the cost is calculated as either average loss sum(L)/n or root mean squared error sqrt(sum(L)/n), for "log" and "sqerror", respectively.

Value

A list of 2 objects:

  1. "loss", loss function values;

  2. "cost", cost function value.

Author(s)

Fernando Palluzzi fernando.palluzzi@gmail.com

See Also

us.predict, brier

Examples


# RBM prediction vs. reality over the simulated dataset

p <- predict(mpm.rbm$fit, dichotomize(mpm.us[2:15], asFactor = TRUE),
             type = "response")

L <- loss(p, mpm.us$y)

print(quantile(L$loss))

print(L$cost)

# Overall RBM performances

y.hat <- ifelse(p > 0.5, 1, 0)
P <- performance(obs = mpm.us$y, pred = y.hat)

print(P)


Morphonodepredictivemodel/morphonode documentation built on Feb. 15, 2023, 4:51 a.m.