Greetings!
I am trying to compare simulated environmental conditions from a model
against a recruitment time series for a species of crab by first dropping 5
data points, and then using the remainder to attempt to simulate the
missing data as a measure of best fit and using the following code:
all.mat<-as.matrix(comb,ncol=ncol(comb),nrow=nrow(comb))
obs<-as.matrix(R2,24,1)
mod<-all.mat
results<-numeric(ncol(mod))
for(i in mod) {
x<-mod[,i]
resid <- matrix(NA, 1000, 5)
for(k in 1:1000) {
sub<-sample(1:24,19)
fit<-lm(obs~x,subset=sub)
cf<-coef(fit)
p <- cf[1] + cf[2] * x[-sub]
resid[k,] <- obs[-sub] - p
}
results[i] <- mean(resid^2)
}
where* R2* is a 24x1 matrix with recruitment data, *comb* was a cbind()
object combining two matrices and *all.mat* is the final 565x24 matrix of
modeled environmental scenarios. When the script is run the first 99
scenarios are processed properly and I get readable output. At scenario 100
however, I get this message:
*Error in na.omit.data.frame(list(obs = c(0.414153096303487,
1.39649463342491, : subscript out of bounds*
Which I understand to mean that the bounds of the indicated vector/matrix
have been violated. I am however at a loss as to how to resolve this. Any
advice would be appreciated
Cheers!
JR
--
Jonathan Richar
Doctoral candidate
UAF SFOS Fisheries Division
17101 Pt. Lena Loop Rd.
University of Alaska Fairbanks
Juneau, AK 99801
Phone: (907) 796-5459
[[alternative HTML version deleted]]