我正在使用模拟中的参数估算值。
n是具有10个级别的因子(36到144,乘以12),n =样本大小。 模拟可以有3个生存选项(phi.set)中的1个,我已将这些选项放在称为s的向量中。 该模拟可以具有3个捕获概率(p.set)选项之一,我将这些选项放在称为p的向量中。 phi和p是基于phi.set和p.set的参数估计值(数字)。我的模拟对n,phi.set和p.set的每个唯一组合进行了100个估计(分别为phi和p)。我想将每个估算值放入与其n,phi.set和p.set相对应的行中。
我正在努力弄清楚如何索引我制作的空矩阵,以便将模拟输出放置在适当的行中。
nboot=100 #specify number of bootstraps to run
n.s<-seq(36,150,12)
p <- c(.75, 0.9, 1)
s <- c(0.6, 0.65, 0.7)
phi.matrix <- matrix(NA, nrow=length(n.s)*nboot*length(p)*length(s),
ncol=5) #a matrix to hold results (all values set to NA), col1=n, col2=phi
estimate col3=p estimate, col4=phi setting, col5=p setting.
for (g in 1:length(n.s)){
for (f in 1:nboot) {
for(d in 1:length(s)){
for(e in 1:length(p)){
S = matrix(s[d],nrow=relYears,ncol=recYears) # survival after the first occasion
p = matrix(p[e],nrow=relYears,ncol=recYears) #recovery after the first occasion
#dont worry about the simulation itself... i've abbreviated it because it
isn't important to my question!
simmod <- mark(sim.proc, sim.ddl, model.parameters =
list(Phi=Phi.sim, p=p.sim))
Phi.estimates=get.real(simmod,"Phi")
bootphi<-Phi.estimates[[1]]$pim[1,1]
p.estimates=get.real(simmod,"p")
bootp<-p.estimates[[1]]$pim[1,1]
#these indices with the blank row spot is where I need help!!
phi.matrix[,1]<-n.s[g]
phi.matrix[,2]<-bootphi
phi.matrix[,3]<-bootp
phi.matrix[,4]<-s[d]
phi.matrix[,5]<-p[e]
}
}
}
}
我要结束的矩阵的开头应该看起来像(尽管,我在此处添加了“ n.boot”列作为参考:
n phi p phi.set p.set n.boot
1 36 0.58 0.72 0.6 0.75 1
2 36 0.53 0.72 0.6 0.9 1
3 36 0.59 0.75 0.6 1.0 1
4 36 0.58 0.71 0.65 0.75 1
5 36 0.57 0.71 0.65 0.9 1
6 36 0.57 0.72 0.65 1.0 1
7 36 0.58 0.73 0.7 0.75 1
8 36 0.58 0.74 0.7 0.9 1
9 36 0.54 0.72 0.7 1.0 1
10 36 0.52 0.75 0.6 0.75 2
11 36 0.58 0.76 0.6 0.9 2
12 36 0.59 0.77 0.65 1.0 2
13 36 0.6 0.72 0.65 0.75 2
14 36 0.61 0.71 0.65 0.9 2
15 36 0.58 0.74 0.6 1.0 2
...
n将由36乘以12变为144,每个唯一的n将具有nboot指定的迭代次数(即1000次迭代)。
我想要一个索引,将每个新模拟的估计值放入与产生该估计值的n,phi设置和p设置相对应的行中。
感谢您的时间!