cv.KLR: K-fold cross-validation for Kernel Logistic Regression

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/cv.KLR.R

Description

The function performs k-fold cross validation for kernel logistic regression to estimate tuning parameters.

Usage

1
2
cv.KLR(X, y, K = 5, lambda = seq(0.001, 0.2, 0.005), kernel = c("matern",
  "exponential")[1], nu = 1.5, power = 1.95, rho = seq(0.05, 0.5, 0.05))

Arguments

X

input for KLR.

y

input for KLR.

K

a positive integer specifying the number of folds. The default is 5.

lambda

a vector specifying lambda values at which CV curve will be computed.

kernel

input for KLR.

nu

input for KLR.

power

input for KLR.

rho

rho value at which CV curve will be computed.

Details

This function performs the k-fold cross-valibration for a kernel logistic regression. The CV curve is computed at the values of the tuning parameters assigned by lambda and rho. The number of fold is given by K.

Value

lambda

value of lambda that gives minimum CV error.

rho

value of rho that gives minimum CV error.

Author(s)

Chih-Li Sung <iamdfchile@gmail.com>

See Also

KLR for performing a kernel logistic regression with given lambda and rho.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
library(calibrateBinary)

set.seed(1)
np <- 10
xp <- seq(0,1,length.out = np)
eta_fun <- function(x) exp(exp(-0.5*x)*cos(3.5*pi*x)-1) # true probability function
eta_x <- eta_fun(xp)
yp <- rep(0,np)
for(i in 1:np) yp[i] <- rbinom(1,1, eta_x[i])

x.test <- seq(0,1,0.001)
etahat <- KLR(xp,yp,x.test)

plot(xp,yp)
curve(eta_fun, col = "blue", lty = 2, add = TRUE)
lines(x.test, etahat, col = 2)

#####   cross-validation with K=5    #####
##### to determine the parameter rho #####

cv.out <- cv.KLR(xp,yp,K=5)
print(cv.out)

etahat.cv <- KLR(xp,yp,x.test,lambda=cv.out$lambda,rho=cv.out$rho)

plot(xp,yp)
curve(eta_fun, col = "blue", lty = 2, add = TRUE)
lines(x.test, etahat, col = 2)
lines(x.test, etahat.cv, col = 3)

calibrateBinary documentation built on May 2, 2019, 4:20 a.m.