View source: R/03-summary-statistics.R
validate_moment | R Documentation |
Routine for checking whether a given moment function object is valid.
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, ...)
... |
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 |
This function checks that:
The supplied object contains elements fn
, gr
, and he
, and that they are all functions,
If checkpositive
is a vector of numbers, then it checks that gg$fn(checkpositive)
is not -Inf
, NA
, or NaN
. (It actually uses is.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.
TRUE
if the function runs to completion without throwing an error.
Other moments:
make_moment_function()
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.