对于代码的混乱,我深表歉意,但我对 R 比较陌生,当我输入以下代码时:
for(t in 2:M)
{
alphcandidate=mvrnorm(1,Gibbsalph[,t-1],as.numeric(csquared*4.93)*Zyesinv)
r=exp((-1/2)*(t(rep(1,105))%*%Z%*%(alphacandidate-Gibbsalph[,t-1])+sum((lnyield-X%*%Gibbsbeta[,t-1])^2)%*%(exp(-Z%*%alphcandidate)-exp(-Z%*%Gibbsalph[,t-1]))+t(alphcandidate-rep(0,m))%*%(solve(as.numeric(100)*diag(m)))%*%(alphcandidate-rep(0,m))-t(Gibbsalph[,t-1]-rep(0,m))%*%(solve(as.numeric(100)*diag(m)))%*%(Gibbsalph[,t-1]-rep(0,m)))
if(runif(1)<min(1,r)) {
Gibbsalph[,t]=alphcandidate
} else{
Gibbsalph[,t]=Gibbsalph[,t-1]
}
Dbetanawinv=t(X)%*%(diag(as.vector(1/(exp(Z%*%Gibbsalph[,t])))))%*%X+solve(as.numeric(100)*diag(n))
Dbetach=chol(Dbetanawinv)
Dbetachinv=solve(Dbetach)
Dbeta=Dbetachinv%*%t(Dbetachinv)
dbeta=t(X)%*%(diag(as.vector(1/(exp(Z%*%Gibbsalph[,t])))))%*%lnyield+(solve(as.numeric(100)*diag(n))%*%(rep(0,n)))
Gibbsbeta[,t]=mvrnorm(1,Dbeta%*%dbeta,Dbeta)
}
我收到以下错误:错误:意外的“如果”在:“如果”
错误:“}”中出现意外的“}”
错误:“}”中出现意外的“}”
我不确定为什么这个 if 语句不能正常工作。对不起,我还不知道如何在这个网站上正确地格式化我的问题。任何帮助,将不胜感激!