[R] Need Help To Solve An Equation In R

Kenneth Knoblauch ken.knoblauch at inserm.fr
Sun May 28 09:38:09 CEST 2017


This looks an awful lot like you are trying to solve for d' in an 
m-alternative forced choice experiment for an unbiased observer.  Try 
the function dprime.mAFC from the psyphy package.  For comparison with 
your example, it's code is:

  psyphy:::dprime.mAFC
function (Pc, m)
{
     m <- as.integer(m)
     if (m < 2)
         stop("m must be an integer greater than 1")
     if (!is.integer(m))
         stop("m must be an integer")
     if (Pc <= 0 || Pc >= 1)
         stop("Pc must be in (0,1)")
     est.dp <- function(dp) {
         pr <- function(x) dnorm(x - dp) * pnorm(x)^(m - 1)
         Pc - integrate(pr, lower = -Inf, upper = Inf)$value
     }
     dp.res <- uniroot(est.dp, interval = c(-10, 10))
     dp.res$root
}
<environment: namespace:psyphy>

Hope that helps,

best,

Ken


On Sat, May 27, 2017 at 9:16 AM, Neetu Shah <nshah.0452 at gmail.com> 
wrote:
> Dear Sir/Ma'am,
> 
> I am trying to make a function to solve an equation that is given 
> below:
> findH <- function(p_star, k){
> fun <- function(y){
> (pnorm(y+h))^(k-1)*dnorm(y)
> }
> lhs <- integrate(fun, -Inf, Inf)$value
> return(uniroot(lhs, lower = -10, upper = 10,
> tol = p_star)$root)
> }
> In lhs, I integrated a function with respect to y and there would be an
> unknown h that I need to find.
> I need to equate this lhs to p_star value in order to find h. Which
> function should I use to solve this equation?
> Please guide me regarding this.
> Thank you.
> 
> --
> With Regards,
> Neetu Shah,
> B.Tech.(CS),
> 3rd Year,
> IIIT Vadodara.
-- 
Kenneth Knoblauch
Inserm U1208
Stem-cell and Brain Research Institute
18 avenue du Doyen Lépine
69500 Bron
France
tel: +33 (0)4 72 91 34 77
fax: +33 (0)4 72 91 34 61
portable: +33 (0)6 84 10 64 10
http://www.sbri.fr/members/kenneth-knoblauch.html



More information about the R-help mailing list