# logistic regression always yielding increasing f'n when should sometimes be decreasing (using R)

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?

-

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.

-