[R] Comparing two diagnostic tests with lme4
Keno Kyrill Bressem
kenobressem at gmail.com
Sun Jul 3 20:27:02 CEST 2016
Dear R experts,
I compare two diagnostic tests. Therfore, I collected patient data from
several studies. The dataframe is similar to this one:
set.seed(10)
data = data.frame( test1 = rbinom(1000, 1, 0.6),
test2 = rbinom(1000, 1, 0.4),
reference = rbinom(1000, 1, 0.7),
study = sort(paste("study_", round(runif(1000, 1, 20),0)
,sep = "")),
id = 1:1000,
age = round(rnorm(1000, 60, 10), 0))
I did a lot of research on how to use hierarchical models for calculating
the respective sensitivities and specifities for my tests and tried a lot
of variations in the formula of glmer. However, I don't have sufficient
statistical knowledge for interpreting these models. So I don't know if my
approach is correct. Therfore I am showing you my latest model.
First, I would like to calculate the logit sensitivity and specifity for
each test. In a paper by Genders et al.
<http://pubs.rsna.org/doi/suppl/10.1148/radiol.12120509> (appendices)
<http://pubs.rsna.org/doi/suppl/10.1148/radiol.12120509/suppl_file/12120509appendices.pdf>
a Stata code to calculate the logit sensitivity and specifity is provided.
I transferred this code to "R", but I am not sure if it's correct this way.
m.sen <- glmer(test1 ~ ( 1 | study) + ( 1 | id ), data = subset(data,
reference == 1), family = binomial(link = "logit"),
control = glmerControl(optimizer = "bobyqa"), nAGQ = 1)
# require("useful")
m.spe <- glmer(binary.flip(test1) ~ ( 1 | study) + ( 1 | id ), data =
subset(data, reference == 0), family = binomial(link = "logit"),
control = glmerControl(optimizer = "bobyqa"), nAGQ =
logit.sen = fixef(m.sen)
logit.spe = fixef(m.spe)
My first question is if it is possible to calculate the logit sensitivity
and specifity of a diagnostic test like this. The next step would be to
adjust for different patient characteristics, such as age.
data <- within(data, {age = as.factor(round(age, -1))})
m.sen.age <- glmer(test1 ~ age + ( 1 | study) + ( 1 | id ), data =
subset(data, reference == 1),
family = binomial(link = "logit"), control = glmerControl(optimizer =
"bobyqa"), nAGQ = 1)
fix <- fixef(m.sen.age)
Now I add the estimates. For example, to determine the logit sensitivity of
test1 in patients aged between 55 and 65: sen.50 = fix[1] + fix[5]
As an alternative, I thought about further defining the data subset, which
produces nearly identically results.
m.sen.age <- glmer(test1 ~ ( 1 | study) + ( 1 | id ), data = subset(data,
reference == 1 & age == 60),
family = binomial(link = "logit"), control = glmerControl(optimizer =
"bobyqa"), nAGQ = 1)
sen.age50 = fixef(m.sen.age)
Thank you very much in advance
kb
[[alternative HTML version deleted]]
More information about the R-help
mailing list