On Dec 31, 2009, at 8:29 AM, John Sorkin wrote:

I have written a function that contains runs
lm()
vif()  and
glm()

When the glm() blows up with an error message, I don't get the output from either the lm() or vf() even thought neither lm() nor vif() have any problems . How can I force the function to print sequential results rather than wait for the entire function to complete before listing the functhion's output?
Thanks,
John

I thought the usual method for graceful error recovery was to use the try or tryCatch functions.


minBMI<-function(SS,SimData)
{
SampleData<-sample(1:SS,size=SS,replace=TRUE)
fitBMIEpiRevlm<-lm(AAMTCARE~BMIEpiRevAdjc+BMIEpiRevAdjcSq+SEX+jPHI +jMEDICAID+H_AGE+jMARSTAT +factor(jEDUCATION) +factor(jsmokercat) +factor(jrace)+log(INCOME_C+1),data=SimData[SampleData,],x=TRUE)
print(summary(fitBMIEpiRevlm))
print(vif(fitBMIEpiRevlm))
#Perhaps (untested):
try( {
fitBMIEpiRev<- glm(AAMTCARE~BMIEpiRevAdjc+BMIEpiRevAdjcSq+SEX+jPHI +jMEDICAID+H_AGE +jMARSTAT+factor(jEDUCATION) +factor(jsmokercat) +factor(jrace)+log(INCOME_C +1),data=SimData[SampleData,],family=Gamma(link="log"))

print(summary(fitBMIEpiRev))
      } )
}
minBMI(SS,SimData)

--
David.


John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to