[R] Help with workaround for: Function '`[`' is not in the derivatives table

Earl F. Glynn efg at stowers-institute.org
Tue Aug 15 00:44:26 CEST 2006


# This works fine:
> a <- 1

> b <- 2

> c <- 3



> E <- expression(a * exp(b*X) + c)



> X <- c(0.5, 1.0, 2.0)



> eval(E)

[1]  5.718282 10.389056 57.598150



> D(E, "b")

a * (exp(b * X) * X)

> eval(D(E, "b"))

[1]   1.359141   7.389056 109.196300



# But if (a,b,c) are replaced with (A[1], A[2], A[3]), how can I get a 
derivative using "D"?



> A <- c(1, 2, 3)

> E <- expression(A[1] * exp(A[2]*X) + A[3])

> X <- c(0.5, 1.0, 2.0)

> eval(E)

[1]  5.718282 10.389056 57.598150



# Why doesn't this work?  Any workarounds?

> D(E, "A[2]")

Error in D(E, "A[2]") : Function '`[`' is not in the derivatives table



If I want to have a long vector of coefficients, A, (perhaps dozens) how can 
I use "D" to compute partial derivatives?



Thanks for any help with this.



efg



Earl F. Glynn

Scientific Programmer

Stowers Institute for Medical Research



More information about the R-help mailing list