View source: R/main-fit_model.R
lgp | R Documentation |
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.
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,
...
)
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
|
Returns an object of the S4 class lgpfit.
There are two ways to define the model formula:
Using a common formula
-like syntax, like in
y ~ age +
age|id
+ sex
. Terms can consist of a
single variable, such as age
, or an interaction of two variables,
such as age|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 that
single-variable terms become gp(x)
if
variable x
is numeric and zs(x)
if x
is a factor
interaction terms x|z
become gp(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.
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.
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 parameters
alpha
and possible noise parameters (sigma
, phi
,
gamma
). Also it should be checked if c_hat
is set in a
sensible way.
Using a model that contains a gp_ns(x)
or gp_vm(x)
expression in its formula. In this case the corresponding covariate
x
is not normalized, and the prior for the input warping steepness
parameter wrp
must be set according to the expected width of the
window in which the nonstationary effect of x
occurs. By default,
the width of this window is about 36, which has been set assuming that
the unit of x
is months.
Other main functions:
create_model()
,
draw_pred()
,
get_draws()
,
pred()
,
prior_pred()
,
sample_model()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.