cvPredictions: cvPredictions - get cross-validated predictions

Description Usage Arguments Value Author(s) Examples

Description

Given a fitted object for which a "predict" method exists (eg from lm() or coxph()), make cross-validated predictions. Note that sample order is maintained, but sample names are not. In the output, a sample name of 4.1 for example, means fold 4, sample 1. Function by Markus Riester.

Usage

1
cvPredictions(fit, data, y = data$y, ...)

Arguments

fit

fit object as returned by lm(), glm(), coxph(), and probably others for which a predict() method exists.

data

a dataframe containing data with which to make cross-validated predictions. Generally should be the same dataframe used to create fit.

y

response variable, by default the column "y" in data.

...

additional variables passed on to cvTools::cvFolds

Value

returns the output of predict(), on left-out samples from cross-validation. In the output, a sample name of 4.1, for example, means fold 4 sample 1.

Author(s)

Levi Waldron and Markus Riester

Examples

1
2
3
4
5
6
7
8
9
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
mydata <- data.frame(group  = gl(2,10,20, labels=c("Ctl","Trt")),
                     weight = c(ctl, trt))
lm.D9 <- lm(weight ~ group, data=mydata)
##non cross-validated predictions:
predict(lm.D9)
##cross-validated predictions.  
cvPredictions(lm.D9, data=mydata, y=mydata$weight)

lwaldron/LeviRmisc documentation built on May 21, 2019, 8:59 a.m.