# [R] Numerical integration with R

David Winsemius dwinsemius at comcast.net
Sat Jun 14 22:18:22 CEST 2014

```On Jun 14, 2014, at 7:40 AM, Christofer Bogaso wrote:

> Hi again,
>
> I was tying to solve following 2-fold integration with package cubature.
> However spending approximately 2 hours it failed to generate any number. I
> am using latest R with win-7 machine having 4gb ram.
>
>> library(cubature)
>> f <- function(x) {
> + z1 <- x
> + z2 <- x
> +
> + Rho = 1
> +
> + L <- log(1 - pnorm(z1)) * log(1 - pnorm(Rho * z1 + sqrt(1 - Rho^2) * z2))
> * dnorm(z1) * dnorm(z2)
> +
> + return(L)
> + }; adaptIntegrate(f, lowerLimit = c(-Inf, -Inf), upperLimit = c(Inf, Inf))
> Error in adaptIntegrate(f, lowerLimit = c(-Inf, -Inf), upperLimit = c(Inf,
> :
>  'Realloc' could not re-allocate memory (1006632880 bytes)
> 1: In adaptIntegrate(f, lowerLimit = c(-Inf, -Inf), upperLimit = c(Inf,  :
>  Reached total allocation of 1535Mb: see help(memory.size)
> 2: In adaptIntegrate(f, lowerLimit = c(-Inf, -Inf), upperLimit = c(Inf,  :
>  Reached total allocation of 1535Mb: see help(memory.size)
>
>
> Would really appreciate if someone helps me to sort out this problem.

You are posting a problem with no data. You are also not explaining what you are trying to do. In particular, what was your intent when you wrote:

upperLimit = c(Inf, Inf)   # ????

When I run this with finite limits that are increasing in range  and several values for a length 2 "x"-vector

x <- c(0.1,0.1)
x <-c(.1, 0 )
x <- c(10,10)
x <- c(10, -10)

I consistently get:

#------------
> adaptIntegrate(f, lowerLimit = c(-1000, 1000), upperLimit = c(-1000, 1000))
\$integral
 0

\$error
 0

\$functionEvaluations
 17

\$returnCode
 0
#---------------

Which makes me think there is something mathematically degenerate about your "L" expression.

>
> Thanks and regards,
>
> 	[[alternative HTML version deleted]]

Arrrgh. Pray tell, exactly how many years have you been posting to R-help? I've checked... and it's really not that difficult to get gmail to send plain text.

--
David Winsemius
Alameda, CA, USA

```