我正在使用r并且我想使用cbind命令来获取rho的每个值的结果。但是为rho的每个值获取一个值而不是n = 3
delete [5]array;
答案 0 :(得分:0)
muy=100 ;mux=50 ; sigy=10; sigx=7
n=3;sim=5;rho=seq(-1,1,0.5)
ybark<-list()
for(j in 1:length(rho)){
for(i2 in 1:sim)
{
z1 = rnorm(n)
z2= rnorm(n)
x = sqrt(1-rho[j]^2)*sigx*z1[j] + rho[j]*sigx*z2[j] + mux
y = sigy*z2[j] + muy
ybark[[paste(j,i2,sep="_")]] = (mean(y)*mean(x))/mux
}
}
n<-length(ybark)/length(rho);grp<-rep(1:n,each=sim)
tapply(ybark,grp,function(x)matrix(x,nrow=1))
是你想要的吗?
$`1`
[,1] [,2] [,3] [,4] [,5]
[1,] 99.88803 92.99583 101.0367 98.73194 99.4599
$`2`
[,1] [,2] [,3] [,4] [,5]
[1,] 111.9889 87.19593 111.1355 86.76358 91.04678
$`3`
[,1] [,2] [,3] [,4] [,5]
[1,] 135.2721 93.4944 71.71243 121.4449 84.8635
$`4`
[,1] [,2] [,3] [,4] [,5]
[1,] NA NA NA NA NA
$`5`
[,1] [,2] [,3] [,4] [,5]
[1,] NA NA NA NA NA