Я не уверен, что здесь правильно, но обычно я делаю это так:
Логистическая функция
Все еще не знаю, как использовать LL.4()
для этой цели
flogis <- function(x, b, c, d, e){
c + (d - c)/(1 + exp(b*(log(x) - log(e))))
}
Dataset
Приведите пример данных:
dose <- rep(exp(seq(-5, 5, length.out = 10)), each = 3)
dat <- data.frame(
dose = dose,
response = flogis(dose, -1, 0, 1, .5) + rnorm(length(dose), 0, .05)
)
head(dat)
# dose response
#1 0.006737947 0.01310683
#2 0.006737947 0.08292573
#3 0.006737947 0.03263079
#4 0.020468076 0.02763111
#5 0.020468076 0.01934260
#6 0.020468076 0.01296994
Примерка 4-х параметров логистической логистической модели
library(drc)
model <- drm(response ~ dose, data = dat, fct = LL.4())
summary(model)
#Model fitted: Log-logistic (ED50 as parameter) (4 parms)
#
#Parameter estimates:
#
# Estimate Std. Error t-value p-value
#b:(Intercept) -1.0012680 0.0887792 -11.2782 1.637e-11 ***
#c:(Intercept) 0.0049506 0.0243151 0.2036 0.8402
#d:(Intercept) 0.9889417 0.0163848 60.3573 < 2.2e-16 ***
#e:(Intercept) 0.4054848 0.0419639 9.6627 4.310e-10 ***
#---
#Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#
#Residual standard error:
#
#0.04466107 (26 degrees of freedom)
Получить параметры модели для использования с ggplot
coefs <- setNames(coef(model), c("b", "c", "d", "e"))
y50 <- predict(model, newdata = data.frame(dose = coefs["e"]))
Данные графика
(Извините, у вас нет времени поиграть с текстовыми метками, и вы не понимаете, что означает phi2 + phi3
на примерном графике, но вполне уверены, что это происходит около EC50)
ggplot(dat, aes(x = dose, y = response)) +
stat_function(fun = function(x, b, c, d, e){
c + (d - c)/(1 + exp(b*(log(x) - log(e))))
}, args = coefs, col = "skyblue", lwd = 1) +
geom_point(pch = 21, fill = "white") +
geom_hline(yintercept = coefs[c("c", "d")], lty = 2, colour = "gray50") +
geom_segment(aes(x = coefs["e"], y = 0, xend = coefs["e"], yend = y50),
lty = 2, colour = "gray50") +
geom_segment(aes(x = coefs["e"], y = y50, xend = 0, yend = y50),
lty = 2, colour = "gray50") +
scale_x_log10(
breaks = scales::trans_breaks("log10", function(x) 10^x),
labels = scales::trans_format("log10", scales::math_format(10^.x))
) +
annotation_logticks(sides = "b") +
labs(x = "Dose",
y = "Response"
) +
expand_limits(y = 1) +
ggthemes::theme_few()