predict.lr: Predict from a Logistic Regression model

View source: R/LogisticRegression.R

predict.lrR Documentation

Predict from a Logistic Regression model

Description

Predicted values of a certain type based on a lr object.

Usage

## S3 method for class 'lr'
predict(object, newdata = NULL, thresh = 0, type = "preds", ...)

Arguments

object

an object of class "lr", the output from lr

newdata

an optional data frame to predict from. If omitted, predictions will be from the original data frame used to fit the model.

thresh

an optional threshold parameter, see 'Details'.

type

type of predictions, can be one of "preds", "probs" or "vals", see 'Details'.

...

further arguments

Details

Predictions from a logistic regression model are formed by first multiplying the model matrix by the parameter vector, i.e.

f(x; \beta) := X \beta.

These values are outputted when the type argument is "vals". Predictions for the positive class can be obtained when these values are above a certain threshold value, the argument thresh, i.e.

f(x; \beta) \ge t,

where the threshold t is usually equal to zero. This is how the predictions are made when the type argument is "preds". To get probabilities, the sigmoid function is used on the values, i.e.

p(y=1) = 1/(1 + e^{-X \beta}).

Value

a vector of predictions, probabilities or values, depending on the input to type.

Examples

y = sample(0:1, 50, replace=TRUE)
d = data.frame(y = y, x = rnorm(10*y + 15))
fit = lr(y ~ x, data = d)
predict(fit, type="preds")

dannyjameswilliams/danielR documentation built on Aug. 20, 2023, 3:25 a.m.