Skip to contents

Computes a selection of external clustering evaluation metrics for spatial data.

Usage

getSpatialExternalMetrics(
  true,
  pred,
  location,
  k = 6,
  alpha = 0.5,
  level = "class",
  metrics = c("SpatialWH", "SpatialAWH", "SpatialWC", "SpatialAWC"),
  fuzzy_true = TRUE,
  fuzzy_pred = FALSE,
  ...
)

Arguments

true

A vector containing the labels of the true classes. Must be a vector of characters, integers, numerics, or a factor, but not a list.

pred

A vector containing the labels of the predicted clusters. Must be a vector of characters, integers, numerics, or a factor, but not a list.

location

A matrix or data.frame of coordinates

k

The number of neighbors used when calculating the fuzzy class memberships for fuzzy metrics, or when calculating the weighted accuracy.

alpha

The parameter to control to what extend the spot itself contribute to the class composition calculation. "equal" means it is weighted the same as other neighbors. A numeric value between 0 and 1 means the weight of the frequency contribution for the spot itself, and the frequency contribution for its knn is then 1-alpha. By default 0.5.

level

The level to calculate the metrics. Options include "element", "class" and "dataset".

metrics

The metrics to compute. See details.

fuzzy_true

Logical; whether to compute fuzzy class memberships for true.

fuzzy_pred

Logical; whether to compute fuzzy class memberships for pred.

...

Optional params for getFuzzyPartitionElementMetrics() or findSpatialKNN().

Value

A data.frame of metrics.

Details

The allowed values for metrics depend on the value of level:

  • If level = "element", the allowed metrics are: "SpatialSPC", "SpatialNPC".

  • If level = "class", the allowed metrics are: "SpatialWH","SpatialAWH", "SpatialWC","SpatialAWC".

  • If level = "dataset", the allowed metrics are: "SpatialRI","SpatialARI","SpatialWH","SpatialAWH", "SpatialWC","SpatialAWC","SpatialAccuracy".

Examples

data(sp_toys)
data <- sp_toys
getSpatialExternalMetrics(data$label, data$p1, data[,c("x", "y")], k=6, level="class")
#> Comparing between a fuzzy truth and a hard prediction...
#> Standard error of the mean NDC across permutations:0.00228
#>   SpatialWH SpatialAWH SpatialWC SpatialAWC class cluster
#> 1        NA         NA 0.8078698   0.589422     1      NA
#> 2        NA         NA 1.0000000   1.000000     2      NA
#> 3 1.0000000  1.0000000        NA         NA    NA       1
#> 4 0.8323893  0.6494766        NA         NA    NA       2