Skip to contents

Fitting linear mixed effects model with latent Whittle-Matern models.

Usage

rspde_lme(
  formula,
  loc,
  loc_time = NULL,
  data,
  model = NULL,
  repl = NULL,
  which_repl = NULL,
  optim_method = "L-BFGS-B",
  possible_methods = c("L-BFGS-B", "Nelder-Mead"),
  use_data_from_graph = TRUE,
  rspde_order = NULL,
  mean_correction = FALSE,
  previous_fit = NULL,
  fix_coeff = FALSE,
  model_options = list(),
  smoothness_upper_bound = 4,
  parallel = FALSE,
  n_cores = parallel::detectCores() - 1,
  optim_controls = list(),
  improve_hessian = FALSE,
  hessian_args = list(),
  alpha = lifecycle::deprecated(),
  nu = lifecycle::deprecated(),
  beta = lifecycle::deprecated(),
  starting_values_latent = lifecycle::deprecated(),
  start_sigma_e = lifecycle::deprecated(),
  start_alpha = lifecycle::deprecated(),
  start_nu = lifecycle::deprecated(),
  start_beta = lifecycle::deprecated(),
  nu_upper_bound = lifecycle::deprecated()
)

Arguments

formula

Formula object describing the relation between the response variables and the fixed effects. If the response variable is a matrix, each column of the matrix will be treated as a replicate.

loc

A vector with the names of the columns in data that contain the observation locations, or a matrix or a data.frame containing the observation locations. If the model is of class metric_graph, the locations must be either a matrix or a data.frame with two columns, or a character vector with the names of the two columns. The first column being the number of the edge, and the second column being the normalized position on the edge. If the model is a 2d model, loc must be either a matrix or data.frame with two columns or a character vector with the name of the two columns that contain the location, the first entry corresponding to the x entry and the second corresponding to the y entry.

loc_time

For spatio-temporal models, the name of the column in data that is the time variable, or a matrix or vector containing the observation time points.

data

A data.frame containing the data to be used.

model

Object generated by matern.operators(), spde.matern.operators() or spacetime.operators(). If NULL, simple linear regression will be performed.

repl

Vector indicating the replicate of each observation. If NULL it will assume there is only one replicate. If the model is generated from graphs from metric_graph class and use_data_from_graph is TRUE, repl needs to be the name of the column inside the metric graph data that contains the replicate. If NULL it will assume there is only one replicate.

which_repl

Which replicates to use? If NULL all replicates will be used.

optim_method

The method to be used with optim function.

possible_methods

The optimization methods to try if the model fitting fails.

use_data_from_graph

Logical. Only for models generated from graphs from metric_graph class. In this case, should the data, the locations and the replicates be obtained from the graph object?

rspde_order

The order of the rational approximation to be used while fitting the model. If not given, the order from the model object will be used. Not used for spatio-temporal models.

mean_correction

If TRUE, use mean correction for intrinsic models. Default FALSE.

previous_fit

An object of class rspde_lme. Use the fitted coefficients as starting values.

fix_coeff

If using a previous fit, should all coefficients be fixed at the starting values?

model_options

A list containing additional options to be used in the model. This will take preference over the values extracted from previous_fit. Currently, it is possible to fix parameters during the estimation or change the starting values of the parameters. The general structure of the elements of the list is fix_parname and start_parname, where parname stands for the name of the parameter. If fix_parname is not NULL, then the model will be fitted with the parname being fixed at the value that was passed. If start_parname is not NULL, the model will be fitted using the value passed as starting value for parname. For 'rSPDE' and 'rSPDE1d' models, the possible elements of the list are fix_sigma_e, start_sigma_e, fix_nu, start_nu, fix_sigma, start_sigma, fix_range, start_range. Alternatively, one can also use the elements fix_sigma_e, start_sigma_e, fix_nu, start_nu, fix_tau, start_tau, fix_kappa, start_kappa. For 'spacetime' models, the possible elements of the list are fix_sigma_e, start_sigma_e, fix_kappa, start_kappa, fix_sigma, start_sigma, fix_gamma, start_gamma, fix_rho, start_rho. For dimension 2, the second coordinate of rho has name rho2 and must be passed as start_rho2 and fix_rho2. For 'rSPDE2d' models, the possible elements of the list are fix_sigma_e, start_sigma_e, fix_nu, start_nu, fix_sigma, start_sigma, fix_hx, start_hx, fix_hy, start_hy, fix_hxy, start_hxy. For nonstationary models, we have two options: the first is to pass the starting values as a vector with name start_theta and a vector with the names of the parameters to be fixed with name fix_theta; the second option is to handle the individual parameters, by passing the names thetan where n is the number of the parameter to pass the starting value or to be fixed. For example, to pass the starting value for theta3 one simply pass start_theta3, and to fix theta2, one simply pass fix_theta2.

smoothness_upper_bound

Upper bound for nu, when nu is the smoothness parameter, or for alpha - d/2 when alpha is the smoothness parameter, or for max\{alpha - d/2, beta - d/2) for intrinsic models.

parallel

logical. Indicating whether to use optimParallel or not.

n_cores

Number of cores to be used if parallel is true.

optim_controls

Additional controls to be passed to optim or optimParallel.

improve_hessian

Should a more precise estimate of the hessian be obtained? Turning on might increase the overall time.

hessian_args

List of controls to be used if improve_hessian is TRUE. The list can contain the arguments to be passed to the method.args argument in the numDeriv::hessian function. See the help of the hessian function in numDeriv package for details. Observe that it only accepts the "Richardson" method for now, the method "complex" is not supported.

alpha

[Deprecated] Use model_options instead.

nu

[Deprecated] Use model_options instead.

beta

[Deprecated] Use model_options instead.

starting_values_latent

[Deprecated] Use model_options instead.

start_sigma_e

[Deprecated] Use model_options instead.

start_alpha

[Deprecated] Use model_options instead.

start_nu

[Deprecated] Use model_options instead.

start_beta

[Deprecated] Use model_options instead.

nu_upper_bound

[Deprecated] Use smoothness_upper_bound instead.

Value

A list containing the fitted model.