在R的Grotwth曲线上绘制渐近线

时间:2018-11-16 14:34:55

标签: r math statistics

如何在上面的曲线上绘制渐近线?

 # Create Data
    Conc <- c(0.03125, 0.06250, 0.12500, 0.25000, 0.50000, 1.00000, 0.03125, 0.06250, 0.12500, 0.25000, 0.50000, 1.00000, 0.03125, 0.06250, 0.12500, 0.25000, 0.50000, 1.00000, 0.03125, 0.06250, 0.12500, 0.25000, 0.50000, 1.00000, 0.03125, 0.06250, 0.12500, 0.25000, 0.50000, 1.00000, 0.03125, 0.06250, 0.12500, 0.25000, 0.50000, 1.00000)

    Response <- c(167.11246201, 53.96960486, 128.42857143, 43.67173252, 4.51975684, 0.34042553, 120.10334347, 101.14589666, 155.17629179, 35.31306991, 8.56534954, 1.71124620, 146.34954407, 108.50151976, 163.60182371, 64.70212766, 2.88145897, 0.50759878, 82.92401216, 109.80547112, 116.69300912, 26.85410334, 3.01519757, 0.37386018, 87.06990881, 84.82978723, 118.36474164, 27.52279635, 2.34650456, 0.10638298, 89.47720365, 109.47112462, 85.43161094, 17.69300912, 2.31306991, 0.07294833)

    df <- data.frame(Conc = Conc, Response = Response)

    #Make Modell
    library(drc)
    #adjust model
    drm <- drm(Response ~ Conc, data = df, fct = LL.4())
    #plot
    plot(drm)

这是我的意思的代表吗? enter image description here

3 个答案:

答案 0 :(得分:0)

尝试:

library(drc)

#adjust model
drm <- drm(Response ~ Conc, data = df, fct = LL.4())

#plot
plot(drm)
abline(a=112.6868 , 0)

enter image description here

答案 1 :(得分:0)

您可以从drm对象中提取渐近线的值:

asymptote <- coef(drm)[3]

此值可用于绘图:

plot(drm)
abline(asymptote, 0)

enter image description here

答案 2 :(得分:0)

我不确定这里正确的方法是什么,但是我通常这样做是这样的:

物流功能

仍然不知道如何为此目的使用LL.4()

flogis <- function(x, b, c, d, e){
  c + (d - c)/(1 + exp(b*(log(x) - log(e))))
}

数据集

提供一些示例数据:

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()

drm