Site menu:



R functions for complex-step differentiation

complex-step method is a clever way of obtaining a numerical approximation to the first derivative of a function, avoiding the round-off error that plagues standard first difference approximations [Ref 1]. An extension of the method allows second derivatives to be calculated with reduced round-off error. [Ref 2] gives an overview of the method with statistical examples.

Here are the R programs for the examples in that article. The examples are all from the book by Brazzale, Davison and Reid [Ref 3].

bdr23.R     bdr35exp.R     bdr35ln.R     bdr43.R    
bdr46.R     bdr52.R          bdr52t4.R     bdr54.R

You will also need the files CStepDiff_functions.R and examples.R.

Put all the files in a single directory and run R with this directory as the working directory. Typing
source("examples.R")
will generate the results in Table 3 of [Ref 2].

Since [Ref 2] was written, I have had to make two changes to the code:

References

[1] Squire, W. and Trapp, G. (1998). Using complex variables to estimate derivatives of real functions. SIAM Review, 40, 110-112. doi: 10.1137/S003614459631241X [pdf]

[2] Ridout M.S. (2009). Statistical applications of the complex-step method of numerical differentiation American Statistician, 63, 66-74. doi: 10.1198/tast.2009.0013

[3] Brazzale, A.R., Davison, A.C. and Reid, N. (2007). Applied Asymptotics: Case Studies in Small-Sample Statistics, Cambridge: Cambridge University Press. doi: 10.1017/CBO9780511611131