From: Berton Gunter <gunter.berton_at_gene.com>

Date: Tue 15 Aug 2006 - 09:10:45 EST

R-help@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 and provide commented, minimal, self-contained, reproducible code. Received on Tue Aug 15 09:43:12 2006

Date: Tue 15 Aug 2006 - 09:10:45 EST

I think this is the sort of problem which is most elegantly handled by
computing on the language. Here is an INelegant solution:

> for(i in 1:3)assign(paste('A',i,sep=''),A[i])

> E <- expression(A1 * exp(A2*X) + A3) ## could also use substitute() here,

I think

## instead of explicitly assigning the coefficients

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

> eval(E)

[1] 5.718282 10.389056 57.598150

> D(E, "A2")

A1 * (exp(A2 * X) * X)

Bert Gunter

Genentech

> -----Original Message-----

*> From: r-help-bounces@stat.math.ethz.ch
**> [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Earl F. Glynn
**> Sent: Monday, August 14, 2006 3:44 PM
**> To: r-help@stat.math.ethz.ch
**> Subject: [R] Help with workaround for: Function '`[`' is not
**> in thederivatives table
**>
**> # 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
**>
**> ______________________________________________
**> R-help@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
**> and provide commented, minimal, self-contained, reproducible code.
*

>

R-help@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 and provide commented, minimal, self-contained, reproducible code. Received on Tue Aug 15 09:43:12 2006

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

Archive generated by hypermail 2.1.8, at Tue 15 Aug 2006 - 14:23:11 EST.

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