= Stata estat = '''`estat`''' is a post-estimation command. <> ---- == Usage == === Vce === === Gof === To calculate goodness of fit for a model, try: {{{ . use https://www.stata-press.com/data/r18/lbw (Hosmer & Lemeshow data) . logistic low age lwt i.race smoke ptl ht ui Logistic regression Number of obs = 189 LR chi2(8) = 33.22 Prob > chi2 = 0.0001 Log likelihood = -100.724 Pseudo R2 = 0.1416 ------------------------------------------------------------------------------ low | Odds ratio Std. err. z P>|z| [95% conf. interval] -------------+---------------------------------------------------------------- age | .9732636 .0354759 -0.74 0.457 .9061578 1.045339 lwt | .9849634 .0068217 -2.19 0.029 .9716834 .9984249 | race | Black | 3.534767 1.860737 2.40 0.016 1.259736 9.918406 Other | 2.368079 1.039949 1.96 0.050 1.001356 5.600207 | smoke | 2.517698 1.00916 2.30 0.021 1.147676 5.523162 ptl | 1.719161 .5952579 1.56 0.118 .8721455 3.388787 ht | 6.249602 4.322408 2.65 0.008 1.611152 24.24199 ui | 2.1351 .9808153 1.65 0.099 .8677528 5.2534 _cons | 1.586014 1.910496 0.38 0.702 .1496092 16.8134 ------------------------------------------------------------------------------ Note: _cons estimates baseline odds. . estat gof Goodness-of-fit test after logistic model Variable: low Number of observations = 189 Number of covariate patterns = 182 Pearson chi2(173) = 179.24 Prob > chi2 = 0.3567 }}} The [[Statistics/PearsonChiSquaredTest|Pearson chi-squared test]] is not significant, so the model is not rejected. However, when the number of covariate patterns approaches the number of observations, the Pearson chi-squared test is not necessarily applicable. Using the '''group''' option, dividing the observations into n-tiles, is a possible solution. {{{ . estat gof, group(10) note: obs collapsed on 10 quantiles of estimated probabilities. Goodness-of-fit test after logistic model Variable: low Number of observations = 189 Number of groups = 10 Hosmer–Lemeshow chi2(8) = 9.65 Prob > chi2 = 0.2904 }}} The [[Statistics/HosmerLemeshowTest|Hosmer-Lemeshow test]] also is not significant, so the model is still not rejected. However, it should be noted that the Hosmer-Lemeshow test is not stable to n-tiles thresholds. The `gof` subcommand is compatible with [[Stata/Svy|survey data]]. {{{ . use https://www.stata-press.com/data/r18/nhanes2d . svy: logistic highbp height weight age female [snip] . estat gof Logistic model for highbp, goodness-of-fit test F(9,23) = 5.32 Prob > F = 0.0006 }}} The F-statistic is significant, so the model is not a good fit. === Classification === ---- == See also == [[https://www.stata.com/manuals/restat.pdf|Stata manual for estat]] [[https://www.stata.com/manuals/restatvce.pdf|Stata manual for estat vce]] [[https://www.stata.com/manuals/restatgof.pdf|Stata manual for estat gof]] (this page specifically for [[Stata/Logistic|logitic]], [[Stata/Logit|logit]], or [[Stata/Probit|probit]] models) [[https://www.stata.com/manuals/restatclassification.pdf|Stata manual for estat classification]] ---- CategoryRicottone