[R] Whitespace
Miguel Angel Hombrados Herrera
mangelhombradosherre at unm.edu
Mon May 1 06:57:43 CEST 2017
Hello
Ive been working on a stan program in Rstudio. Im kind of new on this, so probably my question is trivial, However I was not able to find information about this.
The error Im getting when I run my stan code is:
PARSER EXPECTED: whitespace to end of file.
FOUND AT line 2:
The code is:
iter=500
alphamcmc=matrix(0,ncol=J,nrow=iter)
betamcmc=NULL
mu_alpha=NULL
sigma_alpha_2=NULL
sigma_y_2=NULL
#set initial values
alphamcmc[1,]=rep(mean(y),J)
betamcmc[1]=70
mu_alpha[1]=mean(y)
sigma_alpha_2[1]=300
sigma_y_2[1]=350
#mcmc iteration
for(m in 2:iter){
#update alpha vector
for(j in 1:J){
sj=sum(source==j)
var=1/(sj/sigma_y_2[m-1]+1/sigma_alpha_2[m-1])
temp=0
for(i in 1:N){temp=temp+1*(source[i]==j)*(y[i]-betamcmc[m-1]*x[i])}
#sum up (y_i-beta x_i ) for those belonging to group j
mean=var*(temp/sigma_y_2[m-1]+mu_alpha[m-1]/sigma_alpha_2[m-1])
alphamcmc[m,j]=rnorm(1,mean,sqrt(var))
}
#update beta
var=sigma_alpha_2[m-1]/(sum(x^2))
mean=sum(x%*%(y-alphamcmc[m,source])/sum(sum(x^2)))
betamcmc[m]=rnorm(1,mean,sqrt(var))
#update mu_alpha
#update sigma_alpha_2
sigma_alpha_2[m]=rinvgamma(1,shape=J/2,rate=sum((alphamcmc[m,]
-mu_alpha[m])^2/2))
#update sigma_y_2
sigma_y_2[m]=rinvgamma(1,shape=N/2,rate=sum((y-alphamcmc[m,source]-
betamcmc[m]*x)^2/2))
}
nburn=200
apply(alphamcmc[(nburn+1):iter,],2,mean)
apply(betamcmc[(nburn+1):iter],2,mean)
Ive been searching for wrong spaces or tabulations, but I was not able to find anything.
I really would appreciate your help.
Thaknk you.
[[alternative HTML version deleted]]
More information about the R-help
mailing list