Learn R Programming

Coxnet (version 0.2)

coxsplit: Split Data for Cross-validation

Description

Specify which fold each observation is in to obtain foldid.

coxsplit randomly split data. coxsplity splits data by the `status' of y, and within each status, data is randomly split. coxsplitw splits data in the order of w.

Usage

coxsplit(y, nfolds)
coxsplity(y, nfolds)
coxsplitw(w, nfolds)

Arguments

y
response variable. y should be a two-column matrix with columns named `time' and `status'. The latter is a binary variable, with `1' indicating event, and `0' indicating right censored.
w
input vector, same length as y. The coefficients vary with w.
nfolds
number of folds.

Value

a vector of values between 1 and nfolds specifying which fold each observation is in.

Details

By default, coxsplit is incorporated in Coxnet and coxsplitw in loCoxnet. To use other data splitting method, generate foldid at the outset and supply it as an augment in Coxnet and loCoxnet.

See Also

Coxnet, loCoxnet, print.Coxnet

Examples

Run this code
set.seed(1213)
N=100
xb=rnorm(N)
ty=rexp(N,exp(xb))
tcens=rbinom(n=N,prob=.3,size=1)  # censoring indicator
y=cbind(time=ty,status=1-tcens)
foldid=coxsplit(y,10)  # 10-fold

Run the code above in your browser using DataLab