Estimates regression coefficients and spatial autocorrelation parameters, given spatial coordinates and a model formula.

slmfit(
  formula,
  data,
  xcoordcol,
  ycoordcol,
  areacol = NULL,
  stratacol = NULL,
  CorModel = "Exponential",
  estmethod = "REML",
  covestimates = c(NA, NA, NA)
)

Arguments

formula

is an R linear model formula specifying the response variable as well as covariates for predicting the response on the unsampled sites.

data

is a data frame or tibble with the response column, the covariates to be used for the block kriging, and the spatial coordinates for all of the sites. Alternatively, data can be an sp Spatial Points Data Frame or sf object with POINT geometry.

xcoordcol

is the name of the column in the data frame with x coordinates or longitudinal coordinates

ycoordcol

is the name of the column in the data frame with y coordinates or latitudinal coordinates

areacol

is the name of the column with the areas of the sites. By default, we assume that all sites have equal area, in which case a vector of 1's is used as the areas.

stratacol

is the name of the the column with the stratification variable, if strata are to be fit separately, with different covariance parameter estimates.

CorModel

is the covariance structure. By default, CorModel is Exponential but other options include the Spherical and Gaussian.

estmethod

is either the default "REML" for restricted maximum likelihood to estimate the covariance parameters and regression coefficients or "ML" to estimate the covariance parameters and regression coefficients. This argument can also be set to "None", in which case covestimates must be provided.

covestimates

is an optional vector of covariance parameter estimates (nugget, partial sill, range). If these are given and estmethod = "None", the the provided vector are treated as the estimators to create the covariance structure.

Value

a list of class slmfit with

  • the spatial covariance estimates

  • the regression coefficient estimates

  • the covariance matrix of the fixed effects

  • minus two times the log-likelihood of the model

  • the names of the predictors

  • the sample size

  • the name of the covariance model used

  • a vector of residuals

  • the design matrix

  • a vector of the sampled densities

  • a list containing

    1. formula, the model formula

    2. data, the data set input as the data argument

    3. xcoordcol, the name of the x-coordinate column

    4. ycoordcol, the name of the y-coordinate column

    5. estmethod, either REML or ML

    6. CorModel, the correlation model used

    7. estimated covariance matrix of all sites

    8. Inverted covariance matrix on the sampled sites

    9. the vector of areas.

Examples

data(exampledataset) ## load a toy data set
slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset,
xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar')
summary(slmobj)
#> 
#> Call:
#> counts ~ pred1 + pred2
#> 
#> Residuals:
#>     Min      1Q  Median      3Q     Max 
#> -16.086  -9.120  -4.596   4.963  28.594 
#> 
#> Coefficients:
#>             Estimate Std. Error t value Pr(>|t|)    
#> (Intercept)   26.104      4.465   5.847   <2e-16 ***
#> pred1          2.055      6.065   0.339    0.737    
#> pred2          0.214      1.913   0.112    0.912    
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> Covariance Parameters:
#>              Exponential Model
#> Nugget            2.323211e-04
#> Partial Sill      1.543624e+02
#> Range             8.240060e-01
#> 
#> Generalized R-squared: 0.00413886 

data(exampledataset) ## load a toy data set
exampledataset$strata <- c(rep("A", 19), rep("B", 21))
strataobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset, stratacol = "strata",
xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar')
summary(strataobj)
#> $A
#> 
#> Call:
#> counts ~ pred1 + pred2
#> 
#> Residuals:
#>     Min      1Q  Median      3Q     Max 
#> -7.7826 -2.1499  0.0488  1.5492  9.8233 
#> 
#> Coefficients:
#>             Estimate Std. Error t value Pr(>|t|)  
#> (Intercept)  22.2882    35.0930   0.635   0.5364  
#> pred1        -6.5176     3.6384  -1.791   0.0965 .
#> pred2         0.5545     1.7976   0.308   0.7626  
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> Covariance Parameters:
#>              Exponential Model
#> Nugget                 20.0915
#> Partial Sill         1227.2769
#> Range                8575.6681
#> 
#> Generalized R-squared: 0.1998733 
#> 
#> $B
#> 
#> Call:
#> counts ~ pred1 + pred2
#> 
#> Residuals:
#>    Min     1Q Median     3Q    Max 
#> -9.262 -4.974  1.516  3.355 14.635 
#> 
#> Coefficients:
#>             Estimate Std. Error t value Pr(>|t|)    
#> (Intercept)   19.146      2.994   6.395    1e-05 ***
#> pred1          1.430      5.255   0.272    0.789    
#> pred2         -1.603      1.274  -1.259    0.226    
#> ---
#> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#> 
#> Covariance Parameters:
#>              Exponential Model
#> Nugget            4.188789e-05
#> Partial Sill      4.205452e+01
#> Range             4.954309e-01
#> 
#> Generalized R-squared: 0.09916644 
#>