我是R和统计学的新手,但我需要为我的数据建立一个概率模型,以估计在95%的时间内给我带来积极结果的集中度。我正在尝试调整我发现的功能here。我必须弄清楚模型是如何构建的,如何计算模型的95%CI,并绘制所有图形,如下所示。
# sample data with concentration, number of successful detections and number of fails
dat <- data.frame(conc = c(1e3, 1e2, 1e1, 1e0, 1e-1, 1e-2),
success = c(10, 10, 9, 7, 3, 0),
failure = c(0, 0, 1, 3, 7, 10))
# buid the probit model
probit_model <- glm(cbind(success, failure) ~ log10(conc), data = dat, family = binomial(link ="probit"))
# get the 95% CI FOR THE MODEL
prediction <- predict.glm(probit_model,
newdata = data.frame(conc = prediction_xaxis),
type = "link",
se.fit = TRUE)
se <- qnorm(0.975) * prediction$se.fit
upr <- unlist(probit_model$family$linkinv(prediction$fit + se))
lwr <- unlist(probit_model$family$linkinv(prediction$fit - se))
fit <- unlist(probit_model$family$linkinv(prediction$fit))
我还可以获得浓度的数值,该浓度给出了95%的检测概率:
# get the numeric value for the concentration that gives 95% detections
lod95 <- 10^((probit_model$family$linkfun(0.95) - coef(probit_model)[1])/coef(probit_model)[2])
我像这样绘制它:
# make plot
with(dat, plot(conc, success/(success + failure), ylab = "Probability", xlab = "Concentration", log = "x", pch = 19, ylim = c(0, 1)))
title(main = paste("LoD95% = ", round(lod95, 2), " (", round(ci_upper, 1), " - ", round(ci_lower, 1), ")", sep = ""))
lines(prediction_xaxis, fit)
lines(prediction_xaxis, lwr, lty = 2)
lines(prediction_xaxis, upr, lty = 2)
abline(h = 0.95, lty = 2, col = "red")
abline(v = lod95, lty = 2, col = "red")
我现在需要的是获取95%水平红线与95%CI虚线之间的截距的浓度值。
我在这里找到了几个有关glm()和confint()的网站和帖子,但是似乎没有一个网站可以完全满足我的需要,因此,我对此表示感谢。