gfitLogReg: Goodness of fit of a Logistic Regression

Description Usage Arguments Value Author(s) See Also Examples

Description

Make a goodness of fit plot (observed vs predicted values) in a logistic regression context. Optionally, a table with numerical results (including a chi-squared test) can be produced.

Usage

1
2
3
gfitLogReg(obs, pred, groups, print.table = FALSE, main = "Goodness of fit",
  xlab = "Observations", ylab = "Predictions", xlim = c(0, 1), pch = 16,
  ps = 2, cex.lab = 1.2, cex.axis = 1.1, las = 1, ...)

Arguments

obs

numeric vector with observations (either 0 or 1)

pred

numeric vector (same length as obs) with fitted model probabilities

groups

Number of groups (bins) to divide the data into. If missing, the default is 10.

print.table

Logical (default is FALSE).

...

other arguments (e.g. xlim, xlab, main, ...) to be passed to plot. Some default values have been chosen.

Value

A goodness of fit plot. Optionally (if print.table=T), also a table. See plotCalibration from package PredictABEL.

Author(s)

Paco, based on function plotCalibration from package PredictABEL.

See Also

plotCalibration from package PredictABEL

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Generate some data
x <- seq(1:1000)
yhat <- plogis(0.2 + 0.003*x)   # inverse logit
y <- rbinom(1000, 1, yhat)

# Fit model and get predicted probabilities
model <- glm(y~x, family="binomial")
ypred <- predict(model, type="response")

# Check goodness of fit
gfitLogReg(y, ypred)
gfitLogReg(y, ypred, print.table=TRUE)
gfitLogReg(y, ypred, xlim=c(0.5,1))
gfitLogReg(y, ypred, groups=5)

Pakillo/pacotools documentation built on May 7, 2019, 11:56 p.m.