From: Andrew Clausen <clausen_at_econ.upenn.edu>

Date: Sun, 13 May 2007 13:22:41 -0400

R-devel_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sun 13 May 2007 - 17:27:05 GMT

Date: Sun, 13 May 2007 13:22:41 -0400

I wrote a symbollic differentiation function in R, which can be downloaded here:

http://www.econ.upenn.edu/~clausen/computing/Deriv.R http://www.econ.upenn.edu/~clausen/computing/Simplify.R

It is just a prototype. Of course, R already contains two differentiation functions: D and deriv. However, these functions have several limitations. They can probably be fixed, but since they are written in C, this would require a lot of work. Limitations include:

- The derivatives table can't be modified at runtime, and is only available in C.
- The output of "deriv" can not be differentiated again.
- Neither function can substitute function calls. eg: f <- function(x, y) x + y; deriv(f(x, x^2), "x")
- They can't differentiate vector-valued functions (although my code also can't do this yet)

ll <- function(mean, sd) -sum(log(dnorm(x, mean, sd))) ll.deriv <- Deriv.function(ll)

I can't get this to work with my code since:

- since sum can't add a list of vectors (although I could easily write a sum replacement.)
- "x" is assumed to be a scalar in this contect. I'm not sure if there's a good way to generalize.

The above code would work right now if there were one parameter (so sum doesn't screw it up) and one scalar data point "x".

Is there an existing way of doing this that is close to being this convenient? Is it really much easier to solve the limitations I listed with a fresh R implementation?

Cheers,

Andrew

R-devel_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sun 13 May 2007 - 17:27:05 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Sun 13 May 2007 - 19:33:45 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel.
Please read the posting
guide before posting to the list.
*