[R] Error reporting in R

2008-10-20 Thread A.Noufaily

Hello,

I am hoping someone can help me with the following:

I am applying the function mle on a single data set X n times, each
time using a different set of initial values v[i] (i=1,...,n).
The initial values are all finite. Two cases arise:
A- For some sets of initial values mle is giving parameter estimates.
B- For some other initial values, mle is reporting the following error: 

Error in optim(start,f,method=method,hessian=TRUE,...):
Initial value in vmin is not finite

My aim is to tell R to return the estimates whenever case A, and to
return the word Error whenever case B (using an if statement inside
a loop).

How to tell R to return the word Error whenever mle reports the error
given above?
Is there a function similar to is.nan which tests the existence of an
error?

Any assistance would be much appreciated,

Regards,

Amy

-
The Open University is incorporated by Royal Charter (RC 000391), an exempt 
charity in England  Wales and a charity registered in Scotland (SC 038302).

[[alternative HTML version deleted]]

__
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.


Re: [R] Error reporting in R

2008-10-20 Thread Duncan Murdoch

On 20/10/2008 5:39 AM, A.Noufaily wrote:

Hello,

I am hoping someone can help me with the following:

I am applying the function mle on a single data set X n times, each
time using a different set of initial values v[i] (i=1,...,n).
The initial values are all finite. Two cases arise:
A- For some sets of initial values mle is giving parameter estimates.
B- For some other initial values, mle is reporting the following error: 


Error in optim(start,f,method=method,hessian=TRUE,...):
Initial value in vmin is not finite

My aim is to tell R to return the estimates whenever case A, and to
return the word Error whenever case B (using an if statement inside
a loop).

How to tell R to return the word Error whenever mle reports the error
given above?
Is there a function similar to is.nan which tests the existence of an
error?


Normally an error halts evaluation, but see ?try.  The basic pattern is

result - try(mle(...))
if (inherits(result, try-error)) return(Error)
else return(result)

Duncan Murdoch

__
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.