bru_obs {inlabru} | R Documentation |
Observation model construction for usage with bru()
Description
Observation model construction for usage with bru()
.
Note: Prior to version 2.12.0
, this function was called like()
, and that
alias will remain for a while until examples etc have been updated and users
made aware of the change. The name change is to avoid issues with namespace
clashes, e.g. with data.table::like()
, and also to signal that the function
defines observation models, not just likelihood functions.
Usage
bru_obs(
formula = . ~ .,
family = "gaussian",
data = NULL,
response_data = NULL,
data_extra = NULL,
E = NULL,
Ntrials = NULL,
weights = NULL,
scale = NULL,
domain = NULL,
samplers = NULL,
ips = NULL,
used = NULL,
allow_combine = NULL,
aggregate = NULL,
aggregate_input = NULL,
control.family = NULL,
tag = NULL,
options = list(),
.envir = parent.frame(),
include = deprecated(),
exclude = deprecated(),
include_latent = deprecated()
)
like(
formula = . ~ .,
family = "gaussian",
data = NULL,
response_data = NULL,
E = NULL,
Ntrials = NULL,
weights = NULL,
scale = NULL,
domain = NULL,
samplers = NULL,
ips = NULL,
used = NULL,
allow_combine = NULL,
control.family = NULL,
tag = NULL,
options = list(),
.envir = parent.frame(),
mesh = deprecated(),
include = deprecated(),
exclude = deprecated(),
include_latent = deprecated()
)
bru_obs_list(...)
## S3 method for class 'list'
bru_obs_list(object, ..., .envir = NULL)
## S3 method for class 'bru_obs_list'
bru_obs_list(..., .envir = NULL)
## S3 method for class 'bru_obs'
c(..., .envir = NULL)
## S3 method for class 'bru_obs_list'
c(..., .envir = NULL)
## S3 method for class 'bru_obs_list'
x[i]
like_list(...)
bru_like_list(...)
Arguments
formula |
a |
family |
A string identifying a valid |
data |
Predictor expression-specific data, as a |
response_data |
Observation/response-specific data for models that need
different size/format for inputs and response variables, as a |
data_extra |
object convertible with |
E |
Exposure/effort parameter for family = 'poisson' passed on to
|
Ntrials |
A vector containing the number of trials for the 'binomial'
likelihood. Default taken from |
weights |
Fixed (optional) weights parameters of the likelihood, so the
log-likelihood For |
scale |
Fixed (optional) scale parameters of the precision for several models, such as Gaussian and student-t response models. |
domain , samplers , ips |
Arguments used for
|
used |
Either |
allow_combine |
logical; If |
aggregate |
character ("none", "sum", "average", "logsumexp", or
"logaverageexp", as defined by |
aggregate_input |
list(block = .data.[[".block"]], weights = .data.[["weight"]], n_block = bru_response_size(.response_data.)) |
control.family |
A optional |
tag |
character; Name that can be used to identify the relevant parts
of INLA predictor vector output, via |
options |
A bru_options options object or a list of options passed
on to |
.envir |
The evaluation environment to use for special arguments ( |
include , exclude , include_latent |
|
mesh |
|
... |
For |
object |
A list of |
x |
|
i |
indices specifying elements to extract |
Value
A likelihood configuration which can be used to parameterise bru()
.
Methods (by generic)
-
c(bru_obs)
: Combine severalbru_obs
objects into abru_obs_list
object
Functions
-
like()
:Legacy
like()
method forinlabru
prior to version2.12.0
. Usebru_obs()
instead. -
bru_obs_list()
: Combinebru_obs
observation model object into abru_obs_list
object -
bru_obs_list(list)
: Combine one or more lists ofbru_obs
observation model objects into abru_obs_list
object -
bru_obs_list(bru_obs_list)
: Combine a list ofbru_obs
observation model objects into abru_obs_list
object -
c(bru_obs_list)
: Combine severalbru_obs_list
objects into abru_obs_list
object -
like_list()
:Backwards compatibility for versions
<= 2.12.0
. For later versions, useas_bru_obs_list()
,bru_obs_list()
, orc()
. -
bru_like_list()
:Backwards compatibility for versions
<= 2.12.0.9017
. For later versions, useas_bru_obs_list()
,bru_obs_list()
orc()
.
Author(s)
Fabian E. Bachl bachlfab@gmail.com
Finn Lindgren finn.lindgren@gmail.com
See Also
bru_response_size()
, bru_used()
, bru_comp()
,
bru_comp_eval()
Examples
if (bru_safe_inla() &&
require(ggplot2, quietly = TRUE)) {
# The 'bru_obs()' (previously 'like()') function's main purpose is to set up
# observation models, both for single- and multi-likelihood models.
# The following example generates some random covariates which are observed
# through two different random effect models with different likelihoods
# Generate the data
set.seed(123)
n1 <- 200
n2 <- 10
x1 <- runif(n1)
x2 <- runif(n2)
z2 <- runif(n2)
y1 <- rnorm(n1, mean = 2 * x1 + 3)
y2 <- rpois(n2, lambda = exp(2 * x2 + z2 + 3))
df1 <- data.frame(y = y1, x = x1)
df2 <- data.frame(y = y2, x = x2, z = z2)
# Single likelihood models and inference using bru are done via
cmp1 <- y ~ -1 + Intercept(1) + x
fit1 <- bru(cmp1, family = "gaussian", data = df1)
summary(fit1)
cmp2 <- y ~ -1 + Intercept(1) + x + z
fit2 <- bru(cmp2, family = "poisson", data = df2)
summary(fit2)
# A joint model has two likelihoods, which are set up using the bru_obs
# function
lik1 <- bru_obs(
"gaussian",
formula = y ~ x + Intercept,
data = df1,
tag = "norm"
)
lik2 <- bru_obs(
"poisson",
formula = y ~ x + z + Intercept,
data = df2,
tag = "pois"
)
# The union of effects of both models gives the components needed to run bru
jcmp <- ~ x + z + Intercept(1)
jfit <- bru(jcmp, lik1, lik2)
bru_index(jfit, "norm")
bru_index(jfit, "pois")
# Compare the estimates
p1 <- ggplot() +
gg(fit1$summary.fixed, bar = TRUE) +
ylim(0, 4) +
ggtitle("Model 1")
p2 <- ggplot() +
gg(fit2$summary.fixed, bar = TRUE) +
ylim(0, 4) +
ggtitle("Model 2")
pj <- ggplot() +
gg(jfit$summary.fixed, bar = TRUE) +
ylim(0, 4) +
ggtitle("Joint model")
multiplot(p1, p2, pj)
}