[R] debugging a try() statement

From: Juliet Hannah <juliet.hannah_at_gmail.com>
Date: Tue, 19 Feb 2008 21:35:11 -0500


Dear R Users,

I implemented a try() statement that looks like:

 <- function(index)
{

   reduced_model <- try(glm.fit(X4,n,family=poisson(link="log")))    full_model <- try(glm.fit(X5,n,family=poisson(link="log")))

   if (inherits(reduced_model,"try-error") || inherits(full_model,"try-error")) return(NA)

   else
   {
     p <- pchisq(reduced_model$deviance - full_model$deviance, reduced_model$df.residual - full_model$df.residual, lower.tail= FALSE)

     return (p)
   }

}

After an error occurs NA is returned. But after this occurs, all values returned after this remain as an NA even though this error should occur only 1/500 to 1/1000 times.

For example, I end up with a matrix like this:

       [,1] [,2] [,3] [,4] [,5]
[1,] 0.6291316 0.08900112 0.06693455 6.401101e-06 0.06865330
[2,] 0.6259834 0.21140489 0.06722201 6.401101e-06 0.06833421
[3,] NA NA NA NA NA
[4,] NA NA NA NA NA
[5,] NA NA NA NA NA

Is there anything obviously incorrect with my function above. If not, I will post a full example to illustrate my question.

Thanks for your help,

Juliet



R-help_at_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. Received on Wed 20 Feb 2008 - 02:38:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 20 Feb 2008 - 04:30:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive