Re: [R] integrate and quadratic forms

2007-01-19 Thread Thomas Lumley
As the documentation for integrate() says, the function must be vectorized f: an R function taking a numeric first argument and returning a numeric vector of the same length. so you can't use sum(). You need matrix operations or an explicit loop to add up the terms. -th

Re: [R] integrate and quadratic forms

2007-01-19 Thread rdporto1
Thanks Jim. But a narrower problem still remains. Please, look at this new code: lambda=c(.6,.3) integral = function(u) { theta = (atan(.6*u) + atan(.3*u))/2 - .1*u/2 rho = (1+.6^2*u^2)^(1/4) * (1+.3^2*u^2)^(1/4) integrand = sin(theta)/(u*rho) } > integrate(integral,0,Inf)$value [1] 1.22268

Re: [R] integrate and quadratic forms

2007-01-18 Thread jim holtman
The do give the same answer, unfortunately the examples you sent were not the same. Integral2 was missing a 'sin'. So I would assume there might be something else wrong with your functions. You might want to try breaking it down into smaller steps so you can see what you are doing. It definite

[R] integrate and quadratic forms

2007-01-18 Thread rdporto1
Hi all. I'm trying to numerically invert the characteristic function of a quadratic form following Imhof's (1961, Biometrika 48) procedure. The parameters are: lambda=c(.6,.3,.1) h=c(2,2,2) sigma=c(0,0,0) q=3 I've implemented Imhof's procedure two ways that, for me, should give the same answer: