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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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.
The problem is that f2 is nearly zero for most of its range, eg for
t=100, it is 6.4e-11. The integrate() function only evaluates the function
at finitely many places and at some point it gets zero at all these points
and doesn't notice the tiny region where f2 is non-zero.
If you really want to integrate out to infinity then say so:
> bergernasr.clv.continuous(Inf)
112.1139 with absolute error < 1.2e-12
150.2340 with absolute error < 0.0010
[1] 282.3478
and it will work.
You can see a simpler version of the same thing with dnorm:
integrate(dnorm,0,2)
0.4772499 with absolute error < 5.3e-15
integrate(dnorm,0,20)
0.5 with absolute error < 3.7e-05
integrate(dnorm,0,200)
0.5 with absolute error < 1.6e-07
integrate(dnorm,0,2000)
0.5 with absolute error < 4.4e-06
integrate(dnorm,0,20000)
0 with absolute error < 0
-thomas
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._