I have the following model:
I wish to learn how to implement this model.
Research and Attempt
I’ve had a look at the following Poisson GLM as an example:
```{stan output.var="PoissonGLMQR"}
data{
int<lower=1> n; // number of observations
int<lower=1> p; // number of predictors
matrix[n, p] x; // design matrix
int<lower=0> y[n]; // responses
}
transformed data{
matrix [n, p] Q_ast;
matrix [p, p] R_ast;
matrix [p, p] R_ast_inverse;
Q_ast = qr_Q(x)[,1:p] * sqrt(n - 1.0);
R_ast = qr_R(x)[1:p,] / sqrt(n - 1.0);
R_ast_inverse = inverse(R_ast);
}
parameters{
vector[p] theta; // regression coefficients for predictors
}
transformed parameters{
vector[p] beta;
vector[n] mu;
mu = exp(Q_ast*theta);
beta = R_ast_inverse * theta;
}
model{
y ~ poisson(mu);
}
```
I understand that this example has used QR reparameterization (see section 9.2 of the Stan reference manual). However, since I’m new to Stan, I’m finding this quite intimidating, and I’m unsure of how to implement the exponential GLM in the same way. Does one even need to use the QR reparameterization for the exponential case?
Anyway, my naive attempt at the exponential GLM is the following adaptation of the Poisson GLM code:
```{stan output.var="ExponentialGLM"}
data{
int<lower=1> n; // number of observations
int<lower=1> p; // number of predictors
matrix[n, p] x; // design matrix
real<lower=0> y[n]; // responses
}
transformed data{
matrix [n, p] Q_ast;
matrix [p, p] R_ast;
matrix [p, p] R_ast_inverse;
Q_ast = qr_Q(x)[,1:p] * sqrt(n - 1.0);
R_ast = qr_R(x)[1:p,] / sqrt(n - 1.0);
R_ast_inverse = inverse(R_ast);
}
parameters{
vector[p] theta; // regression coefficients for predictors
}
transformed parameters{
vector[p] beta;
vector[n] mu;
mu = exp(Q_ast*theta);
beta = (R_ast_inverse * theta);
}
model{
y ~ exponential(mu);
}
```
But, I’m totally unsure if this is even the right way to go about coding such a model in Stan. All I did was simply try to adapt the Poisson GLM example to the aforementioned exponential GLM.
I am seeking a demonstration of the exponential GLM and clarifications regarding my misunderstandings above.
Sample Data
conc time
1 6.1 0.8
2 4.2 3.5
3 0.5 12.4
4 8.8 1.1
5 1.5 8.9
6 9.2 2.4
7 8.5 0.1
8 8.7 0.4
9 6.7 3.5
10 6.5 8.3
11 6.3 2.6
12 6.7 1.5
13 0.2 16.6
14 8.7 0.1
15 7.5 1.3



glmequivalents areglm(..., family = poisson)andglm(..., family = Gamma). In a first step you should compare the output of your Stan model with that fromglm. Do point estimates agree? - Maurits Evers