[R] numericDeriv
Florent Bresson
f_bresson at yahoo.fr
Wed Nov 16 13:26:45 CET 2005
I have to compute some standard errors using the delta
method and so have to use the command "numericDeriv"
to get the desired gradient. Befor using it on my
complicated function, I've done a try with a simple
exemple :
x <- 1:5
numericDeriv(quote(x^2),"x")
and i get :
[1] 1 8 27 64 125 216
attr(,"gradient")
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] Inf 0 0 NaN 0 0
[2,] 0 0 0 NaN 0 0
[3,] 0 Inf 0 NaN 0 0
[4,] 0 0 0 NaN 0 0
[5,] 0 0 Inf NaN 0 0
[6,] 0 0 0 NaN 0 0
I don't understand the result. I thought I will get :
[1] 1 8 27 64 125 216
attr(,"gradient")
[,1]
[1,] 1
[2,] 4
[3,] 6
[4,] 8
[5,] 10
[6,] 12
The derivative of x^2 is still 2x, isn't it ?
Thanks for help
More information about the R-help
mailing list