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
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.