## ################################################
## A DISTRIBUTION GIVING THE LOGIT OF A BETA DISTRIBUTION ##
## ################################################
dLogitBeta <- nimbleFunction (
## Returns density of x where
## y ~ Beta(a1,a2)
## x = logit(y)
run = function(x = double(0),
shape1=double(0, default=1.0),
shape2=double(0, default=1.0),
log = integer(0, default=0)) {
returnType(double(0))
y = ilogit(x)
logProbX = log(y) + log(1 - y) + dbeta(y, shape1=shape1, shape2=shape2, log=TRUE) ## Via change of variables
if (log)
return(logProbX)
return(exp(logProbX))
}
)
rLogitBeta <- nimbleFunction (
## Generates y ~ Beta(a1,a2)
## Returns x = logit(y)
run = function(n = integer(0, default=1),
shape1 = double(0, default=1.0),
shape2 = double(0, default=1.0)) {
returnType(double(0))
if(n != 1)
nimPrint("Warning: rLogitBeta only allows n = 1; Using n = 1.\n")
y <- rbeta(1, shape1=shape1, shape2=shape2)
x <- logit(y)
return(x)
}
)
registerDistributions(list(dLogitBeta = list(
BUGSdist = "dLogitBeta(shape1, shape2)",
discrete = FALSE,
types = c("value=double(0)"), ## , "para=double(0)"
pqAvail = FALSE)))