[R] Numerical Derivatives in R

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sun Mar 12 19:31:18 CET 2006


"Gray Calhoun" <gcalhoun at ucsd.edu> writes:

> Tolga,
> 
> Look at numericDeriv.
> 
> > arbfun <- function(x) x^2
> > x <- 3
> > numericDeriv(quote(arbfun(x)), "x")
> [1] 9
> attr(,"gradient")
>      [,1]
> [1,]    6

However, numericDeriv is not particularly intelligent. It is
effectively doing what Tolga was trying not to. A more refined
function could be a good idea, e.g. implementing higher order
approximations, a tunable stepsize, box constraints...
 
> --Gray
> 
> On 3/12/06, Tolga Uzuner <tolga at coubros.com> wrote:
> > Hi,
> >
> > Suppose I have an arbitrary function:
> >
> > arbfun<-function(x) {...}
> >
> > Is there a robust implementation of a numerical derivative routine in R
> > which I can use to take it's derivative ? Something a bit more than
> > simple division by delta of the difference of evaluating the function at
> > x and x+delta...
> >
> > Perhaps there is a way to do this using D or deriv but I could not
> > figure it out. Trying:
> >
> > eval(deriv(function(x) arbfun(x),"x"),1)
> >
> > does not seem to work.
> >
> > Thanks,
> > Tolga
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> >
> 
> 
> --
> Gray Calhoun
> 
> Economics Department
> UC San Diego
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907




More information about the R-help mailing list