[R] multiply of two expressions
Ben Bolker
bbolker at gmail.com
Tue May 6 19:31:33 CEST 2014
Niloofar.Javanrouh <javanrouh_n <at> yahoo.com> writes:
>
>
> hello,
> i want to differentiate of L with respect to b
> when:
>
> L= k*ln (k/(k+mu)) + sum(y) * ln (1-(k/mu+k))
> #(negative binomial ln likelihood)
> and
> ln(mu/(mu+k)) = a+bx #link function
>
> how can i do it in R?
> thank you.
>
R has a couple of functions for differentiation, D() and deriv(),
but this is probably a case where it would actually be simpler to
do it yourself by hand. If you insist on doing it in R, you can
either use the chain rule (i.e. compute d(mu)/d(b)*d(L)/d(mu)) or
you can make a big ugly expression where you substitute the expression
for mu(b) into the expression for L. In either case you'll have to
solve your link expression for mu.
Wolfram Alpha might help too.
good luck
Ben Bolker
More information about the R-help
mailing list