# Error with stan model:

**URL:** <https://discourse.mc-stan.org/t/error-with-stan-model/19909>\
**Category:** Modeling\
**Tags:** specification\
**Created:** [December 21, 2020, 9:06pm UTC](https://discourse.mc-stan.org/t/error-with-stan-model/19909 "2020-12-21T21:06:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lortiz42](https://avatars.discourse-cdn.com/v4/letter/l/46a35a/32.png) [@Lortiz42](https://discourse.mc-stan.org/u/Lortiz42)\
**Post date:** [December 21, 2020, 9:06pm UTC](https://discourse.mc-stan.org/t/error-with-stan-model/19909/1 "2020-12-21T21:06:51Z")

</div>

I am attempting to build a simple multivariate normal example in stan using the target+= accumulator. I am doing this to learn how to code up a custom likelihood using the same format.  
However, I keep getting the same error and I can’t work out where it is coming from or how to resolve it.  
_No matches for:_  
_Available argument signatures for multi\_normal:_  
_Real return type required for probability function_

This occurs at line 33 in the stan file below.  
After checking for past posts in this forum regarding the issue, I believe that this is occurring due to me not understanding how the target+= vs ~ notation works but I have been unable to resolve it.  
Below I have also included my R code to fit the model.

```stan
data {
  int<lower=0> n;
  int<lower = 1> p;
  vector[p] x[n];
  vector[p] beta_0;
  matrix[p,p] sigma_0;
  matrix[p,p] sigma;
 }
parameters {
  real mu;
  real<lower=0> rho;
}
model {
  mu~multi_normal(beta_0,sigma_0);
  rho~inv_gamma(2, 2);
  target+=multi_normal_lpdf(x[n]|mu,rho*sigma);
  //y ~ normal(mu, sigma);
}

```

The data is embedded in the r code.

```
rm(list=ls())
library(rstan)
library(MASS)
  x <- matrix(c( .8, 102, 
                1.0, 98, 
                 .5, 100,
                 .9, 105, 
                 .7, 103, 
                 .4, 110,
                1.2, 99, 
                1.4, 87,
                 .6, 113,
                1.1, 89,
                1.3, 93), nrow=11, ncol=2, byrow=TRUE)
n<-nrow(x)
sigma_<-diag(c(1,1))
sigma_[1,2]<-.5
sigma_[2,1]<-.5
beta_0_=c(0,0)
sigma_0_=diag(c(.1,.1))
p=2
data_ <- list(x=x, 
             n=n,
             sigma=sigma_,
             p=2,
             beta_0=beta_0,
             sigma_0=sigma_0)
niter_ <- 3000   
nchains_ <- 4
full_fit <- stan('/D/Dissertation/Chapter2/R/Multivariate_Normal_Distribution_V01.stan', data = data_, 
                 iter = niter_, chains = nchains_, verbose = FALSE)

```

---

<div class="post-metadata">

**Author:** ![Lortiz42](https://avatars.discourse-cdn.com/v4/letter/l/46a35a/32.png) [@Lortiz42](https://discourse.mc-stan.org/u/Lortiz42)\
**Post date:** [December 21, 2020, 9:14pm UTC](https://discourse.mc-stan.org/t/error-with-stan-model/19909/2 "2020-12-21T21:14:30Z")

</div>

Just in case it wasn’t clear in the example the error:  
_No matches for:_  
_Available argument signatures for multi\_normal:_  
_Real return type required for probability function_  
occurs in the call:  
mu~multi\_normal(beta\_0,sigma\_0);

---

<div class="post-metadata">

**Author:** ![nhuurre](https://avatars.discourse-cdn.com/v4/letter/n/ad7895/32.png) [@nhuurre](https://discourse.mc-stan.org/u/nhuurre)\
**Post date:** [December 21, 2020, 9:33pm UTC](https://discourse.mc-stan.org/t/error-with-stan-model/19909/3 "2020-12-21T21:33:11Z")

</div>

Looks like the problem is that `mu` is declared with type `real`, a scalar. The multinormal distribution applies to vectors, not scalars.  
Try changing `mu` to a `vector`.

```stan
parameters {
  vector[p] mu;
  real<lower=0> rho;
}

```

---

<div class="post-metadata">

**Author:** ![Lortiz42](https://avatars.discourse-cdn.com/v4/letter/l/46a35a/32.png) [@Lortiz42](https://discourse.mc-stan.org/u/Lortiz42)\
**Post date:** [December 21, 2020, 11:40pm UTC](https://discourse.mc-stan.org/t/error-with-stan-model/19909/4 "2020-12-21T23:40:39Z")

</div>

Thank you! That cleared the error.  
So when I see this error in the future, does it generally just mean there is a mismatch between input types? Are there any other common cases that will cause it?

---

<div class="post-metadata">

**Author:** ![nhuurre](https://avatars.discourse-cdn.com/v4/letter/n/ad7895/32.png) [@nhuurre](https://discourse.mc-stan.org/u/nhuurre)\
**Post date:** [December 22, 2020, 9:17am UTC](https://discourse.mc-stan.org/t/error-with-stan-model/19909/5 "2020-12-22T09:17:19Z")

</div>

`No matches for ... Available matches for ...` always means there’s a type mismatch.
