validate_moment {aghq} | R Documentation |
Validate a moment function object
Description
Routine for checking whether a given moment function object is valid.
Usage
validate_moment(...)
## S3 method for class 'aghqmoment'
validate_moment(moment, checkpositive = FALSE, ...)
## S3 method for class 'list'
validate_moment(moment, checkpositive = FALSE, ...)
## S3 method for class ''function''
validate_moment(moment, checkpositive = FALSE, ...)
## S3 method for class 'character'
validate_moment(moment, checkpositive = FALSE, ...)
## Default S3 method:
validate_moment(moment, ...)
Arguments
... |
Used to pass arguments to methods. |
moment |
An object to check if it is a valid moment function or not. Can be an object of class |
checkpositive |
Default |
Details
This function checks that:
The supplied object contains elements
fn
,gr
, andhe
, and that they are all functions,If
checkpositive
is a vector of numbers, then it checks thatgg$fn(checkpositive)
is not-Inf
,NA
, orNaN
. (It actually usesis.infinite
for the first.)
In addition, if a list
is provided, the function first checks that it contains the right elements,
then passes it to make_moment_function
, then checks that. If a function
or a character
is provided,
it checks that match.fun
works, and returns any errors or warnings from doing so in a clear way.
This function throws an informative error messages when checks don't pass or themselves throw errors.
Value
TRUE
if the function runs to completion without throwing an error.
See Also
Other moments:
make_moment_function()
Examples
mom1 <- make_moment_function(exp)
mom2 <- make_moment_function('exp')
mom3 <- make_moment_function(list(fn=function(x) x,gr=function(x) 1,he = function(x) 0))
validate_moment(mom1)
validate_moment(mom2)
validate_moment(mom3)
## Not run:
mombad1 <- list(exp,exp,exp) # No names
mombad2 <- list('exp','exp','exp') # List of not functions
mombad3 <- make_moment_function(function(x) -exp(x)) # Not positive
validate_moment(mombad1)
validate_moment(mombad2)
validate_moment(mombad3)
## End(Not run)