lgp {lgpr} | R Documentation |
Main function of the 'lgpr' package
Description
Creates an additive Gaussian process model using
create_model
and fits it using sample_model
.
See the
Mathematical description of lgpr models
vignette for more information about the connection between different options
and the created statistical model.
Usage
lgp(
formula,
data,
likelihood = "gaussian",
prior = NULL,
c_hat = NULL,
num_trials = NULL,
options = NULL,
prior_only = FALSE,
verbose = FALSE,
sample_f = !(likelihood == "gaussian"),
quiet = FALSE,
skip_postproc = sample_f,
...
)
Arguments
formula |
The model formula, where
See the "Model formula syntax" section below ( |
data |
A |
likelihood |
Determines the observation model. Must be either
|
prior |
A named list, defining the prior distribution of model
(hyper)parameters. See the "Defining priors" section below
( |
c_hat |
The GP mean. This should only be given if
where |
num_trials |
This argument (number of trials) is only needed when
likelihood is |
options |
A named list with the following possible fields:
If |
prior_only |
Should likelihood be ignored? See also
|
verbose |
Can messages be printed during model creation? Has no
effect if |
sample_f |
Determines if the latent function values are sampled
(must be |
quiet |
Should all output messages be suppressed? You need to set
also |
skip_postproc |
Should all postprocessing be skipped? If this is
|
... |
Optional arguments passed to
|
Value
Returns an object of the S4 class lgpfit.
Model formula syntax
There are two ways to define the model formula:
Using a common
formula
-like syntax, like iny ~ age +
age|id
+ sex
. Terms can consist of a single variable, such asage
, or an interaction of two variables, such asage|id
. In single-variable terms, the variable can be either continuous (numeric) or categorical (factor), whereas in interaction terms the variable on the left-hand side of the vertical bar (|
) has to be continuous and the one on the right-hand side has to be categorical. Formulae specified using this syntax are translated to the advanced format so thatsingle-variable terms become
gp(x)
if variablex
is numeric andzs(x)
ifx
is a factorinteraction terms
x|z
becomegp(x)*zs(z)
Using the advanced syntax, like in
y ~ gp(age) +
gp(age)*zs(id) +
het(id)*gp_vm(disAge)
. This creates lgprhs objects, which consist of lgpterms, which consist of lgpexprs. This approach must be used if creating nonstationary, heterogeneous or temporally uncertain components.
Either one of the approaches should be used and they should not be mixed.
Defining priors
The prior
argument must be a named list, like
list(alpha=student_t(4), wrp=igam(30,10))
. See examples in tutorials.
Possible allowed names are
-
"alpha"
= component magnitude parameters -
"ell"
= component lengthscale parameters -
"wrp"
= input warping steepness parameters -
"sigma"
= noise magnitude (Gaussian obs. model) -
"phi"
= inv. overdispersion (negative binomial obs. model) -
"gamma"
= overdispersion (beta-binomial obs. model) -
"beta"
= heterogeneity parameters -
"effect_time"
= uncertain effect time parameters -
"effect_time_info"
= additional options for the above
See priors
for functions that can be
used to define the list elements. If a parameter of a model is not given
in this list, a default prior will be used for it.
When to not use default priors
It is not recommended to use default priors blindly. Rather, priors should
be specified according to the knowledge about the problem at hand, as in any
Bayesian analysis. In lgpr
this is especially important when
Using a non-Gaussian likelihood or otherwise setting
sample_f = TRUE
. In this case the response variable is not normalized, so the scale on which the data varies must be taken into account when defining priors of the signal magnitude parametersalpha
and possible noise parameters (sigma
,phi
,gamma
). Also it should be checked ifc_hat
is set in a sensible way.Using a model that contains a
gp_ns(x)
orgp_vm(x)
expression in its formula. In this case the corresponding covariatex
is not normalized, and the prior for the input warping steepness parameterwrp
must be set according to the expected width of the window in which the nonstationary effect ofx
occurs. By default, the width of this window is about 36, which has been set assuming that the unit ofx
is months.
See Also
Other main functions:
create_model()
,
draw_pred()
,
get_draws()
,
pred()
,
prior_pred()
,
sample_model()