# Sampling uniform distribution on a vector

**URL:** <https://discourse.mc-stan.org/t/sampling-uniform-distribution-on-a-vector/22931>\
**Category:** Modeling\
**Tags:** pystan, fitting-issues\
**Created:** [June 9, 2021, 1:13pm UTC](https://discourse.mc-stan.org/t/sampling-uniform-distribution-on-a-vector/22931 "2021-06-09T13:13:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SHINICHI](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/shinichi/32/9970_2.png) [@SHINICHI](https://discourse.mc-stan.org/u/SHINICHI)\
**Post date:** [June 9, 2021, 1:13pm UTC](https://discourse.mc-stan.org/t/sampling-uniform-distribution-on-a-vector/22931/1 "2021-06-09T13:13:04Z")

</div>

Hi,

I want to generate a uniform distribution on a vector.  
I wrote the following code. For the normal and inverse gamma distributions, they were generated on a three-column vector (and also appear to be uncorrelated).

However, when I try to generate the uniform distribution on “row\_vector[3]”, it returns the error “initalization failed”.  
Just to be sure, I specified “real” instead of “row\_vector[3]”, and the error did not occur and the uniform distribution was returned.

If you know how to generate an uncorrelated uniform distribution on a vector, please let me know.

Thank you.

#sampling only code

sampling\_code = “”"  
parameters {  
row\_vector[3] mu;  
// real phai;  
row\_vector[3] phai;  
row\_vector[3] eta;  
}

model {  
mu ~ normal(0, 10);  
phai ~ uniform(0, 1);  
eta ~ inv\_gamma(4,1);  
print(phai);

}  
“”"

---

<div class="post-metadata">

**Author:** ![andrjohns](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/andrjohns/32/15297_2.png) [@andrjohns](https://discourse.mc-stan.org/u/andrjohns)\
**Post date:** [June 9, 2021, 4:27pm UTC](https://discourse.mc-stan.org/t/sampling-uniform-distribution-on-a-vector/22931/2 "2021-06-09T16:27:10Z")

</div>

If you use a uniform prior you need to specify the corresponding `lower` and `upper` bounds in the parameter declaration:

```stan
row_vector<lower=0,upper=1>[3] phai

```

---

<div class="post-metadata">

**Author:** ![SHINICHI](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/shinichi/32/9970_2.png) [@SHINICHI](https://discourse.mc-stan.org/u/SHINICHI)\
**Post date:** [June 12, 2021, 1:57pm UTC](https://discourse.mc-stan.org/t/sampling-uniform-distribution-on-a-vector/22931/3 "2021-06-12T13:57:06Z")

</div>

Thank you very much for your kindness, the code worked without any errors.
