Learn R Programming

GSIF (version 0.5-3)

autopredict-methods: Autopredict numeric or factor type variables

Description

Fits a spatial prediction model via the fit.gstatModel function (in the case of numeric variable), or some classification algorithm (factor-type variable), and generates predictions. By defaults uses machine learning method (random forest) as implemented in the ranger package.

Usage

"autopredict"(target, covariates, auto.plot=TRUE, spc=TRUE, buffer.dist=TRUE, ...)

Arguments

target
object of class "SpatialPointsDataFrame" containing observations of the target variable
covariates
object of class "SpatialPixelsDataFrame"; spatial covariates
auto.plot
logical; specifies whether to immediately plot the data via the plotKML function
spc
logical; specifies whether to generate spatial predictive components
buffer.dist
logical; specifies whether to use buffer distances as covariates
...
other optional arguments that can be passed to fit.gstatModel

Details

For factor-type variables, classes with <5 observations="" are="" automatically="" removed="" from="" analysis.="" generation="" of="" principal="" components="" via="" the="" spc function and buffer distances can be time-consuming for large rasters.

See Also

fit.gstatModel

Examples

Run this code
library(sp)
library(gstat)
library(ranger)
library(plotKML)
library(raster)

## Ebergotzen data set:
data(eberg)
## subset to 8%
eberg <- eberg[runif(nrow(eberg))<.08,]
coordinates(eberg) <- ~X+Y
proj4string(eberg) <- CRS("+init=epsg:31467")
data(eberg_grid)
gridded(eberg_grid) <- ~x+y
proj4string(eberg_grid) <- CRS("+init=epsg:31467")

## predict sand content:
SNDMHT_A <- autopredict(eberg["SNDMHT_A"], eberg_grid,
   auto.plot=FALSE, rvgm=NULL)
plot(raster(SNDMHT_A$predicted["SNDMHT_A"]), col=SAGA_pal[[1]])

## predict soil types:
soiltype <- autopredict(eberg["soiltype"], eberg_grid, 
  auto.plot=FALSE)
## Not run: 
# spplot(soiltype$predicted, col.regions=R_pal[[2]])
# ## most probable class:
# eberg_grid$soiltype <- as.factor(apply(soiltype$predicted@data, 1, which.max))
# levels(eberg_grid$soiltype) = names(soiltype$predicted@data)
# spplot(eberg_grid["soiltype"])
# 
# ## Meuse data set:
# demo(meuse, echo=FALSE)
# zinc <- autopredict(meuse["zinc"], meuse.grid[c("dist","ffreq")], 
#   auto.plot=FALSE, rvgm=NULL)
# spplot(zinc$predicted["zinc"])
# ## End(Not run)

Run the code above in your browser using DataLab