thank you for your help in advance. I am new to R, so please overlook any glaring errors in my code.
I am trying to replace each non-zero value in a matrix with arrays that I created. Here is what I have so far:
totalsquares<-matrix(data=rbinom(225,1,0.65), nrow=15, ncol=15, byrow=TRUE)
samplesquares <- sum(totalsquares)
totalsquares[totalsquares == 1] <- rpois(samplesquares,30)
urchins<-sum(totalsquares)
for(rowcount in 1:15){
for(colcount in 1:15){
if(totalsquares[rowcount, colcount] != 0){
capprob<-rbeta(1,0.48,0.12)
cmr<-array(data=rbinom((5*totalsquares[rowcount,colcount]), 1, capprob), c(totalsquares[rowcount, colcount],5,samplesquares))
}
}
}
The idea here was to create a grid representing my sampling area, then I'd sample approximately 65% of it. Each square where I'd sample, I'd have some number of urchins based off a density of about 30/square.
The loop is to create encounter histories for a capture-mark-recapture model. It is supposed to create an array of binomial data for each sampled square, with the dimensions being the number of sampled individuals by 5 occasions by the number of the square.
The main problem is that I can't figure out how to replace the values in the matrix with the array representing that sample. I also don't think my loop is working properly, as it keeps having the same number of rows for each array when they should be different for each.
Any help is appreciated!