Thanks again to Dimitris C. Rizopoulos who suggested a different, more
efficient, way to obtain leave-one-out predictions for a series of models
(decreasing computing time from 250 to 49 min when three models were used). His
kind reply is copied below:
======== Dimitris C. Rizopoulos (25/05/2002)
model.1 <- lm(Fuel ~ Weight + Disp., fuel.frame)
model.2 <- lm(Fuel ~ Weight + Mileage, fuel.frame)
model.3 <- lm(Fuel ~ Weight + Type, fuel.frame)
model.4 <- lm(Fuel ~ Weight + Type+Mileage,
fuel.frame)
model.5 <- lm(Fuel ~ Weight + Type+Mileage+Disp.,
fuel.frame)
models <- list(model.1, model.2,
model.3,model.4,model.5)
##########
tic <- proc.time()
n <- nrow(fuel.frame)
predictions <- list(NULL)
for(i in 1:n) {
predictions[[i]] <- lapply(models, function(x){
model <- update(x, data = fuel.frame[-i,])
predict(model, newdata = fuel.frame[i,])})
}
tac <- proc.time() - tic
results <- matrix(unlist(predictions), nrow=n,
ncol=length(models), byrow=T)
dimnames(results) <- list(paste("observation", 1:n),
paste("model.", 1:length(models), sep=""))
CV.results <- colSums((results-fuel.frame$Fuel)^2)
tac
results
CV.results
===================================
Javier Seoane
Department of Applied Biology
Estación Biológica de Doñana, CSIC
Avda. María Luisa s/n
41013, Sevilla
SPAIN
|