Cannot replicate a matrix in paramter block

Hi There,

I am trying to devleop a multiple bayesian change model according to the stan manual:

However in my stan model, as I am trying to define a matrix for log_p = rep_matrix(-log(N),N); the stan gaves me error that “No Match for available argument signature for rep_matrix”. However I checked both manual and the tutrial which they used this function. Could you help me why I give this error?

transformed parameters {
      matrix[N,N] log_p;
      real mu;
      real sigma;
      log_p = rep_matrix(-log(N),N);
      for (tau in 1:N)
       for(tau2 in 1:N){
        for (i in 1:N) {
          mu = i < tau ? (mu1 * x[i] + gamma1) :(i < tau2 ?(mu2 * x[i] + gamma2):(mu3 * x[i] + gamma3));
          sigma = i < tau ? sigma1 : (i < tau2 ? sigma2:sigma3);
          log_p[tau,tau2] = log_p[tau,tau2] + normal_lpdf(y[i] | mu, sigma);

If you’re using rep_matrix() to fill a matrix with a single scalar value (i.e., -log(N)), you need to provide both the number of rows and the number of columns that you want to create:

log_p = rep_matrix(-log(N), N, N);
1 Like

Thank you very much andrew. It is now working

Dear Andrew, so in the stan manual this should be correcet. beacuse it seems that they forgot to correctly use rep_matrix(***, N, N) as you kindly mentions here

Which section of the manual are you referring to? Because if you pass a vector or row-vector to rep_matrix(), then only one size is needed

I read this section which i immagine it is not a vector

Yep that’s a typo, thanks for catching!

1 Like