# Mismatch in dimensions - 2x2 matrix reading as dimensionless object

**URL:** <https://discourse.mc-stan.org/t/mismatch-in-dimensions-2x2-matrix-reading-as-dimensionless-object/34189>\
**Category:** Modeling\
**Tags:** cmdstan\
**Created:** [February 20, 2024, 11:44pm UTC](https://discourse.mc-stan.org/t/mismatch-in-dimensions-2x2-matrix-reading-as-dimensionless-object/34189 "2024-02-20T23:44:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lizlawler](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/lizlawler/32/15997_2.png) [@lizlawler](https://discourse.mc-stan.org/u/lizlawler)\
**Post date:** [February 20, 2024, 11:44pm UTC](https://discourse.mc-stan.org/t/mismatch-in-dimensions-2x2-matrix-reading-as-dimensionless-object/34189/1 "2024-02-20T23:44:11Z")

</div>

ETA: Please ignore this entire post. After taking a break from this, I came back and realized my naming conventions were not the same between my json data list and the data block of the model. I tried to delete the post but it appears to still keep a record of it in the list of topics, so I figured I’d un-delete it and at least make it clear that this was entirely an issue on my end and nothing more than that. Sorry to bother!

* * *

I’m having an issue with reading in a simple 2x2 matrix from a cmdstan json file. I keep getting the error:

```no-highlight
Exception: mismatch in number dimensions declared and found in context; processing stage=data initialization; variable name=iden_matrix; dims declared=(2,2); dims found=() 

```

* * *

Here’s a brief example that produces the issue. I’ve generated the data in `R` as follows:

```r
x <- mvtnorm::rmvnorm(100, mean = c(0,0), 
                      sigma = matrix(c(1, 0.5, 0.5, 1), nrow = 2))
example_data <- list(X = x,
                 N = nrow(x),
                 d = ncol(x), 
                 iden_mat = matrix(c(1,0,0,1), nrow = 2),
                 rho_mat = matrix(c(0,1,1,0), nrow = 2))
cmdstanr::write_stan_json(example_data, "example.json")

```

The model code is as follows (saved as `example.stan`):

```stan
data {
  int<lower=0> N;
  int<lower = 0> d;
  matrix[N, d] X;
  matrix[d, d] iden_matrix;
  matrix[d, d] rho_matrix;
}

parameters {
  real<lower=0, upper =1> dep;
}

transformed parameters {
  corr_matrix[d] sigma = iden_matrix + dep * rho_matrix;
}

model {
  vector[d] mu = rep_vector(0, d);
  dep ~ beta(1.5, 1.5);
  for (n in 1:N) {
    target += multi_normal_lpdf(X[n,] | mu, sigma);
  }
}

```

I then run the model within a `cmdstan` conda environment:

```no-highlight
cmdstan_model example
./example sample num_chains=3 data file="example.json"

```

* * *

I have no idea why I’m getting a message that seems to imply there are no dimensions to `iden_matrix`, while it seems to read the `X` matrix fine.

I’m running this model in `cmdstan` v2.34, with macOS Sonoma 14.3.1. Thank you in advance for your help!

---

<div class="post-metadata">

**Author:** ![Bob\_Carpenter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bob_carpenter/32/9230_2.png) [@Bob\_Carpenter](https://discourse.mc-stan.org/u/Bob_Carpenter)\
**Post date:** [February 21, 2024, 7:32pm UTC](https://discourse.mc-stan.org/t/mismatch-in-dimensions-2x2-matrix-reading-as-dimensionless-object/34189/2 "2024-02-21T19:32:57Z")

</div>

> [@lizlawler](#):
>
> I figured I’d un-delete it and at least make it clear that this was entirely an issue on my end and nothing more than that. Sorry to bother!

Thanks for reposting. I copied this response so I could mark it as solved.
