Description Usage Arguments Value Author(s) Examples
View source: R/devianceCategorical.R
This function calculates a deviance measure for model predictions assuming a Categorical distribution.
1 | devianceCategorical(Y, Y_hat)
|
Y |
a numeric matrix of observations (0s and 1s) where columns indicate categories and rows indicate observations. Should be exactly one 1 per row. |
Y_hat |
a numeric matrix of predictions (between 0 and 1) for Y (must have same dimensions as Y.) Row sums should all equal 1. |
a numeric vector.
Edwin Graham <edwingraham1984@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | # n <- 1000
# nCat <- 10
#
# # Random probabilities normalised by row
# true_logistic <- matrix(rnorm(n*nCat), ncol = nCat)
# true_probabilities <- exp(true_logistic)/rowSums(exp(true_logistic))
#
# # Generate observations
# observed <- t(apply(true_probabilities, 1, cumsum))
# observed <- 1*(observed > runif(n))
# observed <- 1*t(apply(observed, 1, cumsum)==1)
#
# # Generate predictions
# predicted <- true_logistic + matrix(rnorm(n*nCat, sd=0.1), ncol=nCat)
# predicted <- exp(predicted)/rowSums(exp(predicted))
#
# plot(observed, predicted)
#
# devs <- devianceCategorical(observed, predicted)
# sum(devs)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.