[R] Surprising result from integrate

Ravi Varadhan rvaradha at jhsph.edu
Fri Aug 23 21:03:03 CEST 2002


The problem is with the relative tolerance (rel.tol).  The default is the
4th root of the machine epsilon, which works out to be roughly about 1.e-04.
If you lower this to, say,1e-07, then you will get the right results.

Ravi.

----- Original Message -----
From: "Daniel Hoppe" <hoppe at sitewaerts.de>
To: <r-help at stat.math.ethz.ch>
Sent: Friday, August 23, 2002 1:09 PM
Subject: [R] Surprising result from integrate


> Hi all,
>
> sorry for this extensive question, but I think that I'm missing something
> fundamental.
>
> I stepped into a surprising result with the integrate function and I would
> be glad if someone could put some light onto this. I try to integrate over
> an s-shaped growth-function. The results from this calculation seem to be
> correct for small values of t. Just for fun I tried some large values and
> suddenly one part of the formula got close to zero (i2, it is not expected
> to do this). I tried different numbers and found that for t=upper=59954
> everything is fine and for t=upper=59955 integrate wouldn't return the
> correct result anymore (see below). I'm now wondering if I'm
misinterpreting
> how integrate is supposed to be used. Details can be found below.
>
> Thanks for your thoughts and best regards,
>
> Daniel
>
>
> This is the output of the function calls:
>
> > bergernasr.clv.continuous(10)
> 112.1139 with absolute error < 6.2e-13
> 111.1077 with absolute error < 6.2e-13
> [1] 243.2216
>
> > bergernasr.clv.continuous(59954)
> 112.1139 with absolute error < 6.2e-13
> 150.2340 with absolute error < 3e-07
> [1] 282.3478
>
> > bergernasr.clv.continuous(59955)
> 112.1139 with absolute error < 6.2e-13
> 6.137708e-05 with absolute error < 0.00012
> [1] 132.1139
>
> These are the functions required to see this effect.
>
> bergernasr.clv.continuous.f1 <- function(t, h, v, ret, d)
> {
>
>     (h*t^2 + v) * (ret / ( 1 + d ))^t
> }
>
> bergernasr.clv.continuous.f2 <- function (t, g,h, v, ret, N, d)
> {
>     (h*g^2 + v + N*(1-exp(-t+g))) * (ret / ( 1 + d ))^t
> }
>
> bergernasr.clv.continuous <- function(t)
> {
>     g <- 5         # Wendepunkt
>     v <- 20        # Sockelbetrag
>     h <- 4         # Umsatzwachstum
>     N <- 80        # Wachstum ab Wendepunkt
>     r <- .9        # Retention rate
>     d <- .2        # Discount rate
>
>      i1 <- integrate(bergernasr.clv.continuous.f1, h=h,v=v,ret=r,d=d,
> lower=0, upper=5)
>      i2 <- integrate(bergernasr.clv.continuous.f2, g=g, h=h,v=v,ret=r,N=N,
> d=d, lower=g, upper=t)
>      print(i1)
>      print(i2)
>      return (
>         v
>         + i1[[1]]
>         + i2[[1]]
>      )
> }
>
> For better readability the function in Mathtype / Tex format:
>
> % MathType!MTEF!2!1!+-
> % feaafaart1ev1aaatCvAUfeBSjuyZL2yd9gzLbvyNv2CaerbuLwBLn
> % hiov2DGi1BTfMBaeXatLxBI9gBaerbd9wDYLwzYbItLDharqqtubsr
> % 4rNCHbGeaGqiVCI8FfYJH8YrFfeuY-Hhbbf9v8qqaqFr0xc9pk0xbb
> % a9q8WqFfeaY-biLkVcLq-JHqpepeea0-as0Fb9pgeaYRXxe9vr0-vr
> % 0-vqpWqaaeaabiGaciaacaqabeaadaqaaqaaaOqaaiaadoeacaWGmb
> % GaamOvaiabg2da9iaadAhacqGHRaWkdaWdXbqaamaabmaabaGaamiA
> % aiaadshadaahaaWcbeqaaiaaikdaaaGccqGHRaWkcaWG2baacaGLOa
> % GaayzkaaGaeyyXIC9aaeWaaeaadaWcaaqaaiaadkhaaeaacaaIXaGa
> % ey4kaSIaamizaaaaaiaawIcacaGLPaaadaahaaWcbeqaaiaadshaaa
> % GccaWGKbWaaeWaaeaacaWG0baacaGLOaGaayzkaaGaey4kaSYaa8qC
> % aeaadaqadaqaaiaadIgacaWGNbWaaWbaaSqabeaacaaIYaaaaOGaey
> % 4kaSIaamODaiabgUcaRiaad6eacqGHflY1caGGOaGaaGymaiabgkHi
> % TiaadwgadaahaaWcbeqaaiabgkHiTiaadshacqGHRaWkcaWGNbaaaO
> % GaaiykaaGaayjkaiaawMcaaaWcbaGaam4zaaqaaiaad6gaa0Gaey4k
> % IipakiabgwSixpaabmaabaWaaSaaaeaacaWGYbaabaGaaGymaiabgU
> % caRiaadsgaaaaacaGLOaGaayzkaaWaaWbaaSqabeaacaWG0baaaOGa
> % amizamaabmaabaGaamiDaaGaayjkaiaawMcaaaWcbaGaaGimaaqaai
> % aadEgaa0Gaey4kIipaaaa!74B6!
> \[
> CLV = v + \int\limits_0^g {\left( {ht^2  + v} \right) \cdot \left(
> {\frac{r}{{1 + d}}} \right)^t d\left( t \right) + \int\limits_g^n
> {\left( {hg^2  + v + N \cdot (1 - e^{ - t + g} )} \right)}  \cdot
> \left( {\frac{r}{{1 + d}}} \right)^t d\left( t \right)}
> \]
>
> <<<<<<<<<<<<<<<<<<<<<<<<<<<
> sitewaerts GmbH
> Hebelstraße 15
> D-76133 Karlsruhe
>
> Tel: +49 (721) 920 918 0
> Fax: +49 (721) 920 918 29
> http://www.sitewaerts.de
> >>>>>>>>>>>>>>>>>>>>>>>>>>>
>
>
> Der Inhalt dieser E-Mail ist vertraulich und ausschließlich für den
> bezeichneten Adressaten bestimmt. Wenn Sie nicht der vorgesehene Adressat
> dieser E-Mail oder dessen Vertreter sein sollten, so beachten Sie bitte,
daß
> jede Form der Kenntnisnahme, Veröffentlichung, Vervielfältigung oder
> Weitergabe des Inhalts dieser E-Mail unzulässig ist. Wir bitten Sie, sich
in
> diesem Fall mit dem Absender der E-Mail in Verbindung zu setzen. Aussagen
> gegenüber dem Adressaten unterliegen den Regelungen des zugrundeliegenden
> Angebotes bzw. Auftrags, insbesondere den Allgemeinen Auftragsbedingungen
> und der individuellen Haftungsvereinbarung. Der Inhalt der E-Mail ist nur
> rechtsverbindlich, wenn er unsererseits durch einen Brief entsprechend
> bestätigt wird.
>
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-.-
> r-help 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-help-request at stat.math.ethz.ch
>
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list