get_weight_func: Default Weight and Chaining Functions

get_weight_funcR Documentation

Default Weight and Chaining Functions

Description

Get commonly used weight or chaining functions to use within weighted scoring rules. The normal and logistic distribution, density, and survival functions are available. Multivariate normal distribution functions are also available for multivariate scoring rules.

Usage

get_weight_func(name = "norm_cdf", mu = 0, sigma = 1, weight = TRUE)

Arguments

name

name of the weight function to extract.

mu

location parameter(s) of the normal or logistic distribution.

sigma

scale parameter(s) of the normal or logistic distribution.

weight

logical specifying whether to return a weight function (weight = TRUE) or chaining function (weight = FALSE).

Details

The weighted scoring rules in scores_sample_univ_weighted and scores_sample_multiv_weighted require a weight or chaining function argument (weight_func or chain_func) to target particular outcomes. get_weight_func() can be used to obtain the relevant R function corresponding to commonly-used weight and chaining functions.

These commonly-used weight and chaining functions correspond to cumulative distribution functions (cdf's), probability density function (pdf's) and survival functions of the normal and logistic distributions. The name argument specifies the desired weight or chaining function. This must be one of 'norm_cdf', 'norm_pdf', 'norm_surv', 'logis_cdf', 'logis_pdf' and 'logis_surv', corresponding to the cdf, pdf and survival functions of the normal and logistic distribution, respectively.

mu and sigma represent the location and scale parameters of the normal or logistic distribution.

weight is a logical that specifies whether a weight or chaining function should be returned: if weight = TRUE (the default) the weight function is returned, and if weight = FALSE the chaining function is returned.

The normal weight and chaining functions are applicable in both the univariate and multivariate setting. In the univariate case, mu and sigma should be single numeric values. In the multivariate case, 'norm_cdf' and 'norm_pdf' represent the cdf and pdf of the multivariate normal distribution, with mean vector mu and covariance matrix diag(sigma). Here, mu and sigma are vectors with length equal to the dimension of the multivariate outcomes.

Note that get_weight_func() can currently only return multivariate weight and chaining functions corresponding to the multivariate normal distribution with a diagonal covariance matrix.

Value

A weight or chaining function.

Author(s)

Sam Allen

References

Gneiting, T. and R. Ranjan (2011): ‘Comparing density forecasts using threshold-and quantile-weighted scoring rules’, Journal of Business & Economic Statistics 29, 411-422. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1198/jbes.2010.08110")}

Allen, S., Ginsbourger, D. and J. Ziegel (2023): ‘Evaluating forecasts for high-impact events using transformed kernel scores’, SIAM/ASA Journal on Uncertainty Quantification 11, 906-940. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1137/22M1532184")}

See Also

scores_sample_univ_weighted and scores_sample_multiv_weighted for weighted scoring rules.

Examples

## Not run: 

## univariate
# generate data
y <- rnorm(10)
sample_fc <- matrix(rnorm(100), nrow = 10)

# normal cdf
mu <- 1
sigma <- 1

weight_func <- get_weight_func("norm_cdf", mu = mu, sigma = sigma)
chain_func <- get_weight_func("norm_cdf", mu = mu, sigma = sigma, weight = FALSE)
owcrps_sample(y = y, dat = sample_fc, weight_func = weight_func)
twcrps_sample(y = y, dat = sample_fc, chain_func = chain_func)

# results are the same if the weight function is input manually
weight_func <- function(x) pnorm(x, mu, sigma)
chain_func <- function(x) (x - mu)*pnorm(x, mu, sigma) + (sigma^2)*dnorm(x, mu, sigma)
owcrps_sample(y = y, dat = sample_fc, weight_func = weight_func)
twcrps_sample(y = y, dat = sample_fc, chain_func = chain_func)


# logistic pdf
mu <- 0
sigma <- 1

weight_func <- get_weight_func("logis_pdf", mu = mu, sigma = sigma)
chain_func <- get_weight_func("logis_pdf", mu = mu, sigma = sigma, weight = FALSE)
owcrps_sample(y = y, dat = sample_fc, weight_func = weight_func)
twcrps_sample(y = y, dat = sample_fc, chain_func = chain_func)


# normal survival function 
mu <- -1
sigma <- 1

weight_func <- get_weight_func("norm_surv", mu = mu, sigma = sigma)
chain_func <- get_weight_func("norm_surv", mu = mu, sigma = sigma, weight = FALSE)
owcrps_sample(y = y, dat = sample_fc, weight_func = weight_func)
twcrps_sample(y = y, dat = sample_fc, chain_func = chain_func)


## multivariate
d <- 3  # number of dimensions
m <- 10  # number of samples from multivariate forecast distribution

# generate samples from multivariate normal distributions
mu0 <- rep(0, d)
mu <- rep(1, d)
S0 <- S <- diag(d)
S0[S0==0] <- 0.2
S[S==0] <- 0.1

y <- drop(mu0 + rnorm(d) %*% chol(S0))
sample_fc <- replicate(m, drop(mu + rnorm(d) %*% chol(S)))

# component-wise normal cdf
mu <- rep(1, d)
sigma <- rep(1, d)

weight_func <- get_weight_func("norm_cdf", mu = mu, sigma = sigma)
chain_func <- get_weight_func("norm_cdf", mu = mu, sigma = sigma, weight = FALSE)
owes_sample(y = y, dat = sample_fc, weight_func = weight_func)
twes_sample(y = y, dat = sample_fc, chain_func = chain_func)


## End(Not run)


scoringRules documentation built on Sept. 18, 2024, 5:09 p.m.