Learn R Programming

scoringRules (version 0.9.3)

scores_mixnorm: Calculating scores for a mixture of normal distributions.

Description

Calculating scores for a mixture of normal distributions.

Usage

crps_mixnorm(y, m, s, w)

crps_mixnorm_int(y, m, s, w, rel_tol = 1e-06)

logs_mixnorm(y, m, s, w)

Arguments

y

vector of observations.

m

matrix of mean parameters (rows represent observations, columns represent mixture components).

s

matrix of scale parameters (same structure as for m).

w

matrix of weights (same structure as for m; row sums must equal one).

rel_tol

relative accuracy for numerical integration.

Value

A vector of score values.

Details

logs_mixnorm and crps_mixnorm calculate scores via analytical formulas. crps_mixnorm_int uses numerical integration for the CRPS; this can be faster if there are many mixture components (i.e., if m, s and w have many columns). See examples below.

Examples

Run this code
# NOT RUN {
# Example 1: 100 observations, 15 mixture components
mval <- matrix(rnorm(100*15), nrow = 100)
sdval <- matrix(rgamma(100*15, shape = 2), nrow = 100)
weights <- matrix(rep(1/15, 100*15), nrow = 100)
y <- rnorm(100)
crps1 <- crps_mixnorm(y = y, m = mval, s = sdval, w = weights)
crps2 <- crps_mixnorm_int(y = y, m = mval, s = sdval, w = weights)

# }
# NOT RUN {
# Example 2: 2 observations, 10000 mixture components
mval <- matrix(rnorm(2*10000), nrow = 2)
sdval <- matrix(rgamma(2*10000, shape = 2), nrow = 2)
weights <- matrix(rep(1/10000, 2*10000), nrow = 2)
y <- rnorm(2)
# With many mixture components, numerical integration is much faster
system.time(crps1 <- crps_mixnorm(y = y, m = mval, s = sdval, w = weights))
system.time(crps2 <- crps_mixnorm_int(y = y, m = mval, s = sdval, w = weights))
# }

Run the code above in your browser using DataLab