R/gammaPriorFunctions.R

Defines functions gammaPriorParamInit gammaPriorLogProb gammaPriorGradient gammaPriorExtractParam gammaPriorExpandParam

Documented in gammaPriorExpandParam gammaPriorExtractParam gammaPriorGradient gammaPriorLogProb gammaPriorParamInit

gammaPriorExpandParam <- function(prior, params) {
  prior$a <- params[1]
  prior$b <- params[2]

  return (prior)
}


gammaPriorExtractParam <- function(prior, only.values=TRUE,
                                   untransformed.values=TRUE) {
  params <- c(prior$a, prior$b)

  if ( !only.values )
    names(params) <- c("gamma a", "gamma b")

  return (params)
}


gammaPriorGradient <- function(prior, x) {
  return ((prior$a - 1) / x - prior$b)
}


gammaPriorLogProb <- function(prior, x) {
  D <- length(x)
  return (D*prior$a*log(prior$b) - D*lgamma(prior$a) + (prior$a-1)*sum(log(x))
          - prior$b*sum(x))
}


gammaPriorParamInit <- function(prior) {
  prior$a <- 1e-6
  prior$b <- 1e-6

  prior$transforms <- list(list(index=c(1,2), type="positive"))
  prior$nParams <- 2

  return (prior)
}

Try the tigre package in your browser

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

tigre documentation built on Nov. 8, 2020, 5:32 p.m.