Description Usage Arguments Details Value Examples
View source: R/gls_spatial_predict.R
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.
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
)
|
data |
|
regression_results |
object of class |
landcover_varname |
character string. The name of the landcover variable in |
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 |
dep_varname |
character string. Name of the dependent variable in |
x_coords_varname |
character string. Name of the x-coordinate variable in |
y_coords_varname |
character string. Name of the y-coordinate variable in |
covar_adjustment |
list. List specifying change in covariate values. See 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))
.
A list of predicted values for current landcover, invaded landcover, and the associated rasters.
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')
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.