Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

grnd

A reorganization of the call to numDeriv grad() function.


Description

Provides a wrapper for the numDeriv approximation to the gradient of a user supplied objective function userfn.

Usage

grnd(par, userfn, ...)

Arguments

par

A vector of parameters to the user-supplied function fn

userfn

A user-supplied function

...

Other data needed to evaluate the user function.

Details

The Richardson method is used in this routine.

Value

grnd returns an approximation to the gradient of the function userfn

Examples

cat("Example of use of grnd\n")
require(numDeriv)
myfn<-function(xx, shift=100){
    ii<-1:length(xx)
    result<-shift+sum(xx^ii)
}
xx<-c(1,2,3,4)
ii<-1:length(xx)
print(xx)
gn<-grnd(xx,myfn, shift=0)
print(gn)
ga<-ii*xx^(ii-1)
cat("compare to\n")
print(ga)

optimx

Expanded Replacement and Extension of the 'optim' Function

v2020-4.2
GPL-2
Authors
John C Nash [aut, cre], Ravi Varadhan [aut], Gabor Grothendieck [ctb]
Initial release
2020-04-02

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.