3
$\begingroup$

I am using R to fit a logistic model to some data. The problem is as follows:

"The effects of the dose of poison $(x)$, in milligrammes, and the method of delivery $(w)$ on the probability of survival were examined in a study of rats. The two methods of delivery were as a solid with food or as a liquid in water. For each combination of dose and method of delivery, a certain number of rats $(r)$ were used and the number who survived $(y)$ is recorded. Below are the data.

enter image description here

Now when I plot these data, it looks like a model that has a different slope for each delivery method but the same intercept would be suitable:

enter image description here

How would I tell R to do this? I know that to fit a model with different intercepts but the same slope is "glm(p~x+w,...)" and to fit a model with two slopes and two intercepts is "glm(p~x+w+x:w,...)" but can't figure out the case for different slopes and the same intercept.

$\endgroup$

2 Answers 2

2
$\begingroup$

In order to have separate slopes for each group but equal intercepts, explicitly require that in the model.

Instead of

$$ \beta_0+\beta_1x_{group}+\beta_2x_{dose}+\beta_3x_{group}x_{dose}+\epsilon $$

try

$$ \beta_0+\beta_1x_{dose}+\beta_2x_{dose}+\epsilon $$

The R code would be something like glm(y~dose + dose:group, family = binomial). This takes the interaction between the dose and the group (to achieve multiple slopes) while excluding the interaction between the intercept and the two groups that you would get by regressing on the group variable on its own.

$\endgroup$
2
  • 1
    $\begingroup$ I don't think your R code is correct. I think it should be glm(y ~ dose:group, family = binomial). model.matrix(~ Sepal.Length * Species, data = droplevels(iris[iris$Species %in% c("versicolor", "virginica"),])) gives four columns in the design matrix. $\endgroup$
    – Roland
    Dec 9, 2022 at 6:50
  • $\begingroup$ @Roland Corrected to use a colon. $\endgroup$
    – Dave
    Dec 9, 2022 at 6:55
1
$\begingroup$

How do you determine that the intercept is the same for both methods of delivery $w$, from a plot of the observed probability of survival $p$ against the dose $x$?

Recall that a logistic regression is a linear model for the log odds (here, of survival): $$ \begin{aligned} \log\frac{\operatorname{P}(Y)}{1-\operatorname{P}(Y)} =\mathbf{X}\boldsymbol{\beta} \end{aligned} $$

So it's more informative to plot the log odds of survival on the y-axis:

This plot doesn't suggest to me to specify that the slope is the same for both $w$ but to add a quadratic term for $x$.

Here are two fits, both on the logit scale (the link function of the logistic regression is the logit). The first fit is for the model y ~ x + x:w; it has the same intercept, different slopes for $w$. The second fit is for the model y ~ w + rcs(x, 3): restricted cubic splines with 3 knots in the dose $x$, with a vertical shift between the two methods of delivery $w$. The second model suggests that the relationship between dose and the log odds of survival is mostly linear for $x\geq2$.

Created on 2022-12-11 with reprex v2.0.2

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.