[R] Derivative of a function

Gabor Grothendieck ggrothendieck at gmail.com
Wed Jun 29 20:16:02 CEST 2011


On Tue, Jun 28, 2011 at 10:03 PM, Lisa <lisajca at gmail.com> wrote:
> Dear all,
>
> I just want to get the derivative of a function that looks like:
>
> y = exp(x1*b) / (exp(x1*b) + exp(x2*b))
>
> where y is a scalar, x1, x2, and b are vectors. I am going to take the
> derivative of b with respect to y, but I cannot derive an expression in
> which b is function of y. I know there is another way to get the similar
> result, i.e., first take the derivative of y with respect to each element of
> b, and then take its reciprocal. But it is not what I want. Could someone
> please tell me how to solve this problem? Thank you in advance.

Assuming you meant the derivative of y with respect to b:

> D(expression(exp(x1*b) / (exp(x1*b) + exp(x2*b))), "b")
exp(x1 * b) * x1/(exp(x1 * b) + exp(x2 * b)) - exp(x1 * b) *
    (exp(x1 * b) * x1 + exp(x2 * b) * x2)/(exp(x1 * b) + exp(x2 *
    b))^2

See ?D and also note deriv on the same help page for another alternative.

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list