Quantcast

error capture

classic Classic list List threaded Threaded
4 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

error capture

Tim Reid-2
Hi all,

I am currently running some R code bootstrapping some data and
running GLMs on the sampled data sets. Occasionally the data sets
that are sampled cause errors in the GLM (usually with the message
"Error in solve.default(as.matrix(fit$hessian)) "). Currently, if
this occurs, the program stops and exits. I would like to know if
there is a way I can instead of having the program terminate, to get
the program to step through that problem and continue further on in
the program (i.e. getting it to re-sample the data again).

Any help would be much appreciated,
tim.


-----------------------------------------------------------------------
Tim Reid | PhD Candidate

Quantitative Marine Sciences/ Antarctic Wildlife Research Unit
School of Zoology
University of Tasmania
PO Box 252-05
Hobart Tasmania 7001
Australia

phone:  +61 3 6226 2594 | mob: 0404 668 363
www.zoo.utas.edu.au/awru/


        [[alternative HTML version deleted]]

_______________________________________________
R-sig-ecology mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: error capture

Christian A. Parker
Check out the try function (?try). You would have to use try within the
loop, at the step that has the potential to throw an error, and not
around the whole loop.
Hope this helps,
-Chris

Tim Reid wrote:

> Hi all,
>
> I am currently running some R code bootstrapping some data and
> running GLMs on the sampled data sets. Occasionally the data sets
> that are sampled cause errors in the GLM (usually with the message
> "Error in solve.default(as.matrix(fit$hessian)) "). Currently, if
> this occurs, the program stops and exits. I would like to know if
> there is a way I can instead of having the program terminate, to get
> the program to step through that problem and continue further on in
> the program (i.e. getting it to re-sample the data again).
>
> Any help would be much appreciated,
> tim.
>
>
> -----------------------------------------------------------------------
> Tim Reid | PhD Candidate
>
> Quantitative Marine Sciences/ Antarctic Wildlife Research Unit
> School of Zoology
> University of Tasmania
> PO Box 252-05
> Hobart Tasmania 7001
> Australia
>
> phone:  +61 3 6226 2594 | mob: 0404 668 363
> www.zoo.utas.edu.au/awru/
>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-ecology mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>
>

_______________________________________________
R-sig-ecology mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: error capture

Mike Colvin
In reply to this post by Tim Reid-2
Tim,

You might use try which will catch the error and allow you to handle what
happens.
Usually something like this works to get parameter estimates

for (i in 1:1000){
fit<-try(lm(y~x,dataset))
results<- ifelse(class(fit)=="try-error", NA, fit$coefficients)
}

HTH
Mike



On Sun, May 4, 2008 at 11:52 PM, Tim Reid <[hidden email]> wrote:

> Hi all,
>
> I am currently running some R code bootstrapping some data and
> running GLMs on the sampled data sets. Occasionally the data sets
> that are sampled cause errors in the GLM (usually with the message
> "Error in solve.default(as.matrix(fit$hessian)) "). Currently, if
> this occurs, the program stops and exits. I would like to know if
> there is a way I can instead of having the program terminate, to get
> the program to step through that problem and continue further on in
> the program (i.e. getting it to re-sample the data again).
>
> Any help would be much appreciated,
> tim.
>
>
> -----------------------------------------------------------------------
> Tim Reid | PhD Candidate
>
> Quantitative Marine Sciences/ Antarctic Wildlife Research Unit
> School of Zoology
> University of Tasmania
> PO Box 252-05
> Hobart Tasmania 7001
> Australia
>
> phone:  +61 3 6226 2594 | mob: 0404 668 363
> www.zoo.utas.edu.au/awru/
>
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-ecology mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-ecology mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: error capture

Kingsford Jones
In reply to this post by Tim Reid-2
FAQ 7.32 indicates why 'tryCatch' may be preferable to 'try' for this
sort of thing:

http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-capture-or-ignore-errors-in-a-long-simulation_003f


Kingsford Jones

On Sun, May 4, 2008 at 9:52 PM, Tim Reid <[hidden email]> wrote:

> Hi all,
>
>  I am currently running some R code bootstrapping some data and
>  running GLMs on the sampled data sets. Occasionally the data sets
>  that are sampled cause errors in the GLM (usually with the message
>  "Error in solve.default(as.matrix(fit$hessian)) "). Currently, if
>  this occurs, the program stops and exits. I would like to know if
>  there is a way I can instead of having the program terminate, to get
>  the program to step through that problem and continue further on in
>  the program (i.e. getting it to re-sample the data again).
>
>  Any help would be much appreciated,
>  tim.
>
>
>  -----------------------------------------------------------------------
>  Tim Reid | PhD Candidate
>
>  Quantitative Marine Sciences/ Antarctic Wildlife Research Unit
>  School of Zoology
>  University of Tasmania
>  PO Box 252-05
>  Hobart Tasmania 7001
>  Australia
>
>  phone:  +61 3 6226 2594 | mob: 0404 668 363
>  www.zoo.utas.edu.au/awru/
>
>
>         [[alternative HTML version deleted]]
>
>  _______________________________________________
>  R-sig-ecology mailing list
>  [hidden email]
>  https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>

_______________________________________________
R-sig-ecology mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Loading...