R/probability.R

Defines functions prob_to_r

Documented in prob_to_r

#' Sign consistency probability and the value for r parameter 1-1 transformation
#'
#' This function transforms the probability of simulated beta_j having the same
#' sign with the underlying true effect barbeta to the corresponding heterogeneity
#' r parameter value.
#'
#' @param p A value, the required probability of sign consistency.
#'
#' @return
#' The corresponding heterogeneity parameter value.
#'
#'
prob_to_r<-function(p){

  target<-function(r){
    c<- sqrt(2/pi)
    t<-round(integrate(function(t){
      pnorm(sqrt((1-r)/r)*t) * exp(-t^2/2)
      }, 0, Inf,abs.tol = .Machine$double.eps^0.1)$value,4)
    res=c*t
    return(res-p)
  }

  root<-uniroot(target,c(0,0.1),tol = .Machine$double.eps^0.2)$root
  return(root)
}

Try the PRP package in your browser

Any scripts or data that you put into this service are public.

PRP documentation built on Dec. 13, 2021, 9:06 a.m.