Learn R Programming

GSIF (version 0.5-5.1)

spmultinom: Multinomial logistic regression on spatial objects

Description

Runs the multinomial logistic regression via nnet::multinom to produce spatial predictions of the target factor-type variable. It requires point locations of observed classes and a list of covariate layers provided as "SpatialPixelsDataFrame-class" object. The resulting predicted classes are then used to estimate class centres and variances per class.

Usage

# S4 method for formula,SpatialPointsDataFrame,SpatialPixelsDataFrame
spmultinom(formulaString,
     observations, covariates, class.stats = TRUE, predict.probs = TRUE, …)

Arguments

formulaString

formula string

observations

object of type "SpatialPointsData"; occurrences of factors

covariates

object of type "SpatialPixelsData"; list of covariate layers

class.stats

logical; species wether to estimate class centres

predict.probs

logical; species wether to predict probabilities per class

optional arguments

Value

Returns an object of type "SpatialMemberships" with following slots: predicted (classes predicted by the multinomial logistic regression, model (the multinomial logistic regression model), mu (probabilities derived using the mutinom model), class.c (derived class centres), class.sd (derived class deviations), confusion (confusion matrix).

References

See Also

spfkm, SpatialMemberships-class

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 <- spmultinom(formulaString, eberg, eberg_spc@predicted)
# }
# NOT RUN {
# plot memberships:
pal = seq(0, 1, 1/50)
spplot(eberg_sm@mu, col.regions=pal)
image(eberg_sm@mu[1], col=pal)
text(eberg@coords, paste(eberg$soiltype), cex=.6, col="black")
# classes predicted:
Ls = length(levels(eberg_sm@predicted$soiltype))
pnts = list("sp.points", eberg, pch="+", cex=.6, col="black")
spplot(eberg_sm@predicted, col.regions=rainbow(Ls)[rank(runif(Ls))], sp.layout=pnts)
# }

Run the code above in your browser using DataLab