I’m working on a model where the general procedure is looking for the parameters that best minimize the difference between a model based on those parameters and data.

My code is the following:

`real get_model(real logage, real zh) {`

```
return -1.0;
}
real chi2_lpdf(matrix obs, real logage, real zh) {
vector[num_elements(obs[:,1])] tmp;
vector[num_elements(obs[:,1])] holder;
real ln_like;
for (i in 1:num_elements(obs[:,1])) {
holder[i] = 1;
}
for (i in 1:num_elements(obs[:,1])) {
tmp[i] = (obs[i,1]-holder[i])^2/obs[i,2];
}
ln_like = -0.5*sum(tmp);
return ln_like;
}
}
data {
int num;
matrix[num, 2] obs;
}
parameters {
real<lower=1.0, upper=1.1> logage;
real<lower=-0.02, upper=0.00> zh;
}
model {
real mflux;
logage ~ normal(0.5, 1);
zh ~ normal(0.5, 1);
obs ~ chi2(logage, zh);
}
```

As you can see, `get_model`

is just a dummy function right now. What it eventually needs to be is a function that can take the `zh`

and `logage`

parameters, find and return the model associated with those parameters from a pre-computed grid so that it can be used to compare to the observations (`obs`

variable). I’ve searched through the manual looking for any information on how I might go about this but I didn’t find anything. Has anyone dealt with a similar problem? I’d appreciate any suggestions or if there’s a tutorial you can point me to. Thank you!