library(stats)
data(wetland) ## Loads species data
## Creates three clusters using kmeans
wetkm <- kmeans(wetland, centers=3)
## Run indicator analysis with species combinations for the first group
sc <- indicators(X=wetland, cluster=wetkm$cluster, group=1, verbose=TRUE, At=0.5, Bt=0.2)
## Use the indicators to make predictions of the probability of group #1
## Normally an independent data set should be used, because 'wetland' was used to derive
## indicators. The same would be obtained calling 'predict(sc)' without further arguments.
p <- predict(sc, wetland)
## Calculate cross-validated probabilities (recalculates 'A' statistics once for each site
## after excluding it, and then calls predict.indicators for that site)
pcv <- predict(sc, cv = TRUE)
## Show original membership to group 1 along with (resubstitution) predicted probabilities
## and cross-validated probabilities. Cross-validated probabilities can be lower for sites
## originally belonging to the target site group and higher for other sites.
data.frame(Group1 = as.numeric(wetkm$cluster==1), Prob = p, Prob_CV = pcv)
Run the code above in your browser using DataLab