View source: R/26_CONSTRAINED_LOGIT.R
constrained.logit | R Documentation |
constrained.logit
performs estimation of logistic regression with constrains on values of the
estimated coefficient.
constrained.logit(db, x, y, lower, upper)
db |
Data set of risk factors and target variable. |
x |
Character vector of risk factors (independent variables) used in logistic regression. |
y |
Character vector of target (dependent variable) used in logistic regression. |
lower |
Numeric vector of lower boundaries of the coefficients. This vector should contain value of the intercept,
therefore number of elements should be equal to number of elements of the argument |
upper |
Numeric vector of upper boundaries of the coefficients. This vector should contain value of the intercept,
therefore number of elements should be equal to number of elements of the argument |
The command constrained.logit
returns list of two vectors. The first vector contains values of the
estimated coefficients, while the second vector contains predictions of the constrained logistic regression.
suppressMessages(library(PDtoolkit))
data(loans)
#model 1
reg.1 <- glm(Creditability ~ `Account Balance`, family = "binomial", data = loans)
summary(reg.1)$coefficient
loans$pred.1 <- unname(predict(reg.1, type = "response"))
#model 2
reg.2 <- glm(Creditability ~ `Age (years)`, family = "binomial", data = loans)
summary(reg.2)$coefficient
loans$pred.2 <- unname(predict(reg.2, type = "response"))
#integration
fm <- glm(Creditability ~ pred.1 + pred.2, family = "binomial", data = loans)
summary(fm)$coefficient
fm.pred <- predict(fm, type = "response", newdata = loans)
auc.model(predictions = fm.pred, observed = loans$Creditability)
#constrained integration (regression)
cl.r <- constrained.logit(db = loans,
x = c("pred.1", "pred.2"),
y = "Creditability",
lower = c(-Inf, -Inf, -Inf),
upper = c(Inf, 4.5, Inf))
names(cl.r)
cl.r[["beta"]]
auc.model(predictions = cl.r[["prediction"]], observed = loans$Creditability)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.