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

RE: st: obtaining AUC at each iteration when bootstrapping a logistic reg ression model


From   "David Harrison" <[email protected]>
To   <[email protected]>
Subject   RE: st: obtaining AUC at each iteration when bootstrapping a logistic reg ression model
Date   Wed, 21 Jul 2004 16:04:47 +0100

Marieke

In addition to Nick's observations, you still need the commands

 matrix B=e(b)
 local finvars : colfullnames(B)

after the -sw logit- command in -myboot- and -local vinf ...- should be inside the foreach loop, making it:

 foreach v of varlist age bmi pp {
     local vinf : list v in finvars
     return scalar `v'=`vinf'
 }

Note again that in version 8 it is important that nothing follows the -{- on the -foreach- line and that the -}- is on a line of its own.

You could also drop -r(rep78)- from the -bootstrap- command as this refers to a variable in auto.dta, but this probably won't stop it working.

Finally, -saving()- should be given as an option of -bootstrap-, not -save- as a separate command, and the -replace- option should also not be in the brackets of -saving()-, ie

 bootstrap ... saving(bootresults) replace

Hope this helps

David
[email protected]

-----Original Message-----
From: Nick Cox [mailto:[email protected]]
Sent: 21 July 2004 15:33
To: [email protected]
Subject: RE: st: obtaining AUC at each iteration when bootstrapping a
logistic reg ression model


Your -foreach- loop is at a minimum 3 lines, 
with "foreach" as one word and { } aligned
as here. 

foreach v of varlist age bmi pp {
	... 
}

I don't understand the line in the middle, but 
this is a start. 

Nick 
[email protected] 

> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of
> [email protected]
> Sent: 21 July 2004 15:25
> To: [email protected]
> Subject: RE: st: obtaining AUC at each iteration when bootstrapping a
> logistic reg ression model
> 
> 
> David and Nick,
> 
> Thanks for your help! 
> 
> While running the do file I encountered the following error message:  
> 		
> 		command -> myboot
> 		error when command executed on original dataset under
> version 8 control
> 		r(198);
> 
> By now, it is probably quite obvious to you that I am just 
> beginning to
> learn to work with Stata, so it might be something very 
> silly. Still, I hope
> you will help me.
> 
> This is the do-file (as applied to a (simplified version of) 
> my data set (my
> model has of course more independent variables)):
> 
> 	capture program drop myboot
> 	program myboot, rclass
> 	sw logistic ras age bmi pp, forward pe (.1) 
> 	local vinf : list v in finvars
> 	lroc, nograph
> 	return scalar area=r(area)
> 	for each v of varlist age bmi pp {return scalar `v'= ( 
> `vinf' " , "
> `v' " )>0}
> 	end
> 
> 	clear
> 	use "C:\My documents\prediction model.dta"
> 	sw logistic ras age bmi pp, forward pe(.1)
> 	lroc, nograph
> 	bootstrap "myboot" r(area) r(rep78) r(age) r(bmi) 
> r(pp), reps(100) 
> 	save (bootresults, replace)
> 
> 	clear 
> 	use bootresults
> 	list
> 
> This is the output: 
> 
> . capture program drop myboot
> 
> . program myboot, rclass
>   1. sw logistic ras age bmi pp, forward pe (.1) 
>   2. local vinf : list v in finvars
>   3. lroc, nograph
>   4. return scalar area=r(area)
>   5. for each v of varlist age bmi pp {return scalar `v'= ( 
> `vinf' " , " `v'
> " )>0}
>   6. end
> 
> . 
> . clear
> 
> . use "C:\My documents\prediction model.dta"
> 
> . sw logistic ras age bmi pp, forward pe(.1)
>                       begin with empty model
> p = 0.0001 <  0.1000  adding   age
> p = 0.0056 <  0.1000  adding   bmi
> 
> Logistic regression                               Number of obs   =
> 328
>                                                   LR chi2(2)      =
> 26.55
>                                                   Prob > chi2     =
> 0.0000
> Log likelihood = -154.12872                       Pseudo R2       =
> 0.0793
> 
> --------------------------------------------------------------
> --------------
> --
>          ras | Odds Ratio   Std. Err.      z    P>|z|     [95% Conf.
> Interval]
> -------------+------------------------------------------------
> --------------
> --
>          age |   1.052812   .0135307     4.00   0.000     1.026624
> 1.079669
>          bmi |    .909435   .0311763    -2.77   0.006     .8503382
> .972639
> --------------------------------------------------------------
> --------------
> --
> 
> . lroc, nograph
> 
> Logistic model for ras
> 
> number of observations =      328
> area under ROC curve   =   0.6926
> 
> . bootstrap "myboot" r(area) r(rep78) r(age) r(bmi) r(pp), reps(100) 
> 
> command -> myboot
> error when command executed on original dataset under version 
> 8 control
> r(198);
> 
> end of do-file
> r(198);
> 
> Many thanks in advance,
> 
> Marieke
> [email protected]
> 
> *
> *   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/
> 

*
*   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/



*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index