Learn R Programming

fieldRS (version 0.2.3)

classModel: classModel

Description

Derives a spatially-explicit predictive model as well as sample-wise validation.

Usage

classModel(x, y, z, mode = "classification", ...)

Arguments

x

Object of class data.frame.

y

A vector of class character or numeric.

z

A vector of class character or numeric.

mode

One of "classification" or "regression".

...

Arguments passed to train.

Value

A two element numeric vector.

Details

Uses train to derive a predictive model based on x - which contains the predictors - and y - which contains information on the target classes (if mode is "classification") or values (if mode is "regression"). This method iterates through all samples making sure that all contribute for the final accuracy. To specify how the samples should be split, the user should provide the sample-wise identifiers through z. For each unique value in z, the function keeps it for validation and the remaining samples for training. This process is repeated for all sample groups and a final accuracy is estimated from the overall set of results. If mode is "classification", the function will estimate the overall accuracy for each unique value in y. If "regression" is set, the output will be an the coefficient of determination. The classification algorithm and additional commands can be set through ... using inputs of the train function. Apart from the accuracy assessment, the function stores the performance for each sample. If mode is "classification", the function will return a logical vector reporting on the correctly assigned classes. If mode is "regression", the function will report on the percent deviation between the original value and it's predicted value. The final output of the function is a list consisting of:

  • sample.validation - Accuracy assessment of each sample.

  • overall.validation - Finally accuracy value for each class (if "classification").

  • r2 - Correlation between y and the predicted values (if "regression")

See Also

raster2sample poly2sample ccLabel

Examples

Run this code
# NOT RUN {
{

require(raster)

# read raster data
r <- brick(system.file("extdata", "ndvi.tif", package="fieldRS"))

# read field data
data(fieldData)
fieldData <- fieldData[c(1:3, 10),]

# extract values for polygon centroid
c <- spCentroid(fieldData)
ev <- as.data.frame(extract(r, c))

cm <- classModel(ev, fieldData$crop, as.character(1:length(fieldData)), method="rf")

}
# }

Run the code above in your browser using DataLab