[R] R's integrate function

Charles C. Berry cberry at tajo.ucsd.edu
Tue Sep 30 19:10:42 CEST 2008



What verson of R?

Works for me:

> integrate(function(y,z){
+   sapply(y, function(y,z){
+ integrate(function(x,z)
+           1/x*dbeta(0.01,x/(0.005/1.005),(1-x)/(0.005/1.005))*dbeta(y,x/(0.005/1.005),(1-x)/(0.005/1.005))*(1-y)^z,0,1
+           ,423)$value
+ })
+ },0,1,423)
18.9513 with absolute error < 0.0011
> 
> sessionInfo()
R version 2.7.2 (2008-08-25)
i386-apple-darwin8.11.1

locale:
C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base
>

HTH,

Chuck

On Tue, 30 Sep 2008, Susanne Pfeifer wrote:

> Hello,
>
> I am trying to use R's integrate function to calculate the following
> integral for z=423:
>
> integrate(function(y,z){
> sapply(y, function(y,z){
> integrate(function(x,z)
> 1/x*dbeta(0.01,x/(0.005/1.005),(1-x)/(0.005/1.005))*dbeta(y,x/(0.005/1.005),(1-x)/(0.005/1.005))*(1-y)^z,0,1,423)$value
> })
> },0,1,423)$value
>
> but I receive an error message saying that the maximum number of
> subdivisions is reached. If I choose a smaller z it works fine. Does
> anyone know what the problem is?
>
> Thank you very much in advance,
> Tiffy
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

Charles C. Berry                            (858) 534-2098
                                             Dept of Family/Preventive Medicine
E mailto:cberry at tajo.ucsd.edu	            UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901



More information about the R-help mailing list