R: Cross-validation in the main effect logistic AIM
cv.logistic.main
R Documentation
Cross-validation in the main effect logistic AIM
Description
Cross-validation for selecting the number of binary rules in the main effect AIM with binary outcomes
Usage
cv.logistic.main(x, y, K.cv=5, num.replicate=1, nsteps, mincut=0.1, backfit=F, maxnumcut=1, dirp=0, weight=1)
Arguments
x
n by p matrix. The covariate matrix
y
n 0/1 vector. The binary response variable
K.cv
K.cv-fold cross validation
num.replicate
number of independent replications of K-fold cross validations.
nsteps
The maximum number of binary rules to be included in the index
mincut
The minimum cutting proportion for the binary rule at either end. It typically is between 0 and 0.2.
backfit
T/F. Whether the existing split points are adjusted after including a new binary rule
maxnumcut
The maximum number of binary splits per predictor
dirp
p vector. The given direction of the binary split for each of the p predictors. 0 represents "no pre-given direction"; 1 represents "(x>cut)"; -1 represents "(x<cut)". Alternatively, "dirp=0" represents that there is no pre-given direction for any of the predictor.
weight
a positive value. The weight given to responses. "weight=0" means that all observations are equally weighted.
Details
cv.logistic.main implements the K-fold cross-validation for the main effect logistic AIM. It estimates the score test statistics in the test set for testing the association between the binary outcome and index constructed using training data. It also provides pre-validated fits for each observation and the pre-validated score test statistic. The output can be used to select the optimal number of binary rules.
Value
cv.lm.main returns
kmax
the optimal number of binary rules based the cross-validation
meanscore
nsteps-vector. The cross-validated score test statistics (significant at 0.05, if greater than 1.96) for the association between survival time and index.
pvfit.score
nsteps-vector. The pre-validated score test statistics (significant at 0.05, if greater than 1.96) for the association between survival time and index.
preval
nsteps by n matrix. Pre-validated fits for individual observation
References
L Tian and R Tibshirani
Adaptive index models for marker-based risk stratification,
Tech Report, available at http://www-stat.stanford.edu/~tibs/AIM.
R Tibshirani and B Efron, Pre-validation and inference in microarrays,
Statist. Appl. Genet. Mol. Biol., 1:1-18, 2002.
Author(s)
Lu Tian and Robert Tibshirani
Examples
## generate data
set.seed(1)
n=500
p=20
x=matrix(rnorm(n*p), n, p)
z=(x[,1]<0.2)+(x[,5]>0.2)
beta=1
prb=1/(1+exp(-beta*z))
y=rbinom(n,1,prb)
## cross-validate the logistic main effects AIM
a=cv.logistic.main(x, y, nsteps=10, K.cv=5, num.replicate=3)
## examine the score test statistics in the test set
par(mfrow=c(1,2))
plot(a$meanscore, type="l")
plot(a$pvfit.score, type="l")
## construct the index with the optimal number of binary rules
k.opt=a$kmax
a=logistic.main(x, y, nsteps=k.opt)
print(a)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(AIM)
Loading required package: survival
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/AIM/cv.logistic.main.Rd_%03d_medium.png", width=480, height=480)
> ### Name: cv.logistic.main
> ### Title: Cross-validation in the main effect logistic AIM
> ### Aliases: cv.logistic.main
>
> ### ** Examples
>
> ## generate data
> set.seed(1)
> n=500
> p=20
>
> x=matrix(rnorm(n*p), n, p)
> z=(x[,1]<0.2)+(x[,5]>0.2)
> beta=1
> prb=1/(1+exp(-beta*z))
> y=rbinom(n,1,prb)
>
>
> ## cross-validate the logistic main effects AIM
> a=cv.logistic.main(x, y, nsteps=10, K.cv=5, num.replicate=3)
>
> ## examine the score test statistics in the test set
> par(mfrow=c(1,2))
> plot(a$meanscore, type="l")
> plot(a$pvfit.score, type="l")
>
>
> ## construct the index with the optimal number of binary rules
> k.opt=a$kmax
> a=logistic.main(x, y, nsteps=k.opt)
> print(a)
$res
$res[[1]]
jmax cutp maxdir maxsc
[1,] 5 0.2067592 1 6.209041
$res[[2]]
jmax cutp maxdir maxsc
[1,] 5 0.2067592 1 6.209041
[2,] 1 0.3295078 -1 8.023473
$maxsc
[1] 6.209041 8.023473
>
>
>
>
>
>
> dev.off()
null device
1
>