fit.regModel-methods {GSIF}R Documentation

Fits a regression model to spatial data

Description

Fits a regression or a trend model (e.g. a GLM) and, if not available, a variogram for the response residuals using the default settings.

Usage

## S4 method for signature 
## 'formula,data.frame,SpatialPixelsDataFrame,character'
fit.regModel(formulaString, rmatrix, predictionDomain, 
      method = list("GLM", "rpart", "randomForest", "quantregForest", "lme",
       "xgboost", "ranger"), 
      dimensions = NULL, fit.family = gaussian(), stepwise = TRUE, rvgm, 
      GLS = FALSE, steps, subsample, subsample.reg, ...)

Arguments

formulaString

object of class "formula" — regression model

rmatrix

object of class "data.frame"; regression matrix produced as a result of spatial overlay

predictionDomain

object of class "SpatialPixelsDataFrame"; spatial domain of interest

method

character; family of methods considered e.g. "GLM", "rpart" (regression trees), "randomForest" (random forest)

dimensions

character; "2D", "3D", "2D+T", or "3D+T"

fit.family

family to be passed to the glm (see examples below)

stepwise

specifies whether to run step-wise regression on top of GLM to get an optimal subset of predictors

rvgm

residual variogram (to avoid fitting the variogram set as NULL)

GLS

fit trend model using Generalized Least Squares implemented in the nlme package

steps

integer; the maximum number of steps to be considered for step-wise regression; see stats::step for more details

subsample

integer; maximum number of observations to be taken for variogram model fitting (to speed up variogram fitting)

subsample.reg

integer; maximum number of observations to be taken for regression model fitting (especially important for randomForest modelling)

...

other optional arguments that can be passed to gstat::fit.variogram

Details

Produces an object of class "gstatModel" that contains: (1) fitted regression model (e.g. a GLM, cubist model, or randomForest model), (2) fitted variogram, and (c) object of class "SpatialPoints" with observation locations. To combine overlay and model fitting operations, consider using fit.gstatModel.

Author(s)

Tomislav Hengl, Mario Antonio Guevara Santamaria and Bas Kempen

See Also

fit.gstatModel, stats::glm, gstat::fit.variogram, randomForest::randomForest

Examples

library(sp)
library(rpart)
library(nlme)
library(gstat)
library(randomForest)
library(quantregForest)
library(xgboost)
library(caret)
library(scales)
library(AICcmodavg)

## load the Meuse data set:
demo(meuse, echo=FALSE)

## prepare the regression matrix:
ov <- over(meuse, meuse.grid)
ov <- cbind(data.frame(meuse["om"]), ov)
## skip variogram fitting:
m <- fit.regModel(om~dist+ffreq, rmatrix=ov, meuse.grid, 
    fit.family=gaussian(log), method="GLM", rvgm=NULL)
m@regModel
m@vgmModel
plot(m)
## fit a GLM with variogram:
m1 <- fit.regModel(om~dist+ffreq, rmatrix=ov, meuse.grid, 
    fit.family=gaussian(log), method="GLM")
m1@vgmModel
plot(m1)
rk1 <- predict(m1, meuse.grid)
plot(rk1)

## fit a regression tree with variogram:
m2 <- fit.regModel(log1p(om)~dist+ffreq, rmatrix=ov, meuse.grid,
     method="rpart")
plot(m2)
rk2 <- predict(m2, meuse.grid)
plot(rk2)

## fit a lme model with variogram:
m3 <- fit.regModel(log1p(om)~dist, rmatrix=ov, meuse.grid,
     method="lme", random=~1|ffreq)
plot(m3)
#rk3 <- predict(m3, meuse.grid)
#plot(rk3)

## fit a randomForest model with variogram
## NOTE: no transformation required
m4 <- fit.regModel(om~dist+ffreq, rmatrix=ov, meuse.grid,
     method="randomForest")
plot(m4)
rk4 <- predict(m4, meuse.grid)
plot(rk4)

## RF is very sensitive to the 'mtry' argument:
m4b <- fit.regModel(om~dist+ffreq, rmatrix=ov, meuse.grid,
     method="randomForest", mtry=2)
plot(m4b)

## Not run: 
## RF with uncertainty (quantregForest package)
m5 <- fit.regModel(om~dist+ffreq, rmatrix=ov, meuse.grid,
     method="quantregForest")
plot(m5)
rk5 <- predict(m5, meuse.grid)
plot(rk5)
dev.off()
## plot prediction error map:
spplot(rk5@predicted["var1.var"])

## ranger
m6 <- fit.regModel(om~dist+ffreq, rmatrix=ov, meuse.grid,
     method="ranger", rvgm=NULL)
plot(m6)
rk6 <- predict(m6, meuse.grid)
plot(rk6)

## XGBoost
m7 <- fit.regModel(om~dist+ffreq, rmatrix=ov, meuse.grid,
     method="xgboost", rvgm=NULL)
plot(m7)
rk7 <- predict(m7, meuse.grid)
plot(rk7)

## End(Not run)

[Package GSIF version 0.5-5 Index]