Reputation: 1
I am trying to plot dose-response curves using the drc package using the reduced log-normal fit (LN.2), which should be equivalent to the probit dose-response model. When I use the 'predict' function for both the glm package derived probit model (with dose log10 transformed) and the drc model, the outputs are equivalent as expected.
However, when I use the drc method in geom_smooth, the graphical output is completely different than these predicted values.
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()
Here is an example of the behavior.
Upvotes: 0
Views: 238
Reputation: 173793
You need to account for the log-transformed x axis values being passed as the input to the predict
function. You have already done this with glm
, since you are using y ~ x
as the formula instead of y ~ log(x)
, but it will not really work with drm
. However, it isn't really necessary to use geom_smooth
here, since your model already includes a function to recreate the curve using 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()
Note that the two model lines line up perfectly here.
Upvotes: 2