標識再捕獲データをシミュレートしています。以下の簡略化された例では、3つのサンプリング期間(列)にわたって10人の個人(行)を持つマトリックスがあります。それらが生きているか(1)死んでいるか(0)、調査領域に存在するかどうか(1)かどうか(0)を追跡するマトリックスと、記入しようとしているマトリックスがあります。各期間でキャプチャされた(1)またはキャプチャされなかった(0)。
私の実際の例では、1000人を超える180の列があり、forループを高速化したいと考えています。以下のループ(各個人と各行をループする)では、現在の個人が死亡していることが判明したら、次の個人にジャンプできるようにしたいと思います。if / elseステートメントを使用してこれを試してみました。ここで、「is.alive = / 1」の場合、「j」の値(サンプリング期間を繰り返す)が最終値の3に進みます。私は次の個人に進むために、しかし私は得ることになります
"Error in ifelse(is.alive == 1, ifelse(is.pres == 1, ifelse(runif(1) <=:
unused argument(s) (j = 3)"
何かアドバイス?
survival.mat<-matrix(1,10,3) #Matrix tracking 10 individuals (rows) over 3 time periods (columns)
survival.mat[c(2,4,6),c(2,3)]<-0 #Creating some deaths (1=alive, 0=dead)
present.mat<-survival.mat #A new matrix to see if individuals are present for capture
present.mat[c(1,5,8),2]<-0 #Making some alive individuals unavailable (0) for capture
capture.mat<-matrix(0,10,3) #A matrix to test if individuals were captured
capture.mat[,1]<-1 #All individuals captured on first occasion, since this is when they are marked
cap.prob<-0.5 #our probability of capture
for(i in 1:10){ #Iterating through the rows (each row is an individual)
for(j in 2:3){ #Iterating through columns (each column is a time period)
is.alive <- survival.mat[i,j]
is.pres <- present.mat[i,j]
ifelse(is.alive==1, #If the individual is alive, continue, if not jump ahead to 'j=3' which is what I am using to try to advance the loop
ifelse(is.pres==1,ifelse(runif(1)<=cap.prob,capture.mat[i,j]<-1,NA),NA)#If it is alive (previous statement), is it present for capture? If so, run a capture coinflip.
,j=3) #Trying to advance the simulation to j = 3 if the individual is not alive
}
}