Well spotted, the b is a muck up (what happens when you are basing stuff on someone else's code). The bit you though might be a dimension mismatch seems to work ok, but the bit that I was worried about from the start doesn't; the reason I have sqrt of var y/ var x is because my posterior is for a reduced major axis regression, that is the slope, but I somehow thought R might spit that back at me. I might have to go back to the drawing board, and find a different way of doing the posterior.
I get this, having fixed the algorithm. > vx=sd(x) > vy=sd(y) > s2y=matrix(vy,m) > s2x=matrix(vx,m) > #begin MH sampling > for(i in 2:m){ + for(j in vy){s2y[i,j]=s2y[i-1,j]+rnorm(1,mean=0,sd=s2yscale[j]);acc=1} + if((post(y,x,s2ey[i-1],s2x,s2y[i])-post(y,x,s2ey[i-1],s2x,s2y[i-1]))<log(runif(1,min=0,max=1))){s2y[i,j]=s2y[i-1,j]; acc=0} + accrate[i,j]=(accrate[i-1,j]*(i-1)+acc)/i} Error in x * s2y/s2x : non-conformable arrays Ned David Winsemius wrote: > > The comma *before* acc=1 ? > > I also wondered whether (further up) this should work: > s2y[i,]=s2y[i-1] # would think this to result in a dimension mismatch > > This looks sketchy as well: > s2y[i,j] = s2y[b[i-1,j] + rnorm(1,mean=0, sd=s2yscale[j]) > ^ ^ ^ # unmatched sqr-brackets > > It would be easier to run through a paren matching editor if you gave > the original loop code as well as the error output. > -- > David Winsemius > > > -- View this message in context: http://www.nabble.com/MH-algorithm-syntax-help-tp21534889p21553281.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.