plotCalibration: Function for calibration plot and Hosmer-Lemeshow goodness of...

Description Usage Arguments Details Value References See Also Examples

Description

The function produces a calibration plot and provides Hosmer-Lemeshow goodness of fit test statistics.

Usage

1
2
plotCalibration(data, cOutcome, predRisk, groups, rangeaxis, 
plottitle, xlabel, ylabel, filename, fileplot, plottype)

Arguments

data

Data frame or numeric matrix that includes the outcome and predictor variables.

cOutcome

Column number of the outcome variable.

predRisk

Vector of predicted risks of all individuals in the dataset.

groups

Number of groups considered in Hosmer-Lemeshow test. Specification of groups is optional (default groups is 10).

rangeaxis

Range of x-axis and y-axis. Specification of rangeaxis is optional. Default is c(0,1).

plottitle

Title of the plot. Specification of plottitle is optional. Default is "Calibration plot".

xlabel

Label of x-axis Default. Specification of xlabel is optional. Default is "Predicted risk".

ylabel

Label of y-axis. Specification of ylabel is optional. Default is "Observed risk".

filename

Name of the output file in which the calibration table is saved. The file is saved as a txt file in the working directory. When no filename is specified, the output is not saved. Example: filename="calibration.txt"

fileplot

Name of the file that contains the calibation plot. The file is saved in the working directory in the format specified under plottype. Example: fileplot="plotname". Note that the extension is not specified here. When fileplot is not specified, the plot is not saved.

plottype

The format in which the plot is saved. Available formats are wmf, emf, png, jpg, jpeg, bmp, tif, tiff, ps, eps or pdf. Foe example, plottype="eps" will save the plot in eps format. When plottype is not specified, the plot will be saved in jpg format.

Details

Hosmer-Lemeshow test statistic is a measure of the fit of the model, comparing observed and predicted risks across subgroups of the population. The default number of groups is 10.

The function requires the outcome of interest and predicted risks of all individuals. Predicted risks can be obtained from the functions fitLogRegModel and predRisk or be imported from other packages or methods.

Value

The function creates a calibration plot and returns the following measures:

Chi_square

Chi square value of Hosmer-Lemeshow test

df

Degrees of freedom, which is (groups-2) where groups: number of groups

p_value

p-value of Hosmer-Lemeshow test for goodness of fit

References

Hosmer DW, Hosmer T, Le Cessie S, Lemeshow S. A comparison of goodness-of-fit tests for the logistic regression model. Stat Med 1997; 16:965-980.

See Also

predRisk

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
# specify dataset with outcome and predictor variables 
data(ExampleData)
# specify column number of the outcome variable
cOutcome <- 2

# fit a logistic regression model
# all steps needed to construct a logistic regression model are written in a function
# called 'ExampleModels', which is described on page 4-5
riskmodel <- ExampleModels()$riskModel2

# obtain predicted risks
predRisk <- predRisk(riskmodel)

# specify range of x-axis and y-axis  
rangeaxis <- c(0,1) 
# specify number of groups for Hosmer-Lemeshow test            
groups <- 10 

# compute calibration measures and produce calibration plot                          
plotCalibration(data=ExampleData, cOutcome=cOutcome, predRisk=predRisk, 
groups=groups, rangeaxis=rangeaxis)

PredictABEL documentation built on May 2, 2019, 5:01 p.m.