I added "plogis" to the derivative table in the development version of R; the patch against yesterday's R-devel src/deriv/main.c is available at http://www.zoology.ufl.edu/bolker/deriv_patch.txt . I pretty much followed the framework of the other symbols; here was my incantation - } else if (CAR(expr) == PlogisSymbol) { - ans = simplify(TimesSymbol, - PP_S(TimesSymbol, - PP_S2(ExpSymbol, - PP_S2(MinusSymbol,CADR(expr))), - PP_S(PowerSymbol, - PP_S(PlusSymbol, - Constant(1.), - PP_S2(ExpSymbol, - PP_S2(MinusSymbol,CADR(expr)))), - Constant(-2.))), - PP(D(CADR(expr),var))); - UNPROTECT(8); It seems to work:> D(quote(plogis(a)),"a")exp(-a) * (1 + exp(-a))^-2> D(quote(plogis(a+b*x)),"x")exp(-(a + b * x)) * (1 + exp(-(a + b * x)))^-2 * b Any thoughts? I'm sure there's a cleverer way to do this ... Ben Bolker PS I get a minor build error at the end of the compilation (on Ubuntu 8.10): make[2]: *** No rule to make target `VR.ts', needed by `stamp-recommended'. Stop. make[2]: Leaving directory `/usr/local/src/R/R-devel/src/library/Recommended' make[1]: *** [recommended-packages] Error 2 make[1]: Leaving directory `/usr/local/src/R/R-devel/src/library/Recommended' make: *** [stamp-recommended] Error 2 ... don't know if that is important or not. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 252 bytes Desc: OpenPGP digital signature URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20080814/2712b33c/attachment.bin>
While you are at it could you add { to the table so that this works:> # this is ok > f <- function(x) x*x > D(body(f), "x")x + x> # but not g which is same as f > # except it has { ... } surrounding its body > g <- function(x) { x*x } > D(body(g), "x")Error in D(body(g), "x") : Function '`{`' is not in the derivatives table 2008/8/14 Ben Bolker <bolker at zoology.ufl.edu>:> > I added "plogis" to the derivative table in the > development version of R; the patch against yesterday's > R-devel src/deriv/main.c is available at > http://www.zoology.ufl.edu/bolker/deriv_patch.txt . > > I pretty much followed the framework of the other symbols; > here was my incantation > > - } else if (CAR(expr) == PlogisSymbol) { > - ans = simplify(TimesSymbol, > - PP_S(TimesSymbol, > - PP_S2(ExpSymbol, > - PP_S2(MinusSymbol,CADR(expr))), > - PP_S(PowerSymbol, > - PP_S(PlusSymbol, > - Constant(1.), > - PP_S2(ExpSymbol, > - PP_S2(MinusSymbol,CADR(expr)))), > - Constant(-2.))), > - PP(D(CADR(expr),var))); > - UNPROTECT(8); > > It seems to work: > >> D(quote(plogis(a)),"a") > exp(-a) * (1 + exp(-a))^-2 >> D(quote(plogis(a+b*x)),"x") > exp(-(a + b * x)) * (1 + exp(-(a + b * x)))^-2 * b > > Any thoughts? I'm sure there's a cleverer way to do this ... > > Ben Bolker > > PS I get a minor build error at the end of the compilation > (on Ubuntu 8.10): > > make[2]: *** No rule to make target `VR.ts', needed by > `stamp-recommended'. Stop. > make[2]: Leaving directory > `/usr/local/src/R/R-devel/src/library/Recommended' > make[1]: *** [recommended-packages] Error 2 > make[1]: Leaving directory > `/usr/local/src/R/R-devel/src/library/Recommended' > make: *** [stamp-recommended] Error 2 > > ... don't know if that is important or not. > > > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > >
The derivative of plogis is surely dlogis. (And yes, there is a good reason why we have such a function: take a look at its C code.) That means we would need an entry for dlogis too, I guess. I am not convinced that there is a real need for these (and where does this stop?) What would be much more useful is to make this user-extensible (as Bill Venables pointed out a decade ago). [pd]norm were added in 2002 to support MASS, the ability to do all of MASS in R being a goal at the time. On Thu, 14 Aug 2008, Ben Bolker wrote:> > I added "plogis" to the derivative table in the > development version of R; the patch against yesterday's > R-devel src/deriv/main.c is available at > http://www.zoology.ufl.edu/bolker/deriv_patch.txt . > > I pretty much followed the framework of the other symbols; > here was my incantation > > - } else if (CAR(expr) == PlogisSymbol) { > - ans = simplify(TimesSymbol, > - PP_S(TimesSymbol, > - PP_S2(ExpSymbol, > - PP_S2(MinusSymbol,CADR(expr))), > - PP_S(PowerSymbol, > - PP_S(PlusSymbol, > - Constant(1.), > - PP_S2(ExpSymbol, > - PP_S2(MinusSymbol,CADR(expr)))), > - Constant(-2.))), > - PP(D(CADR(expr),var))); > - UNPROTECT(8); > > It seems to work: > >> D(quote(plogis(a)),"a") > exp(-a) * (1 + exp(-a))^-2 >> D(quote(plogis(a+b*x)),"x") > exp(-(a + b * x)) * (1 + exp(-(a + b * x)))^-2 * b > > Any thoughts? I'm sure there's a cleverer way to do this ... > > Ben Bolker > > PS I get a minor build error at the end of the compilation > (on Ubuntu 8.10): > > make[2]: *** No rule to make target `VR.ts', needed by > `stamp-recommended'. Stop. > make[2]: Leaving directory > `/usr/local/src/R/R-devel/src/library/Recommended' > make[1]: *** [recommended-packages] Error 2 > make[1]: Leaving directory > `/usr/local/src/R/R-devel/src/library/Recommended' > make: *** [stamp-recommended] Error 2 > > ... don't know if that is important or not. >A local-to-you problem.> >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Gabor Grothendieck wrote:> If they are on Windows installing Yacas is just a matter > of issuing a single R command with no arguments. > yacas grabs it from the net and installs it automaticaly > without any further user interaction. It also reminds you > to give the command and tells you exactly what it is just > after you issue: > > library(Ryacas) > > (You can also set up it up locally to include yacas right > in the R distribution and originally we did it that way but > had to remove it for CRAN.) > > Another thing you could do would be to copy the derivative > code from R and put it in your own package and then > you can make any enhancements you like without > having to go through the R core. > > Regards. >Hmmm. Interesting but ... now I'm wondering (continuing masochism) how hard it would actually be to implement the derivative rules in native R, which might (?) make it much easier to include the derivative rules as an extendable table. I may play with this some -- it's certainly re-inventing the wheel to reimplement all of the stuff in deriv.c in native R, but it might be worth it in the long run ... Ben -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 252 bytes Desc: OpenPGP digital signature URL: <https://stat.ethz.ch/pipermail/r-devel/attachments/20080815/806f629a/attachment.bin>