On 30/06/11 06:16, Gabor Grothendieck wrote:
On Tue, Jun 28, 2011 at 10:03 PM, Lisa<lisa...@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.
______________________________________________
R-help@r-project.org 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.