[R] Error in integrate

From: Murray Jorgensen <maj_at_stats.waikato.ac.nz>
Date: Fri 07 Oct 2005 - 12:11:23 EST


I'm using R 2.0.1 under Windows XP. I get the following message when I run the code listed below. I don't seem to have any problems using the function "slice" outside "integrate".

Error in integrate(slice, 0, Inf, , , , , , , a, b) * delta :

         non-numeric argument to binary operator

[ By the way, I'm trying to evaluate a two-dimensional integral by slicing it up into one-dimensional bits which I will loop over to evaluate.]

Here's the code:

mu <- 0.3
sig2 <- 0.01
alpha <- 20
beta <- 15.75
rho <- 0.1
k <- 1/(rho^2.5*gamma(rho)^2*sqrt(2*pi*sig2))

slice <- function(w,a,b)
{

  g <- w^(1/rho)
  g1 <- w1^(1/rho)
  h <- g1^a*g^b
  E <- -(y-rho*mu -g1/alpha + g/beta)^2/(2*sig2*rho)   k*h*exp(E- g1 - g)
}

hi <- 10
delta <- 0.05
grid <- seq(delta/2,hi,delta)

y <- -0.3
a <- 0
b <- 0
m <- length(grid)
A <- rep(0,m)
j <- 0

for (w1 in grid)
{

  j <- j+1
  A[j] <- integrate(slice,0,Inf,,,,,,,a,b)*delta   cat(A[j],"\n")
}

-- 
Dr Murray Jorgensen      http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: maj@waikato.ac.nz                                Fax 7 838 4155
Phone  +64 7 838 4773 wk    Home +64 7 825 0441    Mobile 021 1395 862

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Fri Oct 07 12:17:36 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:40:38 EST