constrained.logit: Constrained logistic regression

View source: R/26_CONSTRAINED_LOGIT.R

constrained.logitR Documentation

Constrained logistic regression

Description

constrained.logit performs estimation of logistic regression with constrains on values of the estimated coefficient.

Usage

constrained.logit(db, x, y, lower, upper)

Arguments

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 x plus one.

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 x plus one.

Value

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.

Examples

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)

PDtoolkit documentation built on Sept. 20, 2023, 9:06 a.m.