[R] R's integrate function

Victor Hernando Cervantes Botero vhcervantesb at unal.edu.co
Tue Sep 30 19:27:41 CEST 2008


I got the same error.

> sessionInfo()
R version 2.6.0 (2007-10-03)
i386-pc-mingw32

locale:
LC_COLLATE=Spanish_Colombia.1252;LC_CTYPE=Spanish_Colombia.1252;LC_MONETARY=Spanish_Colombia.1252;LC_NUMERIC=C;LC_TIME=Spanish_Colombia.1252

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



however, you can modify the maximum number of subdivisions for
integrate (check ?integrate)


> 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, subdivisions = 150)
18.97078 with absolute error < 0.0013

hth,

Víctor H

2008/9/30 Charles C. Berry <cberry at tajo.ucsd.edu>:
>
>
> 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
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list