[R] Logistic regression with rcs() and inequality constraints?
Stephan Kolassa
Stephan.Kolassa at gmx.de
Sun Dec 28 21:58:37 CET 2008
Dear guRus,
I am doing a logistic regression using restricted cubic splines via
rcs(). However, the fitted probabilities should be nondecreasing with
increasing predictor. Example:
predictor <- seq(1,20)
y <- c(rep(0,9),rep(1,10),0)
model <- glm(y~rcs(predictor,n.knots=3),family="binomial")
print(1/(1+exp(-predict(model))))
The last expression should be a nondecreasing sequence, as fitted
probabilities make no sense to decrease in this case.
Is there any elegant way to constrain the model fit?
Right now, I am trying to do this by defining a "large" set of linear
inequalities and using constrOptim() on the log-likelihood. However,
this seems to be very sensitive to the starting values, and I am not
really happy with the results.
BTW: yes, working with lrm() would probably be more natural, but lrm()
breaks down on my data because of a rank-deficient information matrix.
Thank you for your time!
Stephan Kolassa
More information about the R-help
mailing list