0
$\begingroup$

I'm modeling a set of outcome data the depends on two parameters:

  1. time, T
  2. -100 < A < 100

I've done logistic regression using R with the command:

model <- glm(Outcome ~ A + T, family = "binomial", data = myData)

My expectation (the only thing that makes sense) is that when A < 0, the fit probability should be an increasing function of time approaching 0.5, while when A > 0 it should be a decreasing function of time approaching 0.5.

However, the fit I get is that A < 0, A > 0, and A = 0 all are increasing functions of time. They in fact appear to be the same curve just shifted (ie same "shape").

What am I doing incorrectly? Any suggestions?

$\endgroup$

2 Answers 2

1
$\begingroup$

The way you have it modeled, you can't get what you expect, since you can only get one model. It will be the same for all values of A.

There are various ways to model your case. Perhaps the simplest is to separate the data into two or three sets (depending on exactly what you want) based on values of A: (untested code)

out <- subset(myData, abs(Y) > 100)
in <- subset(myData, abs(Y) le 100)
m1 <- glm(y ~ A + T, family = binomial, data = in)
m2 <- glm(y ~ A + T, family = binomial, data = out)

However, this could produce odd results in that the curves may be very different at values just under and over 100 (in absolute value).

A better method would be splines. I am not expert in these in R but there are several packages that might help (gam, mgcv). Also, there is a long discussion of these in Frank Harrell's book Regression Modeling Strategies.

Somewhere in between these two is using additional terms in your model. Something like this might be helpful (also untested code):

AIn <- ifelse(abs(A) < 100, 1, 0)
m3 <- glm(y ~ A + T + AIn, family = binomial, data = myData)

You might also want interactions of AIn with the other variables.

$\endgroup$
0
$\begingroup$

You're using a linear model where the model can only generate values that are decreasing or increasing, not both.** You'd need something like a quadratic to have both. You might want to look at polynomial regression (where you can model curves) and perhaps GAM (generalized additive modelling). These can do what you want. You should probably visualize the data using loess models first.

**I know plotting a logistic in probability space is curvy but it's a straight line in log odds space. And either way it's still only increasing or decreasing.

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.