Hi I’m trying to create a model that emulates the Salm: extra - Poisson variation in dose - response study from OpenBUGS. Having trouble with 2 things, my transformed parameter contains log mu however I cant log the left hand side in a transform statement so ive had to try and work around it.

log(mu[i , j]) <- alpha + beta * log(x[i] + 10) + gamma * x[i] + lambda[i , j] is how the statement written in OpenBUGS. You can take a look down here

Also there seems to be a problem when I try and sample from my model, lots of errors come up. My error log is at the bottom

My data and model look like:

c1 = c(0,15,21,29)

c2 = c(10,16,18,21)

c3 = c(33,16,26,33)

c4 = c(100,27,41,69)

c5 = c(333,33,38,31)

c6 = c(1000, 20,27,42)

df = data.frame(c1,c2,c3,c4,c5,c6)

dose = df[1,1:6]

j = length(dose)

i = length(df[2:4,1])

obsmatrix = data.frame(c(15,21,29),

c(16,18,21),

c(16,26,33),

c(27,41,69),

c(33,38,31),

c(20,27,42))

```
data{
int<lower=1> n; // number of doses
int<lower=1> p; // number of plates for each dose
vector[n]x; // doses
int y[p,n]; // responses
}
parameters{
matrix[p,n] lambda;
matrix[p,n] mu;
real<lower=0,upper=100> alpha;
real<lower=0,upper=100> beta;
real<lower=0,upper=100> gamma;
real tau;
}
transformed parameters{
matrix[p,n] lmu;
lmu = log(mu);
for(i in 1:n){
for(j in 1:p){
lmu[i,j] = alpha + beta * log(x[i] + 10) + gamma * x[i] + lambda[i,j];
}}
}
model{
for(i in 1:n){
for(j in 1:p){
y[i,j] ~ poisson(mu[i,j]);
lambda[i,j] ~ normal(0,tau);
}}
alpha ~ normal(0,1000);
beta ~ normal(0,1000);
gamma ~ normal(0,1000);
tau ~ gamma(0.001, 0.001);
}
```

When I try to sample from my model I get

[595] “Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:”

[596] “Exception thrown at line 24: []: accessing element out of range. index 4 out of range; expecting index to be between 1 and 3; index position = 1lambda”

[597] “If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,”

[598] “but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.”

[599] “Rejecting initial value:”

[600] " Error evaluating the log probability at the initial value."

[601] "Initialization between (-2, 2) failed after 100 attempts. “

[602] " Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.”

[603] "Error in sampler$call_sampler(args_list[[i]]) : "

[1] “error occurred during calling the sampler; sampling not done”

I’ve done a lot of fiddling around with parameters and ranges and still cant seem to fix it. Any help is appreciated!