Hi,
I would like to fit a bivariate model for meta analysis of diagnostic test accuracy (sensitivity and specificity). I have approx 50 studies to be included with four cell counts for each study (namely, true positive, false positive, true negative, false negative).
In my codes (attached down below), I transformed the count data to logit of true positive rate and false positive rate and calculated their standard errors. To fit a bivariate normal models for sensitivity and specificity, I wanted to use the standard errors in my covariance matrix for within study variability, but the correlation is unknown. So I wanted to estimate the correlation for within study variability using the known variances while estimating a whole covariance matrix for between study variability.
As I got errors saying my covariance matrix is not symmetric, I tried using the matrix decomposition, but I now got the following error. I was thinking it occurred because I was trying to plug in the estimated variances into the covariance matrix for within variability even though I declared it in the transformed parameters block. Yet, I am not sure how to proceed.
Variable "cov_matrix" does not exist.
error in 'model5e203298a5ca_sen_spe_uni' at line 63, column 14
-------------------------------------------------
61:
62:
63: cov_matrix[J] sigma_w_mat[K]; // vcov matrix for within study variability
^
64:
-------------------------------------------------
The data I am using for the above code is uploaded here:
My code is as follows.
Any help to fix the error, as well as any other comments on the modelling as a whole, would be greatly appreciated.
data {
int<lower=1> K; /* Number of studies */
int<lower=1> J; /* sensitivity and specificity = 2*/
real<lower=0> TP[K];
real<lower=0> FP[K];
real<lower=0> FN[K];
real<lower=0> TN[K];
}
transformed data{
real<lower=0> sigma_tpr[K];
real<lower=0> sigma_fpr[K];
real TPR[K];
real FPR[K];
real LOGIT_tpr[K];
real LOGIT_fpr[K];
vector[J] LOGIT_pair[K];
vector<lower=0>[J] sigma_w[K]; // within-study sd
for (i in 1:K){
TPR[i] = TP[i]/(TP[i] + FN[i]);
FPR[i] = FP[i]/(TN[i] + FP[i]);
LOGIT_tpr[i] = log(TPR[i]/(1-TPR[i]));
sigma_tpr[i] = sqrt(1/((TP[i] + FN[i])*TPR[i]*(1-TPR[i])));
LOGIT_fpr[i] = log(FPR[i]/(1-FPR[i]));
sigma_fpr[i] = sqrt(1/((TN[i] + FP[i])*FPR[i]*(1-FPR[i])));
LOGIT_pair[i,1] = LOGIT_tpr[i];
LOGIT_pair[i,2] = LOGIT_fpr[i];
sigma_w[i,1] = sigma_tpr[i]*sigma_tpr[i];
sigma_w[i,2] = sigma_fpr[i]*sigma_fpr[i];
}
}
parameters{
vector[J] mu;
vector[J] theta;
vector<lower=0>[J] tau; // between-study sd
corr_matrix[J] Omega_b; // correlation matrix for between study variability
corr_matrix[J] Omega_w[K]; // correlation matrix for within study variability
}
transformed parameters {
cov_matrix[J] sigma_b_mat; // vcov matrix for between study variability
sigma_b_mat = quad_form_diag(Omega_b, tau);
cov_matrix[J] sigma_w_mat[K]; // vcov matrix for within study variability
for (i in 1:K){
sigma_w_mat[i] = quad_form_diag(Omega_w[i], sigma_w[i]);
}
}
model {
theta ~ multi_normal(mu, sigma_b_mat);
for (i in 1:K){
LOGIT_pair[i] ~ multi_normal(theta, sigma_w_mat[[group[i]]);
}
// priors
mu ~ normal(0,1);
tau ~ cauchy(0, 0.5);
Omega_w ~ lkj_corr(1); //LKJ prior on the correlation matrix
Omega_b ~ lkj_corr(1); //LKJ prior on the correlation matrix
}