library(ROCnReg)
data(psa)
# Select the last measurement
newpsa <- psa[!duplicated(psa$id, fromLast = TRUE),]
# Log-transform the biomarker
newpsa$l_marker1 <- log(newpsa$marker1)
# \donttest{
cROC_bnp <- cROC.bnp(formula.h = l_marker1 ~ f(age, K = 0),
formula.d = l_marker1 ~ f(age, K = 0),
group = "status",
tag.h = 0,
data = newpsa,
standardise = TRUE,
p = seq(0,1,l=101),
mcmc = mcmccontrol(nsave = 500, nburn = 100, nskip = 1))
### Threshold values based on the YI
th_cROC_bnp_yi <- compute.threshold.cROC(cROC_bnp, criterion = "YI")
# Plot results
# Threshold values
plot(th_cROC_bnp_yi$newdata$age, th_cROC_bnp_yi$thresholds[,"est"],
type = "l", xlab = "Age",
ylab = "log(PSA)", ylim = c(0,3),
main = "Threshold values based on the Youden Index")
lines(th_cROC_bnp_yi$newdata$age, th_cROC_bnp_yi$thresholds[,"qh"], lty = 2)
lines(th_cROC_bnp_yi$newdata$age, th_cROC_bnp_yi$thresholds[,"ql"], lty = 2)
# Youden Index
plot(th_cROC_bnp_yi$newdata$age, th_cROC_bnp_yi$YI[,"est"],
type = "l", xlab = "Age",
ylab = "log(PSA)", ylim = c(0,1),
main = "Threshold values based on the Youden Index")
lines(th_cROC_bnp_yi$newdata$age, th_cROC_bnp_yi$YI[,"qh"], lty = 2)
lines(th_cROC_bnp_yi$newdata$age, th_cROC_bnp_yi$YI[,"ql"], lty = 2)
### Threshold values for a fixed FPF
th_cROC_bnp_fpf <- compute.threshold.cROC(cROC_bnp, criterion = "FPF", FPF = 0.1)
# Plot results
# Threshold values
plot(th_cROC_bnp_yi$newdata$age, th_cROC_bnp_fpf$thresholds[["0.1"]][,"est"],
type = "l", xlab = "Age",
ylab = "log(PSA)", ylim = c(0,3), main = "Threshold values for a FPF = 0.1")
lines(th_cROC_bnp_yi$newdata$age, th_cROC_bnp_fpf$thresholds[["0.1"]][,"qh"], lty = 2)
lines(th_cROC_bnp_yi$newdata$age, th_cROC_bnp_fpf$thresholds[["0.1"]][,"ql"], lty = 2)
# }
# \dontshow{
cROC_bnp <- cROC.bnp(formula.h = l_marker1 ~ f(age, K = 0),
formula.d = l_marker1 ~ f(age, K = 0),
group = "status",
tag.h = 0,
data = newpsa,
standardise = TRUE,
p = seq(0,1,l=101),
mcmc = mcmccontrol(nsave = 5, nburn = 2, nskip = 1))
### Threshold values based on the YI
th_cROC_bnp_yi <- compute.threshold.cROC(cROC_bnp, criterion = "YI")
# Plot results
# Threshold values
plot(th_cROC_bnp_yi$newdata$age, th_cROC_bnp_yi$thresholds[,"est"],
type = "l", xlab = "Age",
ylab = "log(PSA)", ylim = c(0,3),
main = "Threshold values based on the Youden Index")
lines(th_cROC_bnp_yi$newdata$age, th_cROC_bnp_yi$thresholds[,"qh"], lty = 2)
lines(th_cROC_bnp_yi$newdata$age, th_cROC_bnp_yi$thresholds[,"ql"], lty = 2)
# Youden Index
plot(th_cROC_bnp_yi$newdata$age, th_cROC_bnp_yi$YI[,"est"],
type = "l", xlab = "Age",
ylab = "log(PSA)", ylim = c(0,1),
main = "Threshold values based on the Youden Index")
lines(th_cROC_bnp_yi$newdata$age, th_cROC_bnp_yi$YI[,"qh"], lty = 2)
lines(th_cROC_bnp_yi$newdata$age, th_cROC_bnp_yi$YI[,"ql"], lty = 2)
### Threshold values for a fixed FPF
#th_cROC_bnp_fpf <- compute.threshold.cROC(cROC_bnp, criterion = "FPF", FPF = 0.1)
## Plot results
# # Threshold values
# plot(th_cROC_bnp_yi$newdata$age, th_cROC_bnp_fpf$thresholds[["0.1"]][,"est"], type = "l", xlab = "Age",
# ylab = "log(PSA)", ylim = c(0,3), main = "Threshold values for a FPF = 0.1")
# lines(th_cROC_bnp_yi$newdata$age, th_cROC_bnp_fpf$thresholds[["0.1"]][,"qh"], lty = 2)
# lines(th_cROC_bnp_yi$newdata$age, th_cROC_bnp_fpf$thresholds[["0.1"]][,"ql"], lty = 2)
# }
Run the code above in your browser using DataLab