【Description】
crossfold performs k-fold cross-validation on a specified modelin order to evaluate a model's
ability to fit out-of-sample data.
This procedure splits the data randomly into k partitions, thenfor each partition it fits the
specified model using the other k-1 groups and uses the resultingparameters to predict the
dependent variable in the unused group.
Finally, crossfold reports a measure of goodness-of-fit fromeach attempt. The default
evaluation metric is root mean squared error (RMSE).
【Examples】
. sysuse nlsw88
(NLSW, 1988 extract)
. crossfold reg wage union
|RMSE
-------------+-----------
est1 | 4.171849
est2 | 4.105884
est3 | 4.038483
est4 | 4.151482
est5 | 4.171727
. crossfold reg wage union, mae
|MAE
-------------+-----------
est1 | 2.99209
est2 | 3.13541
est3 | 3.158161
est4 | 3.035878
est5 | 3.006016
.crossfold reg wage hours grade i.race i.industry i.occupation,r2
| Pseudo-R2
-------------+-----------
est1 | .2036234
est2 | .1804039
est3 | .2213548
est4 | .2159976
est5 | .1556564
. crossfold qreg wage union [weight=hours], eweight(hours)mae
(importance weights assumed)
|MAE
-------------+-----------
est1 | 3.078402
est2 | 2.864632
est3 | 2.846198
est4 | 2.989049
est5 | 2.990051
. crossfold qreg wage union collgrad age grade [weight=hours],eweight(hours) k(3) mae
(importance weights assumed)
|MAE
-------------+-----------
est1 | 2.449628
est2 | 2.700219
est3 | 2.588182