[R] Derivative of a function

Rolf Turner rolf.turner at xtra.co.nz
Wed Jun 29 22:18:18 CEST 2011


On 30/06/11 06:16, Gabor Grothendieck wrote:
> 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:

I think the original post made it quite clear that the derivative of b
with respect to y was indeed what was wanted; i.e. the OP needs to
do implicit differentiation which R does not do automatically.

     cheers,

         Rolf Turner
>> 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.
>



More information about the R-help mailing list