View source: R/simulationpipeline.R
| glmbfamfunc | R Documentation |
This function takes as input a family object and returns a
set of functions that are used during simulation and summarization of models
using the glmb, and rglmb functions.
glmbfamfunc(family, lik_shape = 1)
## S3 method for class 'glmbfamfunc'
print(x, ...)
family |
an object of class |
lik_shape |
Known shape parameter of the Gamma likelihood; used only for the
|
x |
an object of class |
... |
additional optional arguments |
glmbfamfunc is the canonical R closure bundle for likelihood, posterior, gradient, and
deviance quantities across all supported family/link combinations.
Registration requirement. A branch must exist inside glmbfamfunc for every
family/link combination that is used in the package. If a combination is missing, the
closures f1–f4 will never be assigned and any downstream code that accesses
them will fail with "object 'f1' not found". New family/link combinations must
therefore be explicitly added here before they can produce valid DIC, log-likelihood, or
directional-tail output.
Currently implemented family/link combinations:
| Family | Link |
gaussian | identity |
poisson, quasipoisson | log |
poisson, quasipoisson | identity |
binomial, quasibinomial | logit |
binomial, quasibinomial | probit |
binomial, quasibinomial | cloglog |
binomial, quasibinomial | identity |
Gamma | log |
Gamma | identity |
Any family/link not in this table will fall through all branches silently and produce
the error above at the point of first use. For Gamma(link = "identity"), pass the
known Gamma likelihood shape lik_shape (default 1) so that f1–f4
and f7 use the correct parameterization (coefficient = Gamma rate \beta).
Relationship to C++ simulation paths. Many simulation procedures in the package have
been fully or partially migrated to *.cpp routines, which receive their own
objective functions directly. For those paths glmbfamfunc may not be called at all
during sampling. However, the R-side post-processing functions
(logLik.glmb, summary.rglmb, directional_tail)
always use famfunc\$f1, famfunc\$f4, and famfunc\$f7 respectively, so a
registered branch is still required for those outputs even when the sampler itself has moved
to C++.
A list (class "glmbfamfunc") whose first four components are always
present for every supported family and link. The names f1–f4
are stable: they mean the same roles across families (only the internal formulas change).
f1Negative log-likelihood as a function of coefficients b
(arguments typically b, y, x, optional alpha, wt).
f2Negative log-posterior (likelihood plus Normal prior quadratic form in
b with precision P and mean mu).
f3Gradient of f2 with respect to b (same argument pattern as f2).
f4Deviance-related quantity (twice negative log-likelihood contrast vs.\
saturated model, with a dispersion argument for quasi-families); used in DIC-style summaries.
f7Family-specific matrix: weighted sum of outer products of predictor rows,
i.e.\ a curvature / expected negative Hessian of the log-likelihood w.r.t.\ b
at the supplied b (used e.g.\ by directional_tail for glmb fits).
Slots f5 and f6 are not returned: they were reserved for alternate or
C++-aligned likelihood/posterior routines and remain commented out in the implementation
(only f1, f2, f3, f4, and f7 are assigned in the returned list).
famfunc <- glmbfamfunc(binomial(logit))
print(famfunc)
## f1--f4 and f7 are always present for supported families; f5 and f6 are not returned.
f1 <- famfunc$f1
f2 <- famfunc$f2
f3 <- famfunc$f3
f4 <- famfunc$f4
f7 <- famfunc$f7
stopifnot(is.function(f1), is.function(f2), is.function(f3),
is.function(f4), is.function(f7))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.