R中geom_smooth拟合和predict.drc输出之间的差异

q3aa0525  于 2023-03-10  发布在  其他
关注(0)|答案(1)|浏览(131)

我尝试使用drc软件包使用降阶对数正态拟合(LN.2)绘制剂量-React曲线,这应该等同于probit剂量-React模型。当我对glm软件包导出的probit模型(剂量log 10转换)和drc模型使用'predict'函数时,输出与预期相同。
但是,当我在geom_smooth中使用drc方法时,图形输出与这些预测值完全不同。

require(tidyverse)
require(drc)

df<-tibble(y = c(0.1,0.125,0.275,0.5,0.75, 0.95,1),
           x = c(100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8))


probit_model <- glm(y ~ log10(x), data = df, family = quasibinomial(link = "probit"))
test_model<-drm(y~x, fct = LN.2(), type = "binomial", data = df)

df <- df %>%
  add_row(x = 10, y = NA) %>%  # To underline that these models are different
  mutate(y_pred = predict(probit_model, newdata = ., type = "response"),
         y_pred_2 = predict(test_model, newdata = data.frame(x = x)))

df %>%
  ggplot(aes(x, y)) +
  geom_point(size = 4) +
  scale_x_log10()+
  geom_line(aes(y = y_pred_2), color = "red", lwd = 1) +
  geom_smooth(formula = y ~ x, color = "blue",
              method = "glm", fullrange = TRUE,
              method.args = list(family = quasibinomial(link = "probit")), se = F)+
  geom_smooth(method = drm, method.args = list(fct = LN.2(), type = "binomial"), se = F, color = "black", linetype = 2)+
  theme_bw()

下面是该行为的一个示例。

c2e8gylq

c2e8gylq1#

您需要考虑作为predict函数的输入传递的对数转换的x轴值。您已经在glm中完成了这一操作,因为您使用y ~ x而不是y ~ log(x)作为公式,但它实际上不适用于drm。然而,在这里并不一定要使用geom_smooth。因为您的模型已经包含使用geom_function重新创建曲线的函数

df %>%
  mutate(x = x) %>%
  ggplot(aes(x, y)) +
  geom_point(size = 4) +
  geom_line(aes(y = y_pred_2), color = "red", lwd = 1.5) +
  geom_smooth(formula = y ~ x, color = "skyblue",
              method = "glm", fullrange = TRUE, lwd = 1.5,
              method.args = list(family = quasibinomial(link = "probit")), 
              se = FALSE) +
  geom_function(fun = test_model$curve[[1]], linetype = 2, lwd = 1.5) +
  theme_bw() +
  scale_x_log10()

请注意,两条模型线在此处完全对齐。

相关问题