geoR (version 1.8-1)

trend.spatial: Builds the Trend Matrix


Builds the trend matrix in accordance to a specification of the mean provided by the user.


trend.spatial(trend, geodata,



specifies the mean part of the model. See DETAILS below.


optional. An object of the class geodata as described in as.geodata.

optional. Specifies aditional terms to the mean part of the model. See details below.


An object of the class trend.spatial which is an \(n \times p\) trend matrix, where \(n\) is the number of spatial locations and \(p\) is the number of mean parameters in the model.


The implicity model assumes that there is an underlying process with mean \(\mu(x)\), where \(x = (x_1, x_2)\) denotes the coordinates of a spatial location. The argument trend defines the form of the mean and the following options are allowed:

  • "cte"the mean is assumed to be constant over the region, in which case \(\mu(x)= \mu\). This is the default option.

  • "1st"the mean is assumed to be a first order polynomial on the coordinates: $$\mu(x)= \beta_0 + \beta_1 x_1 + \beta_2 x_2$$

  • "2nd"the mean is assumed to be a second order polynomial on the coordinates: $$\mu(x)= \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \beta_3 (x_1)^2 + \beta_4 (x_2)^2 + \beta_5 x_1 * x_2$$

  • ~ modela model specification. See formula for further details on how to specify a model in R using formulas. Notice that the model term before the ~ is not necessary. Typically used to include covariates (external trend) in the model.

Denote by \(x_1\) and \(x_2\) the spatial coordinates. The following specifications are equivalent:

  • trend = "1st" and trend = ~ x1 + x2

  • trend = "2nd" and trend = ~ x1 + x2 + I(x1^2) + I(x2^2) + I(x1*x2)

Search path for covariates Typically, functions in the package geoR which calls trend.spatial will have the arguments geodata, coords and data.

When the trend is specifed as trend = ~ model the terms included in the model will be searched for in the following path sequence (modified in version 1.7-6, no longer attach objects):

  1. in the object geodata (coerced to data-frame)

  2. in the users/session Global environment

  3. in the session search path

The argument adds terms to what is specified in the argument trend. This seems redundant but allow specifications of the type: trend="2nd", add.trend=~other.covariates.


Further information on the package geoR can be found at:

See Also

The section DETAILS in the documentation for likfit for more about the underlying model.


# a first order polynomial trend
trend.spatial("1st", sic.100)[1:5,]
# a second order polynomial trend
trend.spatial("2nd", sic.100)[1:5,]
# a trend with a covariate
trend.spatial(~altitude, sic.100)[1:5,]
# a first degree trend plus a covariate
trend.spatial(~coords+altitude, sic.100)[1:5,]
# with produces the same as
trend.spatial("1st", sic.100, add=~altitude)[1:5,]
# and yet another exemple
trend.spatial("2nd", sic.100, add=~altitude)[1:5,]
# }