buildFormula {rasclass} | R Documentation |
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 |
varlist |
An optional |
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 for classifiaction, the list of variables to include can be specified using the optional argument varlist. The samplename is specified previously when adding data to the rasclass-class object with the corresponding functions and should not be included in the varlist
argument.
Value
A rasclass-class
object with the newly built formula in the formula
slot.
See Also
rasclass-package
,
rasclass-class
,
rasclassRaster-class
,
readRasterFolder
,
setRasclassData
,
Examples
## Not run:
# Load data from external folder
object <- readRasterFolder(path = "mypath", samplename = "mysample",
filenames = c('myvar1.asc', 'myvar2.asc'))
## End(Not run)
# For this example, create artificial data
mysample <- c(rep(rep(c(1,2), each = 25), 25), rep(rep(c(3,4), each = 25), 25))
mysample <- mysample + sample(c(0, NA), 2500, replace = TRUE, prob = c(1, 10))
myvar1 <- rep(1:50, each = 50) + rnorm(2500, 0, 5)
myvar2 <- rep(rep(1:50), 50) + rnorm(2500, 0, 5)
myvar3 <- sample(1:2500)
newdata <- data.frame(mysample, myvar1, myvar2, myvar3)
# Prepare a rasclass object using the dataframe and specifying raster properties
object <- new('rasclass')
object <- setRasclassData(newdata, ncols = 50, nrows = 50,
xllcorner = 0, yllcorner = 0, cellsize = 1, NAvalue = -9999,
samplename = 'mysample')
# Classify and show results using all columns
object <- classifyRasclass(object)
summary(object)
# Change formula to exclude one variable
object <- buildFormula(object, varlist = c('myvar1', 'myvar3'))
# Classify and show results
object <- classifyRasclass(object)
summary(object)