ush.test: Testing for U-shape relation

View source: R/31_U_SHAPE.R

ush.testR Documentation

Testing for U-shape relation

Description

ush.test performs U-shape testing between the target and analyzed risk factor. Testing is based on B-splines basis functions and change of the sign of the estimated coefficients.

Usage

ush.test(
  x,
  y,
  p.value = 0.05,
  min.pct.obs = 0.05,
  min.pct.def = 0.01,
  g = 20,
  sc = c(NA, Inf, -Inf, NaN)
)

Arguments

x

Numeric vector to be tested for U-shape.

y

Numeric target vector (binary).

p.value

Threshold for p-value of statistical significance of the estimated coefficients next to basis functions. Default is 0.05.

min.pct.obs

Minimum percentage of observations per bin. Default is 0.05.

min.pct.def

Minimum y average rate. Default is 0.01 or minimum 1 bad case for y 0/1.

g

Number of knots used for testing the U-shape (integer). It should take values between 2 and 50 with default value of 20.

sc

Numeric vector with special case elements. Default values are c(NA, NaN, Inf, -Inf). Recommendation is to keep the default values always and add new ones if needed. Otherwise, if these values exist in x and are not defined in the sc vector, function can report the error.

Value

The command ush.test returns list of three objects. The first object (candidates) is the data frame with summary of tested candidate knots. Using the reported results of this data frame user can conclude if U-shape exists at all (column where direction is equal to TRUE) and check its statistical significance (column significance - TRUE, FALSE). The second object (optimal) reports optimal knot value (if exists). It is selected as the knot with minimum deviance among all candidates for which direction and significance are equal to TRUE. The last, third, object (basis.functions) exports basis functions for optimal knot. Basis functions will be exported only in case optimal knot is found.
If optimal knot is not found, then users are encouraged to inspect closer the results of candidate testing.

Examples

data(gcd)
res <- ush.test(x = gcd$amount, y = gcd$qual)
res 
#optimal knot is not found so candidate can be defined as follows:
direction.t <- res$candidate[res$candidate$direction, ]
optimal.k <- direction.t$cp[direction.t$deviance%in%min(direction.t$deviance)]
optimal.k

PDtoolkit documentation built on Sept. 20, 2023, 9:06 a.m.