Learn R Programming

GSIF (version 0.3-1)

fit.regModel-methods: 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

## S3 method for class 'formula,data.frame,SpatialPixelsDataFrame,character':
fit.regModel(formulaString, rmatrix, predictionDomain, 
      method = list("GLM", "rpart", "randomForest", "HB")[[1]], 
      dimensions = NULL, family=gaussian, stepwise=TRUE, rvgm, ...)

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"
dimensions
character; "3D", "2D", "2D+T", "3D+T" models
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)
...
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, randomForest model or a hierarchical Bayes model), (2) fitted variogram, and (c) object of class "SpatialPoints" with observation locations. To combine overlay and model fitting operations, consider using fit.gstatModel.

See Also

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

Examples

Run this code
## Meuse data:
library(sp)
library(randomForest)
library(rpart)

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

## produce a 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, 
    family=gaussian(log), method="GLM", rvgm=NULL)
m@regModel
m@vgmModel
## fit a GLM with variogram:
m1 <- fit.regModel(om~dist+ffreq, rmatrix=ov, meuse.grid, 
    family=gaussian(log), method="GLM")
m1@vgmModel
## fit a regression tree with variogram:
m2 <- fit.regModel(log1p(om)~dist+ffreq, rmatrix=ov, meuse.grid,
     method="rpart")

Run the code above in your browser using DataLab