使用R的drc与ggplot绘制量效曲线时,计算值与图中ED50不一致
四参数逻辑回归拟合ED50与ggplot曲线不匹配的问题排查
问题根源
模型参数含义不匹配:
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拟合曲线,两者的参数尺度不一致,导致图中点位和曲线不匹配。
geom_smooth参数位置错误:
se=FALSE和fullrange=TRUE是geom_smooth的参数,不是传给drm的method.args,原代码中放错位置会导致参数无效。量效关系方向:你的数据显示剂量越高,响应值越低(反向抑制),模型斜率应为负数,需确保参数约束正确。
修正方案
方案一:统一用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
相关产品推荐
相关产品推荐

