[R] Different values for double integral

2009-01-24 Thread Andreas Wittmann
Dear R useRs, i have the function f1(x, y, z) which i want to integrate for x and y. On the one hand i do this by first integrating for x and then for y, on the other hand i do this the other way round and i wondering why i doesn't get the same result each way? z - c(80, 20, 40, 30) f1 -

Re: [R] Different values for double integral

2009-01-24 Thread Prof Brian Ripley
More generally, if you want to do a two-dimensional integral, you will do better to us a 2D integration algorithm, such as those in package 'adapt'. Also, these routines are somewhat sensitive to scaling, so if the correct answer is around 5e-9, you ought to rescale. You seem to be in the

Re: [R] Different values for double integral

2009-01-24 Thread Andreas Wittmann
Thank you all, for the very helpful advice. i want to estimate the parameters omega and beta of the gamma-nhpp-model with numerical integration. so one step in order to do this is to compute the normalizing constant, but as you see below i get different values ## some reliability data,

[R] Different values for double integral

2009-01-24 Thread Christos Argyropoulos
Each of the two integrals (g1, g2) seem to be divergent (or at least is considered to be so by R :) ) Try this: z - c(80, 20, 40, 30) f1 - function(x, y, z) {dgamma(cumsum(z)[-length(z)], shape=x, rate=y)} g1 - function(y, z) {integrate(function(x) {f1(x=x, y=y, z=z)}, 0.1, 0.5,