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

View source: R/genscore.R

get_h_hpR Documentation

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

Description

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

Usage

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 \boldsymbol{h}(\boldsymbol{x})=\mathrm{asinh}(\mathrm{para}\cdot\boldsymbol{x})=\log\left(\mathrm{para}\cdot\boldsymbol{x}+\sqrt{(\mathrm{para}\cdot\boldsymbol{x})^2+1}\right). Unbounded and takes one parameter. Equivalent to min_asinh(x, para, Inf).

cosh

A shifted cosh function \boldsymbol{h}(\boldsymbol{x})=\cosh(\mathrm{para}\cdot\boldsymbol{x})-1. Unbounded and takes one parameter. Equivalent to min_cosh(x, para, Inf).

exp

A shifted exponential function \boldsymbol{h}(\boldsymbol{x})=\exp(\mathrm{para}\cdot\boldsymbol{x})-1. Unbounded and takes one parameter. Equivalent to min_exp(x, para, Inf).

identity

The identity function \boldsymbol{h}(\boldsymbol{x})=\boldsymbol{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 \boldsymbol{h}(\boldsymbol{x})=\log(1+\boldsymbol{x})^{\mathrm{para}}. Unbounded and takes one parameter. Equivalent to min_log_pow(x, para, Inf).

mcp

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

min_asinh

A truncated asinh function applied element-wise: \min(\mathrm{asinh}(\mathrm{para}\cdot\boldsymbol{x}),\mathrm{para}_2). Bounded and takes two parameters.

min_asinh_ada

Adaptive version of min_asinh.

min_cosh

A truncated shifted cosh function applied element-wise: \min(\cosh(\mathrm{para}\cdot\boldsymbol{x})-1,\mathrm{para}_2). Bounded and takes two parameters.

min_cosh_ada

Adaptive version of min_cosh.

min_exp

A truncated shifted exponential function applied element-wise: \boldsymbol{h}(\boldsymbol{x})=\min(\exp(\mathrm{para}\cdot\boldsymbol{x})-1,\mathrm{para}_2). 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: \boldsymbol{h}(\boldsymbol{x})=\min(\log(1+\boldsymbol{x}),\mathrm{para}_2)^{\mathrm{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: \boldsymbol{h}(\boldsymbol{x})=\min(\boldsymbol{x},\mathrm{para}_2)^{\mathrm{para}}. Bounded and takes two parameters.

min_pow_ada

Adaptive version of min_pow.

min_sinh

A truncated sinh function applied element-wise: \min(\sinh(\mathrm{para}\cdot\boldsymbol{x}),\mathrm{para}_2). Bounded and takes two parameters.

min_sinh_ada

Adaptive version of min_sinh.

min_softplus

A truncated shifted softplus function applied element-wise: \min(\log(1+\exp(\mathrm{para}\cdot\boldsymbol{x}))-\log(2),\mathrm{para}_2). Bounded and takes two parameters.

min_softplus_ada

Adaptive version of min_softplus.

pow

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

scad

Treating \lambda=para, \gamma=para2, the step-wise SCAD function applied element-wise: \lambda x if x\leq\lambda, or (2\gamma\lambda x-x^2-\lambda^2)/(2(\gamma-1)) if \lambda<x<\gamma\lambda, or \lambda^2(\gamma+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 \boldsymbol{h}(\boldsymbol{x})=\sinh(\mathrm{para}\cdot\boldsymbol{x}). Unbounded and takes one parameter. Equivalent to min_sinh(x, para, Inf).

softplus

A shifted softplus function \boldsymbol{h}(\boldsymbol{x})=\log(1+\exp(\mathrm{para}\cdot\boldsymbol{x}))-\log(2). Unbounded and takes one parameter. Equivalent to min_softplus(x, para, Inf).

tanh

A tanh function \boldsymbol{h}(\boldsymbol{x})=\tanh(\mathrm{para}\cdot\boldsymbol{x}). Bounded and takes one parameter.

truncated_sin

A truncated sin function applied element-wise: \sin(\mathrm{para}\cdot x) if \mathrm{para}\cdot x\leq\pi/2, or 1 otherwise. Bounded and takes one parameter.

truncated_tan

A truncated tan function applied element-wise: \tan(\mathrm{para}\cdot x) if \mathrm{para}\cdot x\leq\pi/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

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 May 31, 2023, 6:28 p.m.