Learn R Programming

GSIF (version 0.5-5.1)

spfkm: Supervised fuzzy k-means on spatial pixels

Description

Runs supervised fuzzy k-means (Hengl et al., 2004) using a list of covariates layers provided as "SpatialPixelsDataFrame-class" object. If class centres and variances are not provided, it first fits a multinomial logistic regression model (spmultinom), then predicts the class centres and variances based on the output from the nnet::multinom.

Usage

# S4 method for formula,SpatialPointsDataFrame,SpatialPixelsDataFrame
spfkm(formulaString,
           observations, covariates, class.c = NULL, class.sd = NULL, fuzzy.e = 1.2)

Arguments

formulaString

formula string

observations

object of type "SpatialPointsData"; occurrences of factors

covariates

object of type "SpatialPixelsData" or "RasterBrick"; list of covariate layers

class.c

object of type "matrix"; class centres (see examples below)

class.sd

object of type "matrix"; class deviations (see examples below)

fuzzy.e

object of type "numeric"; fuzzy exponent

Value

Returns an object of type "SpatialMemberships" with following slots: predicted (classes predicted either by the multinomial logistic regression or fuzzy k-means), model (the multinomial logistic regression model; if available), mu (memberships derived using the fuzzy k-means), class.c (submitted or derived class centres), class.sd (submitted or derived class deviations), confusion (confusion matrix).

References

See Also

spmultinom, SpatialMemberships-class, nnet::multinom

Examples

Run this code
# NOT RUN {
# load data:
library(plotKML)
library(sp)

data(eberg)
# subset to 20%:
eberg <- eberg[runif(nrow(eberg))<.2,]
data(eberg_grid)
coordinates(eberg) <- ~X+Y
proj4string(eberg) <- CRS("+init=epsg:31467")
gridded(eberg_grid) <- ~x+y
proj4string(eberg_grid) <- CRS("+init=epsg:31467")
# derive soil predictive components:
eberg_spc <- spc(eberg_grid, ~PRMGEO6+DEMSRT6+TWISRT6+TIRAST6)
# predict memberships:
formulaString = soiltype ~ PC1+PC2+PC3+PC4+PC5+PC6+PC7+PC8+PC9+PC10
eberg_sm <- spfkm(formulaString, eberg, eberg_spc@predicted)
# }
# NOT RUN {
# plot memberships:
pal = seq(0, 1, 1/50)
spplot(eberg_sm@mu, col.regions=grey(rev(pal)))
# predict soil properties using memberships:
glm.formulaString = as.formula(paste("SNDMHT_A ~ ", 
    paste(names(eberg_sm@mu), collapse="+"), "-1"))
SNDMHT.m2 <- fit.gstatModel(observations=eberg, glm.formulaString, 
    covariates=eberg_sm@mu)
summary(SNDMHT.m2@regModel)
# Coefficients correspond to the class centres;
# }

Run the code above in your browser using DataLab