<P>i have another problem maby cause by my inexperience in the following code in Rccp inline in the middle of the double cicle (just after ...<BR> for (j=0; j<n; j++) {.... in the abiut middle of code). maby the code is imprecise but i need to undertand (if it is possible) why this troule aris<BR>there is an assegnation th1=th0 but i have seen that it cames in mathematical sense : th0= th1 is the same of th1 =th0 but i dont want it becaus for (j=0; j<n; j++) {<BR>e this make for all iteratin exp(f1-f0) = 0 (except the number 1) because th0 came always the dame th1 like that th0 is the same of th1 ..<BR>and so vanish the metropolis ratio....this not happen in R "classic" i think it is a problem about pointer but im at the startin study c++ .Thank you and sorry for noise.....<BR>The folloing code<BR><BR>require(inline)<BR>code <- '<BR>RNGScope scope;<BR>NumericVector start_= as<NumericVector>(start);<BR>int n=Rf_length(start_);<BR>int N = as<int>(nsim);<BR>NumericVector tune = as<NumericVector>(scale);<BR>NumericMatrix U(N,n);<BR>NumericVector init (n);<BR>NumericVector th0 (n);<BR>NumericVector th1 (n);<BR>NumericMatrix store(N,n);<BR>NumericVector acount (n);<BR>NumericVector f0;<BR>NumericVector f1;<BR>Function ltd(fun);<BR>int i,j;<BR>init = start_;<BR>bool u;<BR>for( i=0; i<n; i++ ){<BR>th0[i] = init[i];<BR> }<BR>f0=ltd(th0); </P>
<P>for (i=0; i<N; i++) {<BR> for (j=0; j<n; j++) {<BR> th1=th0 ;<BR> th1[j] = Rf_rnorm(th0[j],tune[j]);<BR> f1=ltd(th1); <BR> u= Rf_runif(0.0,1.0) <= exp(f1[0] - f0[0]);<BR> if(u) {th0[j] = th1[j];<BR> f0 = f1;<BR> acount[j]++;<BR> }<BR> store(i,j)=th0[j];<BR> }<BR>}<BR>return List::create (Named("sim") = store, Named("acount") = acount,th0,th1,U);<BR>'</P>
<P>AM<- cxxfunction(signature(fun="function",start="numeric",nsim="numeric",scale="numeric"),<BR>code, plugin="Rcpp")<BR></P>