gls_spatial_predict: Predict values from 'gls_spatial()' output

Description Usage Arguments Details Value Examples

View source: R/gls_spatial_predict.R

Description

After creating gls object(s) with the gls_spatial() function, this will create predicted values of the dependent variable from your regression, for the specified landcovers. Particularly useful once your landcover files have changed and you want to predict what effect this may have on the dependent variable.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
gls_spatial_predict(
  data,
  regression_results,
  landcover_varname,
  landcover_invasive,
  landcover_susceptible,
  dep_varname,
  x_coords_varname,
  y_coords_varname,
  covar_adjustment = NA
)

Arguments

data

data.frame with spatial data

regression_results

object of class gls from the gls_spatial function

landcover_varname

character string. The name of the landcover variable in data

landcover_invasive

value. Numerical or character value of the invasive landcover.

landcover_susceptible

value. Numerical or character value(s) of the susceptible landcover(s). If more than one susceptible landcover, provide a vector c().

dep_varname

character string. Name of the dependent variable in data.

x_coords_varname

character string. Name of the x-coordinate variable in data.

y_coords_varname

character string. Name of the y-coordinate variable in data.

covar_adjustment

list. List specifying change in covariate values. See details.

Details

This GLS predict function relies on a model created with the gls_spatial() function. It will not work if it is run independently (or before) the gls_spatial() function has been used to create the regression_results parameter. It returns a list of four objects: (1)a vector of predicted values under the current landcover; (2) a vector of predicted values assuming the invasive landcover takes the place of all susceptible landcovers; (3) a raster of predicted values under the current landcover; and (4) a raster of predicted values assuming the invasive landcover takes the place of all susceptible landcovers.

For covar_adjustment: If, after invasion of a pixel, a covariate var1 needs to be changed to some value a, you would specify covar_adjustment = list('var1', a). If two or more variables need to be adjusted, you would specify a list of lists like so: covar_adjustment = list(list('var1', a), list('var2', b)).

Value

A list of predicted values for current landcover, invaded landcover, and the associated rasters.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
set.seed(1)
# load packages
library(LandCover); library(foreach); library(raster)

# initialize data.frame with coordinates
dat <- expand.grid(x = 1:20, y = 1:20, KEEP.OUT.ATTRS = FALSE)


# create some data: elevation, landcover, and temp/ET dependent on elevation and landcover
dat$elevation <- with(dat, 50 + 2*x + 5*y + rnorm(nrow(dat), sd = 7))
dat$landcover <- ifelse(dat$elevation < median(dat$elevation), 1, 2)
dat[dat$x < median(dat$x) & dat$landcover == 2, 'landcover'] <- 3
dat$temp      <- with(dat, (120-0.7*(0.5*elevation + 0.3*y - 0.5*x + ifelse(landcover == 'lc1', -30, 0) + rnorm(nrow(dat)))))
dat$ET        <- with(dat, (   -0.4*(-2*temp       + 0.5*y - 1.0*x + ifelse(landcover == 'lc1', +20, 0) + rnorm(nrow(dat)))))

# run the gls model
regression_results <- gls_spatial(data = dat, landcover_varname = 'landcover', landcover_vec = c(1,2),
                                  reg_formula = ET ~ elevation + temp, error_formula = ~ x + y)

# get predicted values data
predicted_values <- gls_spatial_predict(data = dat, regression_results = regression_results, landcover_varname = 'landcover', landcover_invasive = 1, landcover_susceptible = 2, dep_varname = 'ET',
                                        x_coords_varname = 'x', y_coords_varname = 'y')

natedemaagd/LandCover documentation built on April 1, 2021, 4:14 p.m.