Defines a data-generating model without fitting it. Parameters are supplied on their natural scale and remain fixed across simulations.
Usage
specify_glgpm(
formula,
data,
family,
parameters,
invlink = NULL,
denominator = NULL,
distance_crs = NULL,
distance_units = c("km", "m")
)Arguments
- formula
A formula object specifying the model to be fitted. The formula should include fixed effects and spatial effects specified using
gp()and optionally, random effects specified usingre(). It can also include oneoffset()term that names a column ofdata, e.g.offset(log_exposure).- data
An sf object containing the variables in the model.
- family
The distribution of the response given the random effects, with its link. Either one of the strings
"gaussian","binomial"and"poisson", which take the identity, logit and log links, a family object as instats::glm(), such asbinomial("probit"), ornegative_binomial()for overdispersed counts with the log link, whose size is estimated unless it is held, byfixed_parsofglgpm()or by the family objectMASS::negative.binomial(2). Where nothing is estimated, as inspecify_glgpm(), the size must be given, asthetain itsparameters. Binomial responses take the logit, probit, complementary log-log ("cloglog") and Cauchy ("cauchit") links, Poisson responses the log link and Gaussian responses the identity link.binomial("log")andpoisson("identity")are not accepted, because they can give means outside the range of the family, nor ispoisson("sqrt"), whose inverse gives the same mean to a positive and a negative linear predictor. Quasi-likelihood families, such asstats::quasibinomial(), have no likelihood to maximise and are not accepted either. Any other link can be given ininvlink. A named link gives the same estimates as its inverse given ininvlink, and is faster when that inverse cannot be differentiated symbolically, as forinvlink = pnorm.- parameters
A named list containing
beta,sigma2andphi.betahas one entry per design-matrix column, including the intercept when present. Supplytau2whengp(nugget = TRUE),sigma2_mefor Gaussian measurement error,thetafor the size of a negative binomial family, andsigma2_refor eachre()term. Variances may be zero.phiis expressed indistance_units.- invlink
A function that maps the linear predictor to the mean of the response given the random effects, for a binomial or Poisson model whose link is not one of those that
familynames, such as a link for an imperfect diagnostic test. Its first and second derivatives are found symbolically where possible and numerically otherwise. They only steer the importance sampler, so they affect the speed of a fit and not its estimates. Not applicable for Gaussian models, and not to be combined with a family object that names a link other than logit or log. Custom links are experimental, and how they are given and checked may change in a minor release.- denominator
Optional denominator for binomial distributions, or exposure for Poisson and negative binomial ones, the mean of a count being the exposure times the inverse link of the linear predictor. Passed as a bare/unquoted column name present in
data. If not provided, defaults to1.- distance_crs
The projected coordinate reference system in which distances, and so
phi, are measured, for example an EPSG code.dataare transformed to it. The default,NULL, keeps projected data as they are and projects longitude/latitude data to the CRS frompropose_crs(), with a message naming it. A warning of classriskmap_warning_crsis raised when the CRS used distorts distances by more than 1% over the data.- distance_units
Character string, either
"km"or"m", indicating the units used for internal coordinate distances and spatial parameters such asphi. The coordinates of the data keep the linear units of their CRS. Defaults to"km".
Value
A validated RiskMap_simulation_model for simulate_glgpm(). It
contains the formula, transformed model data, family, fixed parameters,
denominator name, distance units, inverse link, fixed-effect design
information, random-effect terms, offset, Matern smoothness and response.
See also
print() describes the model,
and simulate_glgpm() simulates from it.
Examples
library(sf)
locations <- st_as_sf(data.frame(x = c(0, 1000, 2000), y = 0),
coords = c("x", "y"), crs = 32629)
grid <- st_as_sf(data.frame(x = c(500, 1500), y = 500),
coords = c("x", "y"), crs = 32629)
model <- specify_glgpm(response ~ gp(),
data = locations,
family = "gaussian",
parameters = list(beta = 1,
sigma2 = 1,
phi = 2,
sigma2_me = 0.1))
