#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
)
#these matrices have attributes tracing how they were generated
lapply(
X = distantia_matrix,
FUN = \(x) attributes(x)$distantia_args
)
#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]]
)
}
Run the code above in your browser using DataLab