get_h_hp: Generator of h and hp (derivative of h) functions.

Description Usage Arguments Details Value Examples

View source: R/genscore.R

Description

Generator of h and hp (derivative of h) functions.

Usage

1
get_h_hp(mode, para = NULL, para2 = NULL)

Arguments

mode

A string, see details.

para

May be optional. A number, the first parameter. Default to NULL.

para2

May be optional. A number, the second parameter. If mode is one of the adaptive mode below, this specifies the percentile (see details). Default to NULL.

Details

The mode parameter can be chosen from the options listed below along with the corresponding definitions of h under appropriate choices of para and para2 parameters. Unless otherwise noted, para and para2, must both be strictly positive if provided, and are set to 1 if not provided. Functions h and hp should only be applied to non-negative values x and this is not enforced or checked by the functions. Internally calls get_h_hp_vector.

asinh

An asinh function h(x)=asinh(para*x)=log(para*x+sqrt((para*x)^2+1)). Unbounded and takes one parameter. Equivalent to min_asinh(x, para, Inf).

cosh

A shifted cosh function h(x)=cosh(para*x)-1. Unbounded and takes one parameter. Equivalent to min_cosh(x, para, Inf).

exp

A shifted exponential function h(x)=exp(para*x)-1. Unbounded and takes one parameter. Equivalent to min_exp(x, para, Inf).

identity

The identity function h(x)=x. Unbounded and does not take any parameter. Equivalent to pow(x, 1) or min_pow(x, 1, Inf).

log_pow

A power function on a log scale log(1+x)^para. Unbounded and takes one parameter. Equivalent to min_log_pow(x, para, Inf).

mcp

Treating λ=para, γ=para2, the step-wise MCP function applied element-wise: λx-x^2/(2γ) if x<=λγ, or γλ^2/2 otherwise. Bounded and takes two parameters.

min_asinh

A truncated asinh function applied element-wise: pmin(asinh(para*x), para2). Bounded and takes two parameters.

min_asinh_ada

Adaptive version of min_asinh.

min_cosh

A truncated shifted cosh function applied element-wise: pmin(cosh(para*x)-1, para2). Bounded and takes two parameters.

min_cosh_ada

Adaptive version of min_cosh.

min_exp

A truncated shifted exponential function applied element-wise: pmin(exp(para*x)-1, para2). Bounded and takes two parameters.

min_exp_ada

Adaptive version of min_exp.

min_log_pow

A truncated power on a log scale applied element-wise: pmin(log(1+x), para2)^para. Bounded and takes two parameters.

min_log_pow_ada

Adaptive version of min_log_pow.

min_pow

A truncated power function applied element-wise: pmin(x, para2)^para. Bounded and takes two parameters.

min_pow_ada

Adaptive version of min_pow.

min_sinh

A truncated sinh function applied element-wise: pmin(sinh(para*x), para2). Bounded and takes two parameters.

min_sinh_ada

Adaptive version of min_sinh.

min_softplus

A truncated shifted softplus function applied element-wise: pmin(log(1+exp(para*x))-log(2), para2). Bounded and takes two parameters.

min_softplus_ada

Adaptive version of min_softplus.

pow

A power function h(x)=x^para. Unbounded and takes two parameter. Equivalent to min_pow(x, para, Inf).

scad

Treating λ=para, γ=para2, the step-wise SCAD function applied element-wise: λx if x<=λ, or (2γλx-x^2-λ^2)/(2(γ-1)) if λ<x<γλ, or λ^2(γ+1)/2 otherwise. Bounded and takes two parameters, where para2 must be larger than 1, and will be set to 2 by default if not provided.

sinh

A sinh function h(x)=sinh(para*x). Unbounded and takes one parameter. Equivalent to min_sinh(x, para, Inf).

softplus

A shifted softplus function h(x)=log(1+exp(para*x))-log(2). Unbounded and takes one parameter. Equivalent to min_softplus(x, para, Inf).

tanh

A tanh function h(x)=tanh(para*x). Bounded and takes one parameter.

truncated_sin

A truncated sin function applied element-wise: sin(para*x) if para*x<=π/2, or 1 otherwise. Bounded and takes one parameter.

truncated_tan

A truncated tan function applied element-wise: tan(para*x) if para*x<=π/4, or 1 otherwise. Bounded and takes one parameter.

For the adaptive modes (names ending with "_ada"), h and hp are first applied to x without truncation. Then inside each column, values that are larger than the para2-th quantile will be truncated. The quantile is calculated using finite values only, and if no finite values exist the quantile is set to 1. For example, if mode == "min_pow_ada", para == 2, para2 == 0.4, the j-th column of the returned hx will be pmin(x[,j]^2, stats::quantile(x[,j]^2, 0.4)), and the j-th column of hpx will be 2*x[,j]*(x[,j] <= stats::quantile(x[,j]^2, 0.4)).

Value

A function that returns a list containing hx=h(x) (element-wise) and hpx=hp(x) (element-wise derivative of h) when applied to a vector (for mode names not ending with "_ada" only) or a matrix x, with both of the results having the same shape as x.

Examples

1
2
3
4
5
6
7
8
get_h_hp("mcp", 2, 4)(0:10)
get_h_hp("min_log_pow", 1, log(1+3))(matrix(0:11, nrow=3))
get_h_hp("min_pow", 1.5, 3)(seq(0, 5, by=0.5))
get_h_hp("min_softplus")(matrix(seq(0, 2, by=0.1), nrow=7))

get_h_hp("min_log_pow_ada", 1, 0.4)(matrix(0:49, nrow=10))
get_h_hp("min_pow_ada", 2, 0.3)(matrix(0:49, nrow=10))
get_h_hp("min_softplus_ada", 2, 0.6)(matrix(seq(0, 0.49, by=0.01), nrow=10))

genscore documentation built on April 28, 2020, 1:06 a.m.