I'm relatively new to R; this is my first post on Stack Overflow. There should be a simple solution to this, but I haven't been able to figure it out.
The R code in "A" below creates a vector of 9 models of interest that I'd like to run through 10-fold cross validation (if it helps, models are at bottom of this post). I'd like to run this code ...
modelList <- read.csv("/Users/XX/Desktop/Academic/XX/XX/R/Core_Files/models.csv",header=F)$V1
set.seed(17)
cv.error.9=rep(NA,9)
for(i in modelList){
cv.error.9[i]=cv.glm(collapsed_Y,eval(parse(text=paste("Mod",i,sep=""))),K=10)$delta[1]
}
cv.error.9
... (or something like it) and have the 'NA' in row cv.error.9[i] be replaced with the CV errors corresponding to model 'i'. I'd like the following table as my output.
x
1 2.734539
2 2.710424
3 2.760761
4 2.564147
5 2.583432
6 2.681044
7 2.583303
8 2.570110
9 2.635983
Unfortunately, the code in "A" is not replacing rows cv.error.9[i], but rather appending test error rates to the end of vector cv.error.9, as shown here:
x
1 0.000000
2 0.000000
3 0.000000
4 0.000000
5 0.000000
6 0.000000
7 0.000000
8 0.000000
9 0.000000
10 2.734539
11 2.710424
12 2.760761
13 2.564147
14 2.583432
15 2.681044
16 2.583303
17 2.570110
18 2.635983
Showing 1 to 18 of 18 entries, 1 total columns
Any help with this would be appreciated. Many thanks in advance.
Models:
print(modelList)
[1] <- glm(y ~ X1 + X2 + X3 + X4 + X5 + X6, family=gaussian, data=collapsed_Y)
[2] <- glm(y ~ X1 + X2 + X3 + X4 + X5 + X6 + X7 , family=gaussian, data=collapsed_Y)
[3] <- glm(y ~ X1 + X2 + X3 + X4 + X5 + X6 + X7 + X4*X5, family=gaussian, data= collapsed_Y)
[4] <- glm(y ~ X1 + X2 + X3 + X4 + X5 + X6, family=poisson, data= collapsed_Y)
[5] <- glm(y ~ X1 + X2 + X3 + X4 + X5 + X6 + X7, family=poisson, data= collapsed_Y)
[6] <- glm(y ~ X1 + X2 + X3 + X4 + X5 + X6 + X7 + X4*X5, family=poisson, data= collapsed_Y)
[7] <- glm.nb(y ~ X1 + X2 + X3 + X4 + X5 + X6, data= collapsed_Y)
[8] <- glm.nb(y ~ X1 + X2 + X3 + X4 + X5 + X6 + X7, data= collapsed_Y)
[9] <- glm.nb(y ~ X1 + X2 + X3 + X4 + X5 + X6 + X7 + X4*X5, data= collapsed_Y)
9 Levels: <- glm.nb(y ~ X1 + X2 + X3 + X4 + X5 + X6 + X7 + X4*X5, data= collapsed_Y) ...