Learn R Programming

rasclass (version 0.1.0)

buildFormula: Build a formula for Raster Classification

Description

This function builds a formula from the dataframe from the data slot in the specified rasclass object.

Usage

buildFormula(object, varlist = NULL)

Arguments

object
A rasclass-class object with non-empty data and samplename slots.
varlist
An optional character vector containing the names of the variables that shall be used in the classification algorithms.

Value

  • A rasclass-class object with the newly built formula in the call slot.

Details

A formula is built automatically using all the columns in the dataframe from the data slot of the specified object. The formula is stored in the call slot of the rasclass-class object. The dependent variable in the formula will be the name specified in the samplename slot of the given input object.

If not all columns from the data slot should be used, specify the list of variables to include using the optional argument varlist.

See Also

accuracyAssessment, buildFormula, checkRasclass, classifyMLC, classifyMlogit, rasclass-class, rasclassRaster-class, readRaster, readRasterFolder, setRasclassData, writeRaster

Examples

Run this code
# Load data from external folder
object <- readRasterFolder(path = "mypath", samplename = "mysample",
	filenames = c('myvar1.asc', 'myvar2.asc'))

# For this example, get data from a random dataframe
mysample <- sample(c(NA, 1, 2, 3), 20000, rep = TRUE)
red <- sample(c(NA,1:255), 20000, rep = TRUE)
green <- sample(c(NA,1:255), 20000, rep = TRUE)
blue <- sample(c(NA,1:255), 20000, rep = TRUE)
newdata <- data.frame(mysample,red,green,blue)

# Prepare object using the dataframe and specifying raster properties
object <- new('rasclass')
object <- setRasclassData(newdata, object, ncols = 100, nrows = 200,
	xllcorner = 0, yllcorner = 0, cellsize = 10, NAvalue = -9999,
	samplename = 'mysample')

# Classify and compute accuracy
object <- classifyMlogit(object, anova = TRUE)
object <- accuracyAssessment(object)

# Summarize and plot results
summary(object)
image(object@predictedGrid)

Run the code above in your browser using DataLab