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 aghqmoment returned by aghq::make_moment_function(), or any object that can be passed to aghq::make_moment_function().

checkpositive

Default FALSE, do not check that gg$fn(theta) > 0. Otherwise, a vector of values for which to perform that check. No default values are provided, since validate_moment has no way of determining the domain and range of gg$fn. This argument is used internally in aghq package functions, with cleverly chosen check values.

Details

This function checks that:

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)

[Package aghq version 0.4.1 Index]