Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
CFBI-public
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Riku Laine
CFBI-public
Commits
9780c5c0
Commit
9780c5c0
authored
5 years ago
by
Riku-Laine
Browse files
Options
Downloads
Patches
Plain Diff
Updated stan code
parent
549f7430
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
analysis_and_scripts/code_linear_dependency.stan
+30
-23
30 additions, 23 deletions
analysis_and_scripts/code_linear_dependency.stan
with
30 additions
and
23 deletions
analysis_and_scripts/code_linear_dependency.stan
+
30
−
23
View file @
9780c5c0
data
{
int
<
lower
=
1
>
D
;
// Dimensions of the features an coefficient vectors
int
<
lower
=
0
>
N_obs
;
// Number of
"
observed observations
"
(with T = 1)
int
<
lower
=
0
>
N_cens
;
// Number of
"
censored observations
"
(with T = 0)
int
<
lower
=
1
>
D
;
// Dimensions of the features an
d
coefficient vectors
int
<
lower
=
0
>
N_obs
;
// Number of observed observations (with T = 1)
int
<
lower
=
0
>
N_cens
;
// Number of censored observations (with T = 0)
int
<
lower
=
0
>
M
;
// Number of judges
real
<
lower
=
0
>
sigma_tau
;
// Prior for the variance parameters.
int
<
lower
=
1
,
upper
=
M
>
jj_obs
[
N_obs
];
// judge_ID array
...
...
@@ -18,11 +18,12 @@ parameters {
vector
[
N_obs
]
Z_obs
;
vector
[
N_cens
]
Z_cens
;
// Intercepts
vector
<
lower
=
0
>
[
M
]
sigma_T
;
// Intercepts
and their variance parameters.
real
<
lower
=
0
>
sigma_T
;
real
<
lower
=
0
>
sigma_Y
;
vector
[
M
]
alpha_T_raw
;
// vector[M] alpha_T;
real
alpha_Y_raw
;
// Temporary variables to compute the coefficients
...
...
@@ -31,10 +32,8 @@ parameters {
real
<
lower
=
0
>
a_ZT
;
// Presume latent variable has a positive coefficient.
real
<
lower
=
0
>
a_ZY
;
real
<
lower
=
0
>
tau_XT
;
real
<
lower
=
0
>
tau_XY
;
real
<
lower
=
0
>
tau_ZT
;
real
<
lower
=
0
>
tau_ZY
;
real
<
lower
=
0
>
tau_X
;
// RL 08DEC2019: Combine taus for X.
real
<
lower
=
0
>
tau_Z
;
// RL 24OCT2019: Combine taus for Z.
}
...
...
@@ -49,13 +48,18 @@ transformed parameters {
// Intercepts
vector
[
M
]
alpha_T
;
real
alpha_Y
;
beta_XT
=
a_XT
/
sqrt
(
tau_XT
);
beta_XY
=
a_XY
/
sqrt
(
tau_XY
);
beta_ZT
=
a_ZT
/
sqrt
(
tau_ZT
);
beta_ZY
=
a_ZY
/
sqrt
(
tau_ZY
);
beta_XT
=
a_XT
/
sqrt
(
tau_X
);
// RL 08DEC2019: Combine taus for X.
beta_XY
=
a_XY
/
sqrt
(
tau_X
);
beta_ZT
=
a_ZT
/
sqrt
(
tau_Z
);
// RL 24OCT2019: Combine taus for Z.
beta_ZY
=
a_ZY
/
sqrt
(
tau_Z
);
// beta_XT = a_XT * tau_X; // RL 08DEC2019: Combine taus for X.
// beta_XY = a_XY * tau_X;
// beta_ZT = a_ZT * tau_Z; // RL 24OCT2019: Combine taus for Z.
// beta_ZY = a_ZY * tau_Z;
alpha_T
=
sigma_T
.
*
alpha_T_raw
;
alpha_T
=
sigma_T
*
alpha_T_raw
;
alpha_Y
=
sigma_Y
*
alpha_Y_raw
;
}
...
...
@@ -65,11 +69,13 @@ model {
Z_obs
~
normal
(
0
,
1
);
Z_cens
~
normal
(
0
,
1
);
//
I
ntercepts
//
Variance parameter for the i
ntercepts
sigma_T
~
normal
(
0
,
sigma_tau
);
sigma_Y
~
normal
(
0
,
sigma_tau
);
// Intercepts
alpha_T_raw
~
normal
(
0
,
1
);
// alpha_T ~ logistic(0, 1);
alpha_Y_raw
~
normal
(
0
,
1
);
// According to
...
...
@@ -90,11 +96,11 @@ model {
a_ZY
~
normal
(
0
,
1
);
// nu = 6 -> nu/2 = 3
tau_X
T
~
gamma
(
3
,
3
);
tau_
XY
~
gamma
(
3
,
3
);
tau_
ZT
~
gamma
(
3
,
3
);
tau_Z
Y
~
gamma
(
3
,
3
);
tau_X
~
gamma
(
3
,
3
);
tau_
Z
~
gamma
(
3
,
3
);
//
tau_
X
~
normal(0
,
1
);
//
tau_Z ~
normal(0
,
1
);
// Compute the regressions for the observed observations
for
(
i
in
1
:
N_obs
){
dec_obs
[
i
]
~
bernoulli_logit
(
alpha_T
[
jj_obs
[
i
]]
+
X_obs
[
i
]
*
beta_XT
+
beta_ZT
*
Z_obs
[
i
]);
...
...
@@ -107,9 +113,10 @@ model {
}
generated quantities
{
// Array for predictions
int
<
lower
=
0
,
upper
=
1
>
y_est
[
N_cens
];
// Generate a draw from the posterior predictive.
// Generate a draw from the posterior predictive
for the outcome
.
for
(
i
in
1
:
N_cens
){
y_est
[
i
]
=
bernoulli_logit_rng
(
alpha_Y
+
X_cens
[
i
]
*
beta_XY
+
beta_ZY
*
Z_cens
[
i
]);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment