[R] help on using try() to catch an error

From: Juliet Hannah <juliet.hannah_at_gmail.com>
Date: Thu, 14 Feb 2008 23:49:49 -0500

Dear R Users,

I have the following glm, which I am running several times in a loop (I am not including the full code):

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

On some occasions, an error is produced, which is why I have attempted to work around this with try().

I then have the following statement, which checks if full_model or reduced_model are still NULL.

if (is.null(reduced_model) || is.null(full_model)) p <- NA else p <- pchisq(reduced_model$deviance - full_model$deviance, reduced_model$df.residual - full_model$df.residual, lower.tail= FALSE); This is not solving my problem meaning my program still stops and gives me the following error:

Error in ifelse(y == 0, 1, y/mu) : dim<- : dims [product 9] do not match the length of object [18]
Error in pmatrix[perm, ] <- apply(pairs.subset, 1, getLRTp2) :

        nothing to replace with

Can you help me figure out what I have done incorrectly?

Thanks for your time,


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 Fri 15 Feb 2008 - 07:57:15 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 Fri 15 Feb 2008 - 09:30:13 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