# Solving integrals in R

I would like to write an R function for solving the following equation:

Essentially I would like to be able to set or vary the parameters values of "m" and "s" and those parameters in "p(t)"

m <- 4 #or better yet vary calculate for all values between 1 and 10,000 for example
s <- 0.1
N <-500

integrate(f,0,Inf)
t = integrate(exp(-4*m*s*integrate(p(t')dt')))*dt)


I have already made a function for p(t) below:

p <- function(t,s,N) {
pt<-(1/(1+((2*N)-1)*exp(-s*t)))
return(pt)
}


I would greatly appreciate if someone more familiar with calculus and solving integrals in R could check over (and probably fix!!) the equation starting at "t ="? Admittedly I am not quite sure to do with the "p(t')(dt') * dt part of the equation...

• first advice - change of variables to $q=\frac{t}{1+t}$ This way your limits are $q=0$ up to $q=1$ instead of having to calculate up to infinity. second advice - find the maximum of the function you are integrating, and the Hessian. This usually helps with choosing the integration points. – probabilityislogic Mar 24 at 2:43
• also thinking...your function $p(t)$ looks like it might be analytically integrable, as we have $\frac{\partial}{\partial x}\log\left(1+e^{-x}\right)=\left(1+e^{-x}\right)^{-1}-1$ – probabilityislogic Mar 24 at 2:52
• It may also help to notice that something of the form $e^{k\log(g(x))}$ can be written $g(x)^k$ – Glen_b Mar 24 at 8:05
• Assuming $N \gt 1/2,$ $s \gt 0,$ and $m\gt 0$ (to assure convergence), the simplest form for the integral I can obtain is $$\frac{(2N)^{4m}}{4ms}{\,_2}F_1(4m,4m,1+4m,1-2N).$$ There are R packages that evaluate this hypergeometric function. – whuber Mar 24 at 14:15