You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用R的drc与ggplot绘制量效曲线时,计算值与图中ED50不一致

四参数逻辑回归拟合ED50与ggplot曲线不匹配的问题排查

问题根源

  1. 模型参数含义不匹配:LL.4和L.4模型的参数e含义不同:

    • LL.4(对数逻辑斯蒂模型)的e是原始剂量尺度下的ED50,模型内部对剂量做log转换
    • L.4(逻辑斯蒂模型)的e是log转换后的ED50,当ggplot的x轴用log10转换时,e对应log10(ED50)
      你用LL.4计算ED50,却用L.4拟合曲线,两者的参数尺度不一致,导致图中点位和曲线不匹配。
  2. geom_smooth参数位置错误:se=FALSE和fullrange=TRUE是geom_smooth的参数,不是传给drm的method.args,原代码中放错位置会导致参数无效。

  3. 量效关系方向:你的数据显示剂量越高,响应值越低(反向抑制),模型斜率应为负数,需确保参数约束正确。

修正方案

方案一:统一用L.4模型(x轴log10转换)

library(ggplot2)
library(drc)

df <- data.frame(dose = c("2000", "666.67", "222.22", 
                          "74.04", "24.69", "8.23", 
                          "2.74", "0.91", "0.30", 
                          "0.10", "0.03", "0.01"),
                 response = c("0.569767442", "0.709302326", "0.767441860",
                 "0.712209302", "0.747093023", "0.723837209", 
                 "0.71802326", "0.7558140", "0.7906977",
                 "0.7616279", "0.8197674", "1"))

df$dose <- as.numeric(df$dose)
df$response <- as.numeric(df$response)

# 基于log10转换后的剂量用L.4拟合
logistic <- drm(response ~ log10(dose), 
                data = df, 
                fct = L.4(fixed = c(NA, 0, 1, NA)))      
# 将log10尺度的ED50转换回原始剂量
ED50 <- 10^ED(logistic, 50)[1]

# 绘图:修正参数位置,确保曲线与ED50匹配
ggplot(data = df, aes(x = dose, y = response))+
  scale_x_continuous(trans = "log10", limits = c(1E-2, 2E6))+
  scale_y_continuous(limits = c(0,1))+
  geom_smooth(method = drm, 
              method.args = list(fct = L.4(fixed = c(NA, 0, 1, NA))),
              se = FALSE,
              fullrange = TRUE)+ 
  geom_point(alpha = 0.5)+
  geom_point(aes(x = ED50, y = 0.5), color = "red") +
  coord_cartesian(xlim = c(1E-2,2E6))

方案二:统一用LL.4模型(x轴仅做log10显示)

library(ggplot2)
library(drc)

df <- data.frame(dose = c("2000", "666.67", "222.22", 
                          "74.04", "24.69", "8.23", 
                          "2.74", "0.91", "0.30", 
                          "0.10", "0.03", "0.01"),
                 response = c("0.569767442", "0.709302326", "0.767441860",
                 "0.712209302", "0.747093023", "0.723837209", 
                 "0.71802326", "0.7558140", "0.7906977",
                 "0.7616279", "0.8197674", "1"))

df$dose <- as.numeric(df$dose)
df$response <- as.numeric(df$response)

# 用LL.4拟合(模型内部处理剂量的log转换)
logistic <- drm(response ~ dose, 
                data = df, 
                fct = LL.4(fixed = c(NA, 0, 1, NA)))      
ED50 <- ED(logistic, 50)[1]

# 绘图:x轴仅做log10显示,曲线与ED50完全匹配
ggplot(data = df, aes(x = dose, y = response))+
  scale_x_continuous(trans = "log10", limits = c(1E-2, 2E6))+
  scale_y_continuous(limits = c(0,1))+
  geom_smooth(method = drm, 
              method.args = list(fct = LL.4(fixed = c(NA, 0, 1, NA))),
              se = FALSE,
              fullrange = TRUE)+ 
  geom_point(alpha = 0.5)+
  geom_point(aes(x = ED50, y = 0.5), color = "red") +
  coord_cartesian(xlim = c(1E-2,2E6))

说明

  • 两种方案都能保证计算的ED50与ggplot拟合曲线完全对应,核心是统一模型的参数尺度
  • 修正后的代码将se=FALSE和fullrange=TRUE放在geom_smooth的参数位置,确保生效

内容的提问来源于stack exchange,提问作者Cookie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 06:25:37