Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: predictive model


From   "Scott Merryman" <smerryman@kc.rr.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: predictive model
Date   Mon, 5 Sep 2005 20:26:59 -0500

> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-
> statalist@hsphsun2.harvard.edu] On Behalf Of marta@biometria.univr.it
> Sent: Monday, September 05, 2005 1:57 PM
> To: statalist@hsphsun2.harvard.edu
> Subject: st: predictive model
> 
> dear statalist members,
> 
> I've set up a multiple linear regression model, and I've to evaluate the
> predictive power of the model: in order to obtain the prediction error,
> I'd use
> the 10 fold cross validation: is it possible with stata?
> 
> thank,
> 
> Marta
> 

Does this method involve dividing the data into 10 subsets of equal size;
running the regression 10 times, each time leaving out one of the subsets
and using the omitted subset to compute the error criterion?

I believe this might work:

sysuse auto,clear
gen random = uniform()
sort random
gen group = group(10)
forv i = 1/10 {
	qui {
	reg mpg gear weight head if group != `i'
	predict res if group == `i', res 
	replace res = res^2 
	sum res, meanonly
	local mse = r(mean)
	local error "`error' + `mse'"
	drop res
	}
	}
disp "MSE (10 Fold) = "(`error')/10


Hope this helps,
Scott



*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index