Convert Dissimilarity Analysis Data Frame to Distance Matrix
Source:R/distantia_matrix.R
distantia_matrix.Rd
Transforms a data frame resulting from distantia()
into a dissimilarity matrix.
Arguments
- df
(required, data frame) Output of
distantia()
ordistantia_aggregate()
. Default: NULL
See also
Other dissimilarity_analysis:
distantia_aggregate()
,
distantia_boxplot()
,
distantia_cluster_hclust()
,
distantia_cluster_kmeans()
,
distantia_plot()
,
distantia_to_sf()
Examples
#weekly covid prevalence in three California counties
#load as tsl
#subset 5 counties
#sum by month
tsl <- tsl_initialize(
x = covid_prevalence,
name_column = "name",
time_column = "time"
) |>
tsl_subset(
names = 1:5
) |>
tsl_aggregate(
new_time = "months",
method = sum
)
if(interactive()){
#plotting first three time series
tsl_plot(
tsl = tsl,
guide_columns = 3
)
dev.off()
}
#dissimilarity analysis
#two combinations of arguments
distantia_df <- distantia(
tsl = tsl,
lock_step = c(TRUE, FALSE)
)
#to dissimilarity matrix
distantia_matrix <- distantia_matrix(
df = distantia_df
)
#returns a list of matrices
lapply(
X = distantia_matrix,
FUN = class
)
#> $`1`
#> [1] "matrix" "array"
#>
#> $`2`
#> [1] "matrix" "array"
#>
#these matrices have attributes tracing how they were generated
lapply(
X = distantia_matrix,
FUN = \(x) attributes(x)$distantia_args
)
#> $`1`
#> distance diagonal weighted ignore_blocks lock_step group
#> 11 euclidean TRUE TRUE FALSE TRUE 1
#>
#> $`2`
#> distance diagonal weighted ignore_blocks lock_step group
#> 1 euclidean TRUE TRUE FALSE FALSE 2
#>
#plot matrix
if(interactive()){
#plot first matrix (default behavior of utils_matrix_plot())
utils_matrix_plot(
m = distantia_matrix
)
#plot second matrix
utils_matrix_plot(
m = distantia_matrix[[2]]
)
}