| like {inlabru} | R Documentation | 
Observation model construction for usage with bru()
Description
Observation model construction for usage with bru()
Usage
like(
  formula = . ~ .,
  family = "gaussian",
  data = NULL,
  response_data = NULL,
  mesh = deprecated(),
  E = NULL,
  Ntrials = NULL,
  weights = NULL,
  scale = NULL,
  samplers = NULL,
  ips = NULL,
  domain = NULL,
  include = NULL,
  exclude = NULL,
  include_latent = NULL,
  used = NULL,
  allow_latent = deprecated(),
  allow_combine = NULL,
  control.family = NULL,
  options = list(),
  .envir = parent.frame()
)
like_list(...)
## S3 method for class 'list'
like_list(object, envir = NULL, ...)
## S3 method for class 'bru_like'
like_list(..., envir = NULL)
## S3 method for class 'bru_like'
c(..., envir = NULL)
## S3 method for class 'bru_like_list'
c(..., envir = NULL)
## S3 method for class 'bru_like_list'
x[i]
Arguments
formula | 
 a   | 
family | 
 A string identifying a valid   | 
data | 
 Likelihood-specific data, as a   | 
response_data | 
 Likelihood-specific data for models that need different
size/format for inputs and response variables, as a   | 
mesh | 
 Deprecated.  | 
E | 
 Exposure 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  | 
scale | 
 Fixed (optional) scale parameters of the precision for several models, such as Gaussian and student-t response models.  | 
samplers | 
 Integration domain for 'cp' family.  | 
ips | 
 Integration points for 'cp' family. Overrides   | 
domain | 
 Named list of domain definitions.  | 
include | 
 Character vector of component labels that are used as effects
by the
predictor expression; Default: the result of   | 
exclude | 
 Character vector of component labels that are not used by the
predictor expression. The exclusion list is applied to the list
as determined by the   | 
include_latent | 
 character vector.
Specifies which the latent state variables are
directly available to the predictor expression, with a   | 
used | 
 Either   | 
allow_latent | 
|
allow_combine | 
 logical; If   | 
control.family | 
 A optional   | 
options | 
 A bru_options options object or a list of options passed
on to   | 
.envir | 
 The evaluation environment to use for special arguments (  | 
... | 
 For   | 
object | 
 A list of   | 
envir | 
 An optional environment for the new   | 
x | 
 
  | 
i | 
 indices specifying elements to extract  | 
Value
A likelihood configuration which can be used to parameterise bru().
Functions
-  
like_list(): Combinebru_likelikelihoods into abru_like_listobject -  
like_list(list): Combine a list ofbru_likelikelihoods into abru_like_listobject -  
like_list(bru_like): Combine severalbru_likelikelihoods into abru_like_listobject -  
c(bru_like): Combine severalbru_likelikelihoods and/orbru_like_listobjects into abru_like_listobject -  
c(bru_like_list): Combine severalbru_likelikelihoods and/orbru_like_listobjects into abru_like_listobject 
Author(s)
Fabian E. Bachl bachlfab@gmail.com
Finn Lindgren finn.lindgren@gmail.com
Examples
if (bru_safe_inla() &&
    require(ggplot2, quietly = TRUE)) {
  # The like function's main purpose is to set up models with multiple likelihoods.
  # 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 like function
  lik1 <- like("gaussian", formula = y ~ x + Intercept, data = df1)
  lik2 <- like("poisson", formula = y ~ x + z + Intercept, data = df2)
  # The union of effects of both models gives the components needed to run bru
  jcmp <- ~ x + z + Intercept(1)
  jfit <- bru(jcmp, lik1, lik2)
  # 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)
}