From p.dalgaard@biostat.ku.dk  Sun Oct  7 11:42:34 2001
From: p.dalgaard@biostat.ku.dk (Peter Dalgaard BSA)
Date: 07 Oct 2001 12:42:34 +0200
Subject: [Rd] Bug in Deriv? (PR#1119)
In-Reply-To: <200110071024.MAA09258@pubhealth.ku.dk>
References: <200110071024.MAA09258@pubhealth.ku.dk>
Message-ID: <x2elofivdx.fsf@blueberry.kubism.ku.dk>

dieter.menne@menne-biomed.de writes:

> deriv seems to have problems with a minus-sign before a bracket.
> Below are four examples of the same function, the top one
> is wrong, all others are correct (hopefully).
> 
> 
> Rest of expression not shown, it is the same for all versions.
> 
>          _
> platform i386-pc-mingw32
> arch     x86
> os       Win32
> system   x86, Win32
> status
> major    1
> minor    3.0
> year     2001
> month    06
> day      22
> language R
> 
> -----------------------------------------------------------------
> > deriv(~offv+Asym/(1+exp(-(x-xmid)/scal)),"x")
> expression({
>     .expr4 <- exp(-x - xmid/scal)  #### Wrong !!!!


Actually, only the deparsing of the expression is wrong, cf:

> deriv(~offv+Asym/(1+exp(-(x-xmid)/scal)),"x")[[1]][[2]][[3]]
exp(-x - xmid/scal)
> deriv(~offv+Asym/(1+exp(-(x-xmid)/scal)),"x")[[1]][[2]][[3]][[2]]
-x - xmid/scal
> deriv(~offv+Asym/(1+exp(-(x-xmid)/scal)),"x")[[1]][[2]][[3]][[2]][[2]]
-x - xmid
> deriv(~offv+Asym/(1+exp(-(x-xmid)/scal)),"x")[[1]][[2]][[3]][[2]][[2]][[2]]
x - xmid

I.e. the expression is really exp((-(x - xmid))/scal). It is a
well-known problem with the deparser that it doesn't parenthesize
properly based on operator hierarchy. Similarly, the parser should
probably drop parentheses in most cases. 

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] Bug in Deriv? (PR#1119)
Peter Dalgaard BSA