The logisticLackfit action computes the Hosmer and Lemeshow goodness-of-fit test for a logistic regression model. This test assesses whether the observed event rates match the expected event rates in subgroups of the model population. It is a key diagnostic for evaluating the calibration of a logistic regression model.
| Parameter | Description |
|---|---|
| binEps | Specifies the precision of the predicted probabilities that are used for classification. Default: 1E-05. |
| cutpt | Specifies cutpoints for the Hosmer and Lemeshow partitions. |
| df | Specifies the degrees of freedom to use for the Hosmer and Lemeshow test. |
| dfReduce | Specifies the reduction in degrees of freedom for the Hosmer and Lemeshow test. Default: 2. |
| display | Specifies a list of results tables to send to the client for display. |
| nGroups | Specifies the maximum number of groups to create for the Hosmer and Lemeshow test. Default: 10. |
| noncentrality | Specifies the noncentrality parameter for the Hosmer and Lemeshow test. Default: 0. |
| outputTables | Lists the names of results tables to save as CAS tables on the server. |
| powerAdj | When set to True, adjusts the number of groups so that the Hosmer and Lemeshow test can maintain power. Default: FALSE. |
| restore | Restores a logistic regression model from a saved item store (a CAS table containing a BLOB) to perform the lack-of-fit test. |
| table | Specifies the input data table to be used for the test. This is typically the same data used to fit the model. |
This SAS code creates a dataset named 'getheart' with patient information, including a binary outcome 'Status' (Dead or Alive) and several risk factors. This data will first be used to train a logistic regression model, and then to evaluate its goodness-of-fit.
| 1 | DATA getheart; |
| 2 | LENGTH STATUS $ 6; |
| 3 | INFILE CARDS; |
| 4 | INPUT STATUS $ Age Weight Chol; |
| 5 | CARDS; |
| 6 | Alive 55 180 250 |
| 7 | Dead 60 200 300 |
| 8 | Alive 50 170 220 |
| 9 | Dead 65 210 320 |
| 10 | Alive 45 160 210 |
| 11 | Dead 70 220 350 |
| 12 | Alive 58 185 260 |
| 13 | Dead 62 205 310 |
| 14 | ; |
| 15 | RUN; |
| 16 | |
| 17 | PROC CASUTIL; |
| 18 | load DATA=getheart outcaslib='casuser' casout='getheart' replace; |
| 19 | QUIT; |
This example first fits a logistic regression model on the 'getheart' data to predict 'Status' based on 'Age' and 'Weight', saving the model into a store named 'myModelStore'. It then uses the `logisticLackfit` action to perform the default Hosmer-Lemeshow test on the restored model.
| 1 | PROC CAS; |
| 2 | regression.logistic TABLE='getheart' class={'Status'} model={depvar='Status', effects={'Age', 'Weight'}} store={name='myModelStore', replace=true}; |
| 3 | QUIT; |
| 4 | PROC CAS; |
| 5 | regression.logisticLackfit TABLE='getheart' restore='myModelStore'; |
| 6 | QUIT; |
This example performs the Hosmer-Lemeshow test using a custom number of groups. After fitting the logistic regression model and creating the store 'myModelStore', the `logisticLackfit` action is called with `nGroups=8`, partitioning the data into 8 groups based on predicted probabilities instead of the default 10.
| 1 | PROC CAS; |
| 2 | regression.logistic TABLE='getheart' class={'Status'} model={depvar='Status', effects={'Age', 'Weight', 'Chol'}} store={name='myModelStore', replace=true}; |
| 3 | QUIT; |
| 4 | PROC CAS; |
| 5 | regression.logisticLackfit TABLE='getheart' restore='myModelStore' nGroups=8; |
| 6 | QUIT; |
This example demonstrates using specific cutpoints to define the risk groups for the test. After fitting the model, `logisticLackfit` is called with the `cutpt` parameter, which explicitly defines the upper boundaries of the predicted probability for each group. This allows for a more tailored assessment of fit across specific probability ranges.
| 1 | PROC CAS; |
| 2 | regression.logistic TABLE='getheart' class={'Status'} model={depvar='Status', effects={'Age', 'Weight', 'Chol'}} store={name='myModelStore', replace=true}; |
| 3 | QUIT; |
| 4 | PROC CAS; |
| 5 | regression.logisticLackfit TABLE='getheart' restore='myModelStore' cutpt={0.2, 0.4, 0.6, 0.8}; |
| 6 | QUIT; |