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]]
> 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... Presumably because you haven't learned to use R's debugging tools. So time to learn. See the "debugging" Chapter of the R Language Manual and the Help files of the referenced functions. Also ?recover and set the error option as described there so you can browse in the frame in which the error was triggered. Also check ?traceback Someone (but not me!) may have the patience to go thru your code and pick out the error(s); but if you write code, you need to learn how to debug code for yourself instead of posting to the list every time. Consider it part of your doctoral training. Cheers, Bert> > 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]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm