fit.regModel: Fits a regression model to spatial data

Description Usage Arguments Details Author(s) See Also Examples

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

1
2
3
4
5
6
7
## 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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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)

GSIF documentation built on May 2, 2019, 5:44 p.m.

Related to fit.regModel in GSIF...