cgeneric_get {INLAtools} | R Documentation |
cgeneric_get
is an internal function used by
graph
, pred
, initial
, mu
or prior
methods for cgeneric
.
Description
The generic_get
retrieve a model property specified by
cmd
on an cgeneric
object.
The functions listed below are for each cmd
case.
Usage
cgeneric_get(
model,
cmd = c("graph", "Q", "initial", "mu", "log_prior"),
theta,
optimize = TRUE
)
## S3 method for class 'cgeneric'
initial(model)
## S3 method for class 'cgeneric'
mu(model, theta)
## S3 method for class 'cgeneric'
graph(model, optimize)
## S3 method for class 'cgeneric'
prec(model, theta, optimize)
## S3 method for class 'cgeneric'
prior(model, theta)
Arguments
model |
a |
cmd |
an string to specify which model element to get |
theta |
numeric vector with the model parameters.
If missing, the |
optimize |
logical indicating if it is to be returned only the elements and not as a sparse matrix. |
Value
depends on cmd
numeric scalar (if numeric vector is provided for theta) or vector (if numeric matrix is provided for theta).
Functions
-
initial(cgeneric)
: Retrive the initial parameter(s) of ancgeneric
model. -
mu(cgeneric)
: Evaluate the mean for ancgeneric
model. -
graph(cgeneric)
: Retrieve the graph of ancgeneric
object -
prec(cgeneric)
: Retrieve the precision of ancgeneric
object -
prior(cgeneric)
: Evaluate the prior for ancgeneric
model
See Also
check the examples in cgeneric_generic0()
Examples
old.par <- par(no.readonly = TRUE)
## Setting the prior parameters
prior.par <- c(1, 0.5) # P(sigma > 1) = 0.5
cmodel <- cgeneric(
model = "iid", n = 10,
param = prior.par)
## prior summaries: sigma and log-precision
(lamb <- -log(prior.par[2])/prior.par[1])
(smedian <- qexp(0.5, lamb))
(smean <- 1/lamb)
## mode: at the minimum of - log-prior
(lpmode <- optimize(function(x)
-prior(cmodel, theta = x),
c(-10, 30))$minimum)
## mean: integral of x*f(x)dx
(lpmean <- integrate(function(x)
exp(prior(cmodel, theta = matrix(x, 1)))*x,
-10, 30)$value)
## prior visualization: log(precision) and sigma
par(mfrow = c(1, 2))
plot(function(x)
exp(prior(cmodel, theta = matrix(x, nrow=1))),
-3, 3, n = 601, xlab = "log-precision",
ylab = "density")
abline(v = lpmode, lwd = 3, col = 2)
rug(-2*log(smedian), lwd = 3, col = 3)
rug(lpmean, lwd = 3, col = 4)
plot(function(x)
exp(prior(cmodel,
theta = matrix(
-2*log(x),
nrow = 1))+log(2)-log(x)),
1/100, 10, n = 1000,
xlab = expression(sigma),
ylab = "density")
plot(function(x) dexp(x, lamb),
1/100, 10, n = 1000,
add = TRUE, lty = 2, col = 2)
rug(smedian, lwd = 3, col = 3)
rug(smean, lwd = 3, col = 4)
par(old.par)