-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
26 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,47 @@ | ||
# Separate priors for intercept and host_common_name | ||
data { | ||
int<lower=0> N; // number of samples | ||
int<lower=0> D; // number of dimensions | ||
real A; // mean intercept | ||
int<lower=0> p; // number of covariates | ||
real depth[N]; // sequencing depths of microbes | ||
vector[N] depth; // sequencing depths of microbes | ||
matrix[N, p] x; // covariate matrix | ||
int y[N, D]; // observed microbe abundances | ||
real<lower=0> B_p_1; // stdev for Beta Normal prior | ||
real<lower=0> B_p_2; // stdev for Beta Normal prior | ||
array[N, D] int y; // observed microbe abundances | ||
real<lower=0> B_p; // stdev for intercept | ||
real<lower=0> phi_s; // constant phi value | ||
} | ||
|
||
parameters { | ||
// parameters required for linear regression on the species means | ||
matrix[p, D-1] beta_var; | ||
row_vector<offset=A, multiplier=B_p>[D-1] beta_0; | ||
matrix<multiplier=B_p>[p-1, D-1] beta_x; | ||
real inv_disp; | ||
} | ||
|
||
transformed parameters { | ||
matrix[p, D-1] beta_var = append_row(beta_0, beta_x); | ||
matrix[N, D-1] lam; | ||
matrix[N, D] lam_clr; | ||
vector[N] z; | ||
|
||
z = to_vector(rep_array(0, N)); | ||
lam = x * beta_var; | ||
lam_clr = append_col(z, lam); | ||
lam = x*beta_var; | ||
for (n in 1:N){ | ||
lam[n] += depth[n]; | ||
} | ||
lam_clr = append_col(to_vector(rep_array(0, N)), lam); | ||
} | ||
|
||
model { | ||
// setting priors ... | ||
inv_disp ~ lognormal(0, phi_s); | ||
|
||
for (i in 1:D-1){ | ||
beta_var[1, i] ~ normal(0., B_p_1); // uninformed prior | ||
beta_var[2, i] ~ normal(0., B_p_2); // uninformed prior | ||
for (j in 1:p){ | ||
beta_var[j, i] ~ normal(0., B_p); // uninformed prior | ||
} | ||
} | ||
|
||
// generating counts | ||
for (n in 1:N){ | ||
for (i in 1:D){ | ||
target += neg_binomial_2_log_lpmf(y[n, i] | depth[n] + lam_clr[n, i], phi_s); | ||
target += neg_binomial_2_log_lpmf(y[n, i] | lam_clr[n, i], inv(inv_disp)); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters