title: How to deal with the missing data in stan?
body: <p>I am a newbie to stan and I am implementing the probabilistic matrix factorization model. </p>
  
  <p>Given a user-item rating matrix:</p>
  
  <pre><code>                       item
   user     1    3   NA   4     5    NA
            2    0    3   NA    1     5
            1    1    NA  NA    NA    0
            ....
  </code></pre>
  
  <p>How should I represent the observable data in the <code>data</code> block and the missing data for prediction in the <code>parameter</code> block? </p>
  
  <p>Thank you in advance!</p>
  
  <p>EDIT:</p>
  
  <p>Now I am implementing the model as below:</p>
  
  <pre><code>pmf_code = """
  data {
  
  int&lt;lower=0&gt; K; //number of factors
  int&lt;lower=0&gt; N; //number of user
  int&lt;lower=0&gt; M; //number of item
  int&lt;lower=0&gt; D; //number of observation
  int&lt;lower=0&gt; D_new; //number of pridictor 
  int&lt;lower=0, upper=N&gt; ii[D]; //item 
  int&lt;lower=0, upper=M&gt; jj[D]; //user
  int&lt;lower=0, upper=N&gt; ii_new[D_new]; // item
  int&lt;lower=0, upper=N&gt; jj_new[D_new]; // user
  real&lt;lower=0, upper=5&gt; r[D]; //rating
  real&lt;lower=0, upper=5&gt; r_new[D_new]; //pridict rating
  
  }
  
  parameters {
  row_vector[K] i[M]; // item profile
  row_vector[K] u[N]; // user profile
  real&lt;lower=0&gt; alpha;
  real&lt;lower=0&gt; alpha_i;
  real&lt;lower=0&gt; alpha_u;
  
  }
  transformed parameters {
  matrix[N,M] I; // indicator variable
  I &lt;- rep_matrix(0, N, M);
  for (d in 1:D){
      I[ii[d]][jj[d]] &lt;- 1;
  }
  }
  model {
  for (d in 1:D){
      r[d] ~ normal(u[jj[d]]' * i[ii[d]], 1/alpha);
  }
  
  for (n in 1: N){
      u[n] ~ normal(0,(1/alpha_u) * I);
  }
  for (m in 1:M){
      i[m] ~ normal(0,(1/alpha_i) * I);
  }
  }
  generated_quantities{
  for (d in 1:D_new){
      r_new[d] &lt;- normal(u[jj_new[d]]' * i[ii_new[d]], 1/alpha);
  }
  }
  """     
  </code></pre>
  
  <p>but got an <code>No matches for: real ~ normal(matrix, real)</code> error in this line of code:</p>
  
  <pre><code>for (d in 1:D){
      r[d] ~ normal(u[jj[d]]' * i[ii[d]], 1/alpha);
  }
  </code></pre>
  
  <p>But the <code>jj[d]</code> should be a integer, denoting the id of <code>user</code>. And u[<code>int</code>] should be a <code>row_vector</code> has <code>k</code> factors and so is <code>i[ii[d]]</code>. The product of them should be a single real value, why stan said it was a <code>matrix</code>?</p>