similarity_matrix: Get the similarity matrix of an area

Description Usage Arguments Value Author(s) References Examples

View source: R/similarity_matrix.R

Description

Calculates the Jaccard similarity index and Sorensen similarity index.

Usage

1
2
3
4
5
6
7
8
9
similarity_matrix(
  df,
  species,
  comparison,
  NI_label = "",
  index = "Sorensen",
  dendrogram = FALSE,
  n_groups = 3
)

Arguments

df

A data frame.

species

Quoted name of the scientific names variable, or any variable used to differentiate the different species found in data. If supplied, will be used to classify the species in the diameter data.

comparison

Quoted name of the variable containing levels to be compared with each other.

NI_label

Label used for Species not identified. This parameter works along with species. The level supplied here will not be considered in the classification. Default "".

index

Character value for the desired index to be used. Can be either "Jaccard", for a matrix based on the Jaccard index of similarity, "Sorensen", for a matrix based the Sorensen index of similarity, or "all", for a list with matrices for both indexes. Default: "Sorensen".

dendrogram

If TRUE, a dendrogram will also be created. Default: FALSE.

n_groups

Number of groups in the dendrogram. Default 3.

Value

a matrix object with a similarity matrix, or a list, according to the "index" and "dendrogram" arguments.

Author(s)

Eric Bastos Gorgens e.gorgens@gmail.com

References

Souza, A. L. and Soares, C. P. B. (2013) Florestas Nativas: estrutura, dinamica e manejo. Vicosa: UFV.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
library(forestmangr)
data("exfm20")
head(exfm20)

# To get the similarity matrix of an area, we simply need to provide
# the species variable name, and a subdivision variable name, like
# transect. By default we get a a matrix based on the Sorensen index:
similarity_matrix(exfm20, "scientific.name", "transect")

# To get the similarity matrix of Jaccard, use the index argument:
similarity_matrix(exfm20, "scientific.name", "transect", index = "Jaccard")

# To get a dendrogram with the matrix, use dendrogram=TRUE:
similarity_matrix(exfm20, "scientific.name", "transect", index = "Jaccard", dendrogram = TRUE)

# To get a list with both matrices, use index="all":
similarity_matrix(exfm20, "scientific.name", "transect", index = "all")

# If the data supplied only has 2 levels, a paired comparison is made instead:
ex_pair <- exfm20[exfm20$transect %in% c("T01", "T02") , ]
ex_pair

similarity_matrix(ex_pair, "scientific.name", "transect", index = "all")

forestmangr documentation built on Aug. 16, 2021, 5:08 p.m.