# [R] Solve an equation including integral

Fri Jan 8 17:47:00 CET 2016

```There was a mistake in the previously sent function.  I had hard coded the values of parameters `nu' and `exi'.

Use this one:

myroot <- function(t, nu, exi, alpha){
fun <- function(t, exi, nu) (nu+t^2)^(-(nu+1)/2)*exp(((nu+1)*exi*t)/((nu+t^2)^0.5))
res <- alpha - integrate(fun, -Inf, t, nu=nu, exi=exi)\$value
return(res)
}

uniroot(myroot, c(-2, 2), nu=2, exi=0.5, alpha=.05)

Ravi

Sent: Friday, January 08, 2016 11:29 AM
To: r-help at r-project.org; 'sstoline at gmail.com' <sstoline at gmail.com>
Subject: Re: Solve an equation including integral

I think this is what you want:

myroot <- function(t, nu, exi, alpha){
fun <- function(t, exi, nu) (nu+t^2)^(-(nu+1)/2)*exp(((nu+1)*exi*t)/((nu+t^2)^0.5))
res <- alpha - integrate(fun, -Inf, t, nu=2, exi=0.5)\$value
return(res)
}

uniroot(myroot, c(-2, 2), nu=2, exi=0.5, alpha=.05)

Ravi

Ravi Varadhan, Ph.D. (Biostatistics), Ph.D. (Environmental Engg)
Associate Professor,  Department of Oncology
Division of Biostatistics & Bionformatics
Sidney Kimmel Comprehensive Cancer Center
Johns Hopkins University