I have a hierarchical linear regression, that works like this:
In the following model, when p_target gets << 0.5 the information for calculating the proportions decreases, therefore the hierachical regression on the proportions stops to cenverge, because the variance on the regression goes to 0.
If I put a lower bound on the variance of 0.1 for example the convergence is reached (which is not that generative).
How can I behave?
data{
int G; // Number of marker genes
int P; // Number of cell types
int S; // Number of mix samples
int<lower=1> R; // Number of covariates (e.g., treatments)
matrix[S,R] X; // Array of covariates for hierarchical regresison
matrix<lower=0>[S,G] y; // Observed counts
matrix<lower=0>[G,P] x; // signature counts
vector<lower=0, upper=1>[S] p_target; //This is the proportion of the whole taget -> simplex_beta * p_target
matrix[S,G] y_hat_background; // This is the matrix of background -> will be summed up with the matrix of the target
}
transformed data{
matrix<lower=0>[S,G] y_log; // log tranformation of the data
y_log = log(y+1); // log tranformation of the data
}
parameters {
simplex[P] beta[S]; // Proportions, of the signatures in the xim
real<lower=0> sigma; // Variance linear model
matrix[R,P] alpha; // design matrix of the hierarchical regression
vector<lower=0>[P] phi; // Variance of the hierarchical regression
}
transformed parameters{
matrix[S,P] beta_target; // Multiply the simplex by the whole proportion of the target
matrix[S,G] y_hat_target; // The predicted counts for the linear model
matrix[S,G] y_hat;
for(s in 1:S) beta_target[s] = to_row_vector(beta[s]) * p_target[s];
y_hat_target = beta_target * x';
y_hat = y_hat_target + y_hat_background;
}
model {
matrix[S,P] beta_hat; // Predicted proportions in the hierachical linear model
sigma ~ normal(0, 0.1);
to_vector(y_log) ~ student_t(8, log(to_vector(y_hat_target)), sigma); // Linear system
//p_target it's < 0.5 usually 0.01, thus I use log-link instead of inv_logit
to_vector(alpha) ~ normal(0, 0.2);
phi ~ cauchy(0, 2);
//////////////////////////////////////////////////////////////////////////
// WHEN p_target is small (so the proportions gets really small compared
// to the background) adding this regression cause lack of regression.
// If I take this out, then the proportions are predicted with convergence
//////////////////////////////////////////////////////////////////////////
beta_hat = exp(X * alpha);
for(s in 1:S) beta[s] ~ normal(beta_hat[s], phi);
//////////////////////////////////////////////////////////////////////////
// I tried Also to treat this as lognormal, no improvements
//////////////////////////////////////////////////////////////////////////
// beta_hat = X * alpha;
// for(s in 1:S) beta[s] ~ lognormal(beta_hat[s], phi);
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
}
But if I add forcely 0.1 for the phi variance I get convergence
beta[s] ~ normal(beta_hat[s], phi + 0.1);
Here is the design matrix for the hierarchical regression
> my_design
(Intercept) cov
1 1 -1.207436
2 1 -1.207436
3 1 -1.207436
4 1 -1.207436
5 1 -1.207436
6 1 -1.207436
7 1 -1.207436
8 1 -1.207436
9 1 -1.207436
10 1 -1.207436
11 1 -1.207436
12 1 -1.207436
13 1 -1.207436
14 1 -1.207436
15 1 -1.207436
16 1 -1.207436
17 1 -1.207436
18 1 -1.207436
19 1 -1.207436
20 1 -1.207436
21 1 -1.207436
22 1 1.207436
23 1 1.207436
24 1 1.207436
25 1 1.207436
26 1 1.207436
27 1 1.207436
28 1 1.207436
29 1 1.207436
30 1 1.207436
31 1 1.207436
32 1 1.207436
33 1 1.207436
34 1 1.207436
35 1 1.207436
36 1 1.207436
37 1 1.207436
38 1 1.207436
39 1 1.207436
40 1 1.207436
41 1 1.207436
42 1 1.207436
43 1 1.207436
44 1 1.207436
45 1 1.207436
46 1 1.207436
47 1 1.207436
48 1 1.207436
49 1 1.207436
50 1 1.207436
51 1 1.207436
52 1 1.207436
53 1 1.207436
54 1 1.207436
55 1 1.207436
56 1 1.207436
57 1 1.207436
58 1 0.000000
59 1 0.000000
60 1 0.000000
61 1 0.000000
62 1 0.000000
63 1 0.000000
64 1 0.000000
65 1 0.000000
66 1 0.000000
67 1 0.000000
68 1 0.000000
69 1 0.000000
70 1 0.000000
71 1 0.000000
72 1 0.000000
73 1 0.000000
74 1 0.000000
75 1 0.000000
76 1 0.000000
77 1 0.000000
78 1 0.000000
79 1 0.000000
80 1 0.000000
attr(,"assign")
[1] 0 1