-
Notifications
You must be signed in to change notification settings - Fork 0
/
befa.stan
43 lines (34 loc) · 1013 Bytes
/
befa.stan
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
data {
int<lower = 1> subjectsCount;
int<lower = 1> itemsCount;
int<lower = 1> factorsCount;
matrix[subjectsCount, itemsCount] responses;
}
transformed data {
vector[itemsCount] responseMeans;
responseMeans = rep_vector(0.0, itemsCount);
}
parameters {
matrix[itemsCount, factorsCount] factorLoadings;
vector<lower = 0>[itemsCount] itemVariances;
real<lower = 0> itemVariancesMean;
real<lower = 0> itemVariancesSd;
}
transformed parameters{
cov_matrix[itemsCount] covarianceMatrix;
covarianceMatrix = factorLoadings * factorLoadings' + diag_matrix(itemVariances);
}
model {
// the hyperpriors
itemVariancesMean ~ cauchy(0, 1);
itemVariancesSd ~ cauchy(0, 1);
// the priors
itemVariances ~ cauchy(itemVariancesMean, itemVariancesSd);
for(itemIndex in 1:itemsCount) {
factorLoadings[itemIndex] ~ cauchy(0, 1);
}
// the likelihood
for(subjectIndex in 1:subjectsCount) {
responses[subjectIndex] ~ multi_normal(responseMeans, covarianceMatrix);
}
}