├── .Rbuildignore ├── .github ├── .gitignore └── workflows │ ├── R-CMD-check.yaml │ ├── pkgdown.yaml │ └── rhub.yaml ├── .gitignore ├── CRAN-RELEASE ├── DESCRIPTION ├── LICENSE ├── LICENSE.md ├── NAMESPACE ├── NEWS.md ├── R ├── RcppExports.R ├── color_continuous.R ├── color_discrete.R ├── data.R ├── distance.R ├── distance_matrix.R ├── distantia-package.R ├── distantia.R ├── distantia_aggregate.R ├── distantia_boxplot.R ├── distantia_cluster_hclust.R ├── distantia_cluster_kmeans.R ├── distantia_dtw.R ├── distantia_dtw_plot.R ├── distantia_ls.R ├── distantia_matrix.R ├── distantia_model_frame.R ├── distantia_spatial.R ├── distantia_stats.R ├── distantia_time_delay.R ├── globals.R ├── momentum.R ├── momentum_aggregate.R ├── momentum_boxplot.R ├── momentum_dtw.R ├── momentum_ls.R ├── momentum_model_frame.R ├── momentum_spatial.R ├── momentum_stats.R ├── momentum_to_wide.R ├── psi_auto_distance.R ├── psi_auto_sum.R ├── psi_cost_matrix.R ├── psi_cost_path.R ├── psi_cost_path_sum.R ├── psi_distance_lock_step.R ├── psi_distance_matrix.R ├── psi_equation.R ├── transformations.R ├── tsl_aggregate.R ├── tsl_burst.R ├── tsl_colnames.R ├── tsl_count_NA.R ├── tsl_diagnose.R ├── tsl_handle_NA.R ├── tsl_initialize.R ├── tsl_join.R ├── tsl_names.R ├── tsl_ncol.R ├── tsl_nrow.R ├── tsl_plot.R ├── tsl_repair.R ├── tsl_resample.R ├── tsl_simulate.R ├── tsl_smooth.R ├── tsl_stats.R ├── tsl_subset.R ├── tsl_time.R ├── tsl_to_df.R ├── tsl_transform.R ├── utils_as_time.R ├── utils_block_size.R ├── utils_boxplot_common.R ├── utils_check_args.R ├── utils_check_list_class.R ├── utils_clean_names.R ├── utils_cluster_hclust_optimizer.R ├── utils_cluster_kmeans_optimizer.R ├── utils_cluster_silhouette.R ├── utils_coerce_time_class.R ├── utils_color_breaks.R ├── utils_digits.R ├── utils_distantia_df_split.R ├── utils_drop_geometry.R ├── utils_global_scaling_params.R ├── utils_is_time.R ├── utils_line_color.R ├── utils_line_guide.R ├── utils_matrix_guide.R ├── utils_matrix_plot.R ├── utils_new_time.R ├── utils_optimize_loess.R ├── utils_optimize_spline.R ├── utils_prepare_df.R ├── utils_prepare_matrix.R ├── utils_prepare_matrix_list.R ├── utils_prepare_time.R ├── utils_prepare_vector_list.R ├── utils_prepare_zoo_list.R ├── utils_rescale_vector.R ├── utils_time_keywords.R ├── utils_time_keywords_dictionary.R ├── utils_time_keywords_translate.R ├── utils_time_units.R ├── utils_tsl_pairs.R ├── zoo_aggregate.R ├── zoo_names.R ├── zoo_permute.R ├── zoo_plot.R ├── zoo_resample.R ├── zoo_simulate.R ├── zoo_smooth_exponential.R ├── zoo_smooth_window.R ├── zoo_time.R ├── zoo_to_tsl.R ├── zoo_vector_to_matrix.R └── zzz.R ├── README.Rmd ├── README.md ├── _pkgdown.yml ├── cran-comments.md ├── data ├── albatross.rda ├── cities_coordinates.rda ├── cities_temperature.rda ├── covid_counties.rda ├── covid_prevalence.rda ├── distances.rda ├── eemian_coordinates.rda ├── eemian_pollen.rda ├── fagus_coordinates.rda ├── fagus_dynamics.rda ├── honeycomb_climate.rda └── honeycomb_polygons.rda ├── data_full ├── albatross.rda ├── california.csv ├── cities_coordinates.rda ├── cities_temperature.rda ├── covid_coordinates.rda ├── covid_polygons.rda ├── covid_prevalence.rda ├── honeycomb_climate.rda ├── honeycomb_distantia.RData ├── honeycomb_polygons.rda └── waxwings │ ├── XC449649 - Ampelis europeo - Bombycilla garrulus.mp3 │ ├── XC83651 - Ampelis europeo - Bombycilla garrulus.mp3 │ ├── files.txt │ └── processing.R ├── dev_scripts ├── albatross.R ├── albatross.csv ├── check_as_cran.sh ├── code_coverage.R ├── counties.R ├── create_test_files.R ├── data.R ├── debugging_orthogonal_dtw.R ├── dependencies_graph.R ├── distances.R ├── distantia_bluesky_demo.qmd ├── github_actions.R ├── install.R ├── linting.R ├── logo.R ├── logo.odp ├── predictors_and_honeycomb.R ├── rhub.R ├── roxyglobals.R └── valgrind.R ├── distantia.Rproj ├── inst ├── CITATION └── WORDLIST ├── man ├── albatross.Rd ├── auto_distance_cpp.Rd ├── auto_sum_cpp.Rd ├── auto_sum_full_cpp.Rd ├── auto_sum_path_cpp.Rd ├── cities_coordinates.Rd ├── cities_temperature.Rd ├── color_continuous.Rd ├── color_discrete.Rd ├── cost_matrix_diagonal_cpp.Rd ├── cost_matrix_diagonal_weighted_cpp.Rd ├── cost_matrix_orthogonal_cpp.Rd ├── cost_path_cpp.Rd ├── cost_path_diagonal_bandwidth_cpp.Rd ├── cost_path_diagonal_cpp.Rd ├── cost_path_orthogonal_bandwidth_cpp.Rd ├── cost_path_orthogonal_cpp.Rd ├── cost_path_slotting_cpp.Rd ├── cost_path_sum_cpp.Rd ├── cost_path_trim_cpp.Rd ├── covid_counties.Rd ├── covid_prevalence.Rd ├── distance.Rd ├── distance_bray_curtis_cpp.Rd ├── distance_canberra_cpp.Rd ├── distance_chebyshev_cpp.Rd ├── distance_chi_cpp.Rd ├── distance_cosine_cpp.Rd ├── distance_euclidean_cpp.Rd ├── distance_hamming_cpp.Rd ├── distance_hellinger_cpp.Rd ├── distance_jaccard_cpp.Rd ├── distance_ls_cpp.Rd ├── distance_manhattan_cpp.Rd ├── distance_matrix.Rd ├── distance_matrix_cpp.Rd ├── distance_russelrao_cpp.Rd ├── distance_sorensen_cpp.Rd ├── distances.Rd ├── distantia-package.Rd ├── distantia.Rd ├── distantia_aggregate.Rd ├── distantia_boxplot.Rd ├── distantia_cluster_hclust.Rd ├── distantia_cluster_kmeans.Rd ├── distantia_dtw.Rd ├── distantia_dtw_plot.Rd ├── distantia_ls.Rd ├── distantia_matrix.Rd ├── distantia_model_frame.Rd ├── distantia_spatial.Rd ├── distantia_stats.Rd ├── distantia_time_delay.Rd ├── eemian_coordinates.Rd ├── eemian_pollen.Rd ├── f_binary.Rd ├── f_clr.Rd ├── f_detrend_difference.Rd ├── f_detrend_linear.Rd ├── f_detrend_poly.Rd ├── f_hellinger.Rd ├── f_list.Rd ├── f_log.Rd ├── f_percent.Rd ├── f_proportion.Rd ├── f_proportion_sqrt.Rd ├── f_rescale_global.Rd ├── f_rescale_local.Rd ├── f_scale_global.Rd ├── f_scale_local.Rd ├── f_trend_linear.Rd ├── f_trend_poly.Rd ├── fagus_coordinates.Rd ├── fagus_dynamics.Rd ├── figures │ ├── README-unnamed-chunk-11-1.png │ ├── README-unnamed-chunk-12-1.png │ ├── README-unnamed-chunk-13-1.png │ ├── README-unnamed-chunk-4-1.png │ ├── README-unnamed-chunk-5-1.png │ ├── README-unnamed-chunk-6-1.png │ ├── README-unnamed-chunk-7-1.png │ ├── README-unnamed-chunk-8-1.png │ ├── README-unnamed-chunk-9-1.png │ └── logo.png ├── honeycomb_climate.Rd ├── honeycomb_polygons.Rd ├── importance_dtw_cpp.Rd ├── importance_dtw_legacy_cpp.Rd ├── importance_ls_cpp.Rd ├── momentum.Rd ├── momentum_aggregate.Rd ├── momentum_boxplot.Rd ├── momentum_dtw.Rd ├── momentum_ls.Rd ├── momentum_model_frame.Rd ├── momentum_spatial.Rd ├── momentum_stats.Rd ├── momentum_to_wide.Rd ├── permute_free_by_row_cpp.Rd ├── permute_free_cpp.Rd ├── permute_restricted_by_row_cpp.Rd ├── permute_restricted_cpp.Rd ├── psi_auto_distance.Rd ├── psi_auto_sum.Rd ├── psi_cost_matrix.Rd ├── psi_cost_path.Rd ├── psi_cost_path_sum.Rd ├── psi_distance_lock_step.Rd ├── psi_distance_matrix.Rd ├── psi_dtw_cpp.Rd ├── psi_equation.Rd ├── psi_equation_cpp.Rd ├── psi_ls_cpp.Rd ├── psi_null_dtw_cpp.Rd ├── psi_null_ls_cpp.Rd ├── subset_matrix_by_rows_cpp.Rd ├── tsl_aggregate.Rd ├── tsl_burst.Rd ├── tsl_colnames_clean.Rd ├── tsl_colnames_get.Rd ├── tsl_colnames_prefix.Rd ├── tsl_colnames_set.Rd ├── tsl_colnames_suffix.Rd ├── tsl_count_NA.Rd ├── tsl_diagnose.Rd ├── tsl_handle_NA.Rd ├── tsl_initialize.Rd ├── tsl_join.Rd ├── tsl_names_clean.Rd ├── tsl_names_get.Rd ├── tsl_names_set.Rd ├── tsl_names_test.Rd ├── tsl_ncol.Rd ├── tsl_nrow.Rd ├── tsl_plot.Rd ├── tsl_repair.Rd ├── tsl_resample.Rd ├── tsl_simulate.Rd ├── tsl_smooth.Rd ├── tsl_stats.Rd ├── tsl_subset.Rd ├── tsl_time.Rd ├── tsl_to_df.Rd ├── tsl_transform.Rd ├── utils_as_time.Rd ├── utils_block_size.Rd ├── utils_boxplot_common.Rd ├── utils_check_args_distantia.Rd ├── utils_check_args_matrix.Rd ├── utils_check_args_momentum.Rd ├── utils_check_args_path.Rd ├── utils_check_args_tsl.Rd ├── utils_check_args_zoo.Rd ├── utils_check_distance_args.Rd ├── utils_check_list_class.Rd ├── utils_clean_names.Rd ├── utils_cluster_hclust_optimizer.Rd ├── utils_cluster_kmeans_optimizer.Rd ├── utils_cluster_silhouette.Rd ├── utils_coerce_time_class.Rd ├── utils_color_breaks.Rd ├── utils_digits.Rd ├── utils_distantia_df_split.Rd ├── utils_drop_geometry.Rd ├── utils_global_scaling_params.Rd ├── utils_is_time.Rd ├── utils_line_color.Rd ├── utils_line_guide.Rd ├── utils_matrix_guide.Rd ├── utils_matrix_plot.Rd ├── utils_new_time.Rd ├── utils_optimize_loess.Rd ├── utils_optimize_spline.Rd ├── utils_prepare_df.Rd ├── utils_prepare_matrix.Rd ├── utils_prepare_matrix_list.Rd ├── utils_prepare_time.Rd ├── utils_prepare_vector_list.Rd ├── utils_prepare_zoo_list.Rd ├── utils_rescale_vector.Rd ├── utils_time_keywords.Rd ├── utils_time_keywords_dictionary.Rd ├── utils_time_keywords_translate.Rd ├── utils_time_units.Rd ├── utils_tsl_pairs.Rd ├── zoo_aggregate.Rd ├── zoo_name_clean.Rd ├── zoo_name_get.Rd ├── zoo_name_set.Rd ├── zoo_permute.Rd ├── zoo_plot.Rd ├── zoo_resample.Rd ├── zoo_simulate.Rd ├── zoo_smooth_exponential.Rd ├── zoo_smooth_window.Rd ├── zoo_time.Rd ├── zoo_to_tsl.Rd └── zoo_vector_to_matrix.Rd ├── pkgdown ├── extra.css └── favicon │ ├── apple-touch-icon.png │ ├── favicon-96x96.png │ ├── favicon.ico │ ├── favicon.svg │ ├── site.webmanifest │ ├── web-app-manifest-192x192.png │ └── web-app-manifest-512x512.png ├── src ├── .gitignore ├── RcppExports.cpp ├── RcppExports.o ├── auto_sum.cpp ├── auto_sum.h ├── auto_sum.o ├── cost_matrix.cpp ├── cost_matrix.h ├── cost_matrix.o ├── cost_path.cpp ├── cost_path.h ├── cost_path.o ├── distance_matrix.cpp ├── distance_matrix.h ├── distance_matrix.o ├── distance_methods.cpp ├── distance_methods.h ├── distance_methods.o ├── distantia.so ├── importance.cpp ├── importance.h ├── importance.o ├── permute.cpp ├── permute.h ├── permute.o ├── psi.cpp ├── psi.h └── psi.o ├── tests ├── spelling.R ├── testthat.R └── testthat │ ├── test-distance.R │ ├── test-distance_matrix.R │ ├── test-distantia.R │ ├── test-distantia_cluster_hclust.R │ ├── test-distantia_cluster_kmeans.R │ ├── test-distantia_model_frame.R │ ├── test-distantia_spatial.R │ ├── test-distantia_time_shift.R │ ├── test-momentum.R │ ├── test-psi_equation.R │ ├── test-tsl_aggregate.R │ ├── test-tsl_burst.R │ ├── test-tsl_colnames.R │ ├── test-tsl_count_NA.R │ ├── test-tsl_diagnose.R │ ├── test-tsl_handle_NA.R │ ├── test-tsl_initialize.R │ ├── test-tsl_join.R │ ├── test-tsl_names.R │ ├── test-tsl_ncol.R │ ├── test-tsl_repair.R │ ├── test-tsl_resample.R │ ├── test-tsl_smooth.R │ ├── test-tsl_stats.R │ ├── test-tsl_subset.R │ ├── test-tsl_time.R │ ├── test-tsl_to_df.R │ ├── test-tsl_transform.R │ ├── test-utils_as_time.R │ ├── test-utils_clean_names.R │ ├── test-utils_cluster.R │ ├── test-utils_coerce_time_class.R │ ├── test-utils_digits.R │ ├── test-utils_distantia_df_split.R │ ├── test-utils_is_time.R │ ├── test-utils_new_time.R │ ├── test-utils_optimize_loess.R │ ├── test-utils_optimize_spline.R │ ├── test-utils_prepare_zoo_list.R │ ├── test-utils_rescale_vector.R │ ├── test-utils_time_keywords.R │ ├── test-utils_time_keywords_dictionary.R │ ├── test-utils_time_keywords_translate.R │ ├── test-utils_time_units.R │ ├── test-zoo_aggregate.R │ ├── test-zoo_names.R │ ├── test-zoo_permute.R │ ├── test-zoo_resample.R │ ├── test-zoo_simulate.R │ ├── test-zoo_smooth.R │ ├── test-zoo_time.R │ ├── test-zoo_to_tsl.R │ └── test-zoo_vector_to_matrix.R └── vignettes └── articles ├── distantia_in_the_wild.Rmd ├── dtw_applications.Rmd ├── dynamic_time_warping_and_lock_step.Rmd ├── mapping_dissimilarity.Rmd └── time_series_lists.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^README\.Rmd$ 4 | ^docs$ 5 | ^cran-comments\.md$ 6 | ^CRAN-RELEASE$ 7 | ^dev_scripts/ 8 | ^TODO.md$ 9 | NEXT_DAY.md 10 | README_old.Rmd 11 | _pkgdown.yaml 12 | ^\.github$ 13 | ^vignettes/articles$ 14 | ^pkgdown$ 15 | ^_pkgdown\.yml$ 16 | data_full/ 17 | ^LICENSE\.md$ 18 | data_full/* 19 | dev_scripts/* 20 | vignettes/* 21 | man/figures/* 22 | bibliography/* 23 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [development, main] 6 | pull_request: 7 | branches: [development, development] 8 | 9 | name: R-CMD-check 10 | 11 | permissions: read-all 12 | 13 | jobs: 14 | R-CMD-check: 15 | runs-on: ${{ matrix.config.os }} 16 | 17 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 18 | 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | config: 23 | - {os: windows-latest, r: 'release'} 24 | - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} 25 | - {os: ubuntu-latest, r: 'release'} 26 | - {os: ubuntu-latest, r: 'oldrel-1'} 27 | 28 | env: 29 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 30 | R_KEEP_PKG_SOURCE: yes 31 | 32 | steps: 33 | - uses: actions/checkout@v4 34 | 35 | - uses: r-lib/actions/setup-pandoc@v2 36 | 37 | - uses: r-lib/actions/setup-r@v2 38 | with: 39 | r-version: ${{ matrix.config.r }} 40 | http-user-agent: ${{ matrix.config.http-user-agent }} 41 | use-public-rspm: true 42 | 43 | - uses: r-lib/actions/setup-r-dependencies@v2 44 | with: 45 | extra-packages: any::rcmdcheck 46 | needs: check 47 | 48 | - uses: r-lib/actions/check-r-package@v2 49 | with: 50 | upload-snapshots: true 51 | build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")' 52 | -------------------------------------------------------------------------------- /.github/workflows/pkgdown.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | release: 8 | types: [published] 9 | workflow_dispatch: 10 | 11 | name: pkgdown.yaml 12 | 13 | permissions: read-all 14 | 15 | jobs: 16 | pkgdown: 17 | runs-on: ubuntu-latest 18 | # Only restrict concurrency for non-PR jobs 19 | concurrency: 20 | group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} 21 | env: 22 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 23 | permissions: 24 | contents: write 25 | steps: 26 | - uses: actions/checkout@v4 27 | 28 | - uses: r-lib/actions/setup-pandoc@v2 29 | 30 | - uses: r-lib/actions/setup-r@v2 31 | with: 32 | use-public-rspm: true 33 | 34 | - uses: r-lib/actions/setup-r-dependencies@v2 35 | with: 36 | extra-packages: any::pkgdown, local::. 37 | needs: website 38 | 39 | - name: Build site 40 | run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) 41 | shell: Rscript {0} 42 | 43 | - name: Deploy to GitHub pages 🚀 44 | if: github.event_name != 'pull_request' 45 | uses: JamesIves/github-pages-deploy-action@v4.5.0 46 | with: 47 | clean: false 48 | branch: gh-pages 49 | folder: docs 50 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # History files 2 | .Rhistory 3 | .Rapp.history 4 | 5 | # Session Data files 6 | .RData 7 | .RDataTmp 8 | 9 | # User-specific files 10 | .Ruserdata 11 | 12 | # Example code in package build process 13 | *-Ex.R 14 | 15 | # Output files from R CMD build 16 | /*.tar.gz 17 | 18 | # Output files from R CMD check 19 | /*.Rcheck/ 20 | 21 | # RStudio files 22 | .Rproj.user/ 23 | 24 | # produced vignettes 25 | vignettes/*.html 26 | vignettes/*.pdf 27 | 28 | # OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 29 | .httr-oauth 30 | 31 | # knitr and R markdown default cache directories 32 | *_cache/ 33 | /cache/ 34 | 35 | # Temporary files created by R markdown 36 | *.utf8.md 37 | *.knit.md 38 | 39 | # R Environment Variables 40 | .Renviron 41 | 42 | # pkgdown site 43 | docs/ 44 | 45 | # translation temp files 46 | po/*~ 47 | src/*.o 48 | src/distantia.so 49 | # RStudio Connect folder 50 | rsconnect/ 51 | .Rproj.user 52 | docs 53 | data_full/cru_time_series.R 54 | bibliography/* 55 | -------------------------------------------------------------------------------- /CRAN-RELEASE: -------------------------------------------------------------------------------- 1 | This package was submitted to CRAN on 2019-10-28. 2 | Once it is accepted, delete this file and tag the release (commit 78d854beb1). 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2024 2 | COPYRIGHT HOLDER: Blas M. Benito 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2024 Blas M. Benito 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /R/color_continuous.R: -------------------------------------------------------------------------------- 1 | #' Default Continuous Color Palette 2 | #' 3 | #' @description 4 | #' Uses the function [grDevices::hcl.colors()] to generate a continuous color palette. 5 | #' 6 | #' 7 | #' @param n (required, integer) number of colors to generate. Default = NULL 8 | #' @param palette (required, character string) Argument `palette` of [grDevices::hcl.colors()]. Default: "Zissou 1" 9 | #' @param rev (optional, logical) If TRUE, the color palette is reversed. Default: FALSE 10 | #' @return color vector 11 | #' @export 12 | #' @autoglobal 13 | #' @examples 14 | #' 15 | #' color_continuous(n = 20) 16 | #' 17 | #' @family internal_plotting 18 | color_continuous <- function( 19 | n = 5, 20 | palette = "Zissou 1", 21 | rev = FALSE 22 | ){ 23 | 24 | grDevices::hcl.colors( 25 | n = n, 26 | palette = palette, 27 | rev = rev 28 | ) 29 | 30 | } 31 | -------------------------------------------------------------------------------- /R/color_discrete.R: -------------------------------------------------------------------------------- 1 | #' Default Discrete Color Palettes 2 | #' 3 | #' @description 4 | #' Uses the function [grDevices::palette.colors()] to generate discrete color palettes using the following rules: 5 | #' \itemize{ 6 | #' \item `n <= 9`: "Okabe-Ito". 7 | #' \item `n == 10`: "Tableau 10" 8 | #' \item `n > 10 && n <= 12`: "Paired" 9 | #' \item `n > 12 && n <= 26`: "Alphabet" 10 | #' \item `n > 26 && n <= 36`: "Polychrome 36" 11 | #' } 12 | #' 13 | #' 14 | #' @inheritParams color_continuous 15 | #' 16 | #' @return color vector 17 | #' @export 18 | #' @autoglobal 19 | #' @examples 20 | #' 21 | #' color_discrete(n = 9) 22 | #' @family internal_plotting 23 | color_discrete <- function( 24 | n = NULL, 25 | rev = FALSE 26 | ){ 27 | 28 | if(n == 1){ 29 | return("#C8443F") 30 | } 31 | if(n <= 9 && n > 1){ 32 | pal <- "Okabe-Ito" 33 | } 34 | if(n == 10){ 35 | pal <- "Tableau 10" 36 | } 37 | if(n > 10 && n <= 12){ 38 | pal <- "Paired" 39 | } 40 | if(n > 12 && n <= 26){ 41 | pal <- "Alphabet" 42 | } 43 | if(n > 26 && n <= 36){ 44 | pal <- "Polychrome 36" 45 | } 46 | if(n > 36){ 47 | return( 48 | color_continuous( 49 | n = n, 50 | rev = rev 51 | ) 52 | ) 53 | } 54 | 55 | out <- grDevices::palette.colors( 56 | n = n, 57 | palette = pal 58 | ) 59 | 60 | if(rev){ 61 | out <- rev(out) 62 | } 63 | 64 | out 65 | 66 | } 67 | -------------------------------------------------------------------------------- /R/distantia-package.R: -------------------------------------------------------------------------------- 1 | #' @title distantia: A Toolset for Time Series Dissimilarity Analysis 2 | #' 3 | #' @description 4 | #' Fast C++ implementation of Dynamic Time Warping for time series dissimilarity analysis, with applications in environmental monitoring and sensor data analysis, climate science, signal processing and pattern recognition, and financial data analysis. Built upon the ideas presented in Benito and Birks (2020) , provides tools for analyzing time series of varying lengths and structures, including irregular multivariate time series. Key features include individual variable contribution analysis, restricted permutation tests for statistical significance, and imputation of missing data via GAMs. Additionally, the package provides an ample set of tools to prepare and manage time series data. 5 | #' 6 | #' @docType package 7 | #' @author Blas Benito 8 | #' @keywords internal 9 | #' @importFrom Rcpp evalCpp 10 | #' @useDynLib distantia 11 | #' @name distantia-package 12 | "_PACKAGE" 13 | -------------------------------------------------------------------------------- /R/globals.R: -------------------------------------------------------------------------------- 1 | # Generated by roxyglobals: do not edit by hand 2 | 3 | utils::globalVariables(c( 4 | "distances", # 5 | "i", # 6 | "median", # 7 | "i", # 8 | "i", # 9 | "sd", # 10 | "sd", # 11 | "i", # 12 | "i", # 13 | "i", # 14 | "median", # 15 | "i", # 16 | "i", # 17 | "sd", # 18 | "sd", # 19 | "i", # 20 | "i", # 21 | "i", # 22 | "na.omit", # 23 | "median", # 24 | "distances", # 25 | "i", # 26 | "i", # 27 | "i", # 28 | "i", # 29 | NULL 30 | )) 31 | -------------------------------------------------------------------------------- /R/psi_auto_distance.R: -------------------------------------------------------------------------------- 1 | #' Cumulative Sum of Distances Between Consecutive Cases in a Time Series 2 | #' 3 | #' @description 4 | #' Demonstration function to compute the sum of distances between consecutive cases in a time series. 5 | #' 6 | #' @param x (required, zoo object or matrix) univariate or multivariate time series with no NAs. Default: NULL 7 | #' @inheritParams distantia 8 | #' 9 | #' @return numeric value 10 | #' @export 11 | #' @autoglobal 12 | #' @examples 13 | #' #distance metric 14 | #' d <- "euclidean" 15 | #' 16 | #' #simulate zoo time series 17 | #' x <- zoo_simulate( 18 | #' name = "x", 19 | #' rows = 100, 20 | #' seasons = 2, 21 | #' seed = 1 22 | #' ) 23 | #' 24 | #' #sum distance between consecutive samples 25 | #' psi_auto_distance( 26 | #' x = x, 27 | #' distance = d 28 | #' ) 29 | #' @family psi_demo 30 | psi_auto_distance <- function( 31 | x = NULL, 32 | distance = "euclidean" 33 | ){ 34 | 35 | #check x 36 | x <- utils_check_args_zoo( 37 | x = x, 38 | arg_name = "x" 39 | ) 40 | 41 | #check distance 42 | distance <- utils_check_distance_args( 43 | distance = distance 44 | )[1] 45 | 46 | #auto sum 47 | x.auto_distance <- auto_distance_cpp( 48 | x = x, 49 | distance = distance 50 | ) 51 | 52 | x.auto_distance 53 | 54 | } 55 | -------------------------------------------------------------------------------- /R/psi_cost_path_sum.R: -------------------------------------------------------------------------------- 1 | #' Sum of Distances in Least Cost Path 2 | #' 3 | #' @description 4 | #' Demonstration function to sum the distances of a least cost path. 5 | #' 6 | #' 7 | #' @param path (required, data frame) least cost path produced by [psi_cost_path()]. Default: NULL 8 | #' @return numeric value 9 | #' @examples 10 | #' #distance metric 11 | #' d <- "euclidean" 12 | #' 13 | #' #simulate two irregular time series 14 | #' x <- zoo_simulate( 15 | #' name = "x", 16 | #' rows = 100, 17 | #' seasons = 2, 18 | #' seed = 1 19 | #' ) 20 | #' 21 | #' y <- zoo_simulate( 22 | #' name = "y", 23 | #' rows = 80, 24 | #' seasons = 2, 25 | #' seed = 2 26 | #' ) 27 | #' 28 | #' if(interactive()){ 29 | #' zoo_plot(x = x) 30 | #' zoo_plot(x = y) 31 | #' } 32 | #' 33 | #' #distance matrix 34 | #' dist_matrix <- psi_distance_matrix( 35 | #' x = x, 36 | #' y = y, 37 | #' distance = d 38 | #' ) 39 | #' 40 | #' #orthogonal least cost matrix 41 | #' cost_matrix <- psi_cost_matrix( 42 | #' dist_matrix = dist_matrix 43 | #' ) 44 | #' 45 | #' #orthogonal least cost path 46 | #' cost_path <- psi_cost_path( 47 | #' dist_matrix = dist_matrix, 48 | #' cost_matrix = cost_matrix 49 | #' ) 50 | #' 51 | #' #sum of distances in cost path 52 | #' psi_cost_path_sum( 53 | #' path = cost_path 54 | #' ) 55 | #' @autoglobal 56 | #' @export 57 | #' @family psi_demo 58 | psi_cost_path_sum <- function(path = NULL){ 59 | 60 | path <- utils_check_args_path( 61 | path = path 62 | ) 63 | 64 | cost_path_sum_cpp( 65 | path = path 66 | ) 67 | 68 | } 69 | -------------------------------------------------------------------------------- /R/psi_distance_lock_step.R: -------------------------------------------------------------------------------- 1 | #' Lock-Step Distance 2 | #' 3 | #' @description 4 | #' Demonstration function to compute the lock-step distance between two univariate or multivariate time series. 5 | #' 6 | #' This function does not accept NA data in the matrices `x` and `y`. 7 | #' 8 | #' @param x (required, zoo object or numeric matrix) a time series with no NAs. Default: NULL 9 | #' @param y (zoo object or numeric matrix) a time series with the same columns as `x` and no NAs. Default: NULL 10 | #' @inheritParams distantia 11 | #' @examples 12 | #' #distance metric 13 | #' d <- "euclidean" 14 | #' 15 | #' #simulate two time series 16 | #' #of the same length 17 | #' x <- zoo_simulate( 18 | #' name = "x", 19 | #' rows = 100, 20 | #' seasons = 2, 21 | #' seed = 1 22 | #' ) 23 | #' 24 | #' y <- zoo_simulate( 25 | #' name = "y", 26 | #' rows = 100, 27 | #' seasons = 2, 28 | #' seed = 2 29 | #' ) 30 | #' 31 | #' if(interactive()){ 32 | #' zoo_plot(x = x) 33 | #' zoo_plot(x = y) 34 | #' } 35 | #' 36 | #' #sum of distances 37 | #' #between pairs of samples 38 | #' psi_distance_lock_step( 39 | #' x = x, 40 | #' y = y, 41 | #' distance = d 42 | #' ) 43 | #' @return numeric 44 | #' @export 45 | #' @autoglobal 46 | #' @family psi_demo 47 | psi_distance_lock_step <- function( 48 | x = NULL, 49 | y = NULL, 50 | distance = "euclidean" 51 | ){ 52 | 53 | distance <- utils_check_distance_args( 54 | distance = distance 55 | )[1] 56 | 57 | d <- distance_ls_cpp( 58 | x, 59 | y, 60 | distance 61 | ) 62 | 63 | d 64 | 65 | } 66 | -------------------------------------------------------------------------------- /R/tsl_count_NA.R: -------------------------------------------------------------------------------- 1 | #' Count NA Cases in Time Series Lists 2 | #' 3 | #' @description 4 | #' Converts Inf, -Inf, and NaN to NA (via [tsl_Inf_to_NA()] and [tsl_NaN_to_NA()]), and counts the total number of NA cases in each time series. 5 | #' 6 | #' 7 | #' @param tsl (required, list) Time series list. Default: NULL 8 | #' 9 | #' @return list 10 | #' @export 11 | #' @autoglobal 12 | #' @examples 13 | #' #tsl with no NA cases 14 | #' tsl <- tsl_simulate() 15 | #' 16 | #' tsl_count_NA(tsl = tsl) 17 | #' 18 | #' #tsl with NA cases 19 | #' tsl <- tsl_simulate( 20 | #' na_fraction = 0.3 21 | #' ) 22 | #' 23 | #' tsl_count_NA(tsl = tsl) 24 | #' 25 | #' #tsl with variety of empty cases 26 | #' tsl <- tsl_simulate() 27 | #' tsl[[1]][1, 1] <- Inf 28 | #' tsl[[1]][2, 1] <- -Inf 29 | #' tsl[[1]][3, 1] <- NaN 30 | #' tsl[[1]][4, 1] <- NaN 31 | #' 32 | #' tsl_count_NA(tsl = tsl) 33 | #' 34 | #' @family tsl_management 35 | tsl_count_NA <- function( 36 | tsl = NULL 37 | ){ 38 | 39 | utils_check_args_tsl( 40 | tsl = tsl, 41 | min_length = 1 42 | ) 43 | 44 | #replaces Inf with Na 45 | tsl <- tsl_Inf_to_NA( 46 | tsl = tsl 47 | ) 48 | 49 | #replaces NaN with NA 50 | tsl <- tsl_NaN_to_NA( 51 | tsl = tsl 52 | ) 53 | 54 | na_count_list <- future.apply::future_lapply( 55 | X = tsl, 56 | FUN = function(x){ 57 | sum(is.na(x)) 58 | } 59 | ) 60 | 61 | 62 | na_count_list 63 | 64 | } 65 | -------------------------------------------------------------------------------- /R/tsl_ncol.R: -------------------------------------------------------------------------------- 1 | #' Get Number of Columns in Time Series Lists 2 | #' 3 | #' @param tsl (required, list) Time series list. Default: NULL 4 | #' 5 | #' @return list 6 | #' @export 7 | #' @examples 8 | #' #initialize time series list 9 | #' tsl <- tsl_simulate( 10 | #' n = 2, 11 | #' cols = 6 12 | #' ) 13 | #' 14 | #' #number of columns per zoo object 15 | #' tsl_ncol(tsl = tsl) 16 | #' @autoglobal 17 | #' @family tsl_management 18 | tsl_ncol <- function( 19 | tsl = NULL 20 | ){ 21 | 22 | utils_check_args_tsl( 23 | tsl = tsl, 24 | min_length = 1 25 | ) 26 | 27 | lapply( 28 | X = tsl, 29 | FUN = function(x){ 30 | ncol(x) 31 | } 32 | ) 33 | 34 | } 35 | -------------------------------------------------------------------------------- /R/tsl_nrow.R: -------------------------------------------------------------------------------- 1 | #' Get Number of Rows in Time Series Lists 2 | #' 3 | #' @param tsl (required, list) Time series list. Default: NULL 4 | #' 5 | #' @return list 6 | #' @export 7 | #' @examples 8 | #' #simulate zoo time series 9 | #' tsl <- tsl_simulate( 10 | #' rows = 150 11 | #' ) 12 | #' 13 | #' #count rows 14 | #' tsl_nrow( 15 | #' tsl = tsl 16 | #' ) 17 | #' @autoglobal 18 | #' @family tsl_management 19 | tsl_nrow <- function( 20 | tsl = NULL 21 | ){ 22 | 23 | utils_check_args_tsl( 24 | tsl = tsl, 25 | min_length = 1 26 | ) 27 | 28 | lapply( 29 | X = tsl, 30 | FUN = function(x){ 31 | nrow(x) 32 | } 33 | ) 34 | 35 | } 36 | -------------------------------------------------------------------------------- /R/tsl_to_df.R: -------------------------------------------------------------------------------- 1 | #' Transform Time Series List to Data Frame 2 | #' 3 | #' @param tsl (required, list) Time series list. Default: NULL 4 | #' 5 | #' @return data frame 6 | #' @export 7 | #' @autoglobal 8 | #' @examples 9 | #' 10 | #' tsl <- tsl_simulate( 11 | #' n = 3, 12 | #' rows = 10, 13 | #' time_range = c( 14 | #' "2010-01-01", 15 | #' "2020-01-01" 16 | #' ), 17 | #' irregular = FALSE 18 | #' ) 19 | #' 20 | #' df <- tsl_to_df( 21 | #' tsl = tsl 22 | #' ) 23 | #' 24 | #' names(df) 25 | #' nrow(df) 26 | #' head(df) 27 | #' @family tsl_management 28 | tsl_to_df <- function( 29 | tsl = NULL 30 | ){ 31 | 32 | utils_check_args_tsl( 33 | tsl = tsl, 34 | min_length = 1 35 | ) 36 | 37 | df_list <- lapply( 38 | X = tsl, 39 | FUN = function(x){ 40 | 41 | data.frame( 42 | name = attributes(x)$name, 43 | time = zoo::index(x), 44 | as.data.frame(x) 45 | ) 46 | 47 | } 48 | 49 | ) 50 | 51 | df <- do.call( 52 | what = "rbind", 53 | args = df_list 54 | ) 55 | 56 | rownames(df) <- NULL 57 | 58 | df 59 | 60 | } 61 | -------------------------------------------------------------------------------- /R/utils_block_size.R: -------------------------------------------------------------------------------- 1 | #' Default Block Size for Restricted Permutation in Dissimilarity Analyses 2 | #' 3 | #' @param tsl (required, list) Time series list. Default: NULL 4 | #' @param block_size (optional, integer vector) Row block sizes for restricted permutation tests. Only relevant when permutation methods are "restricted" or "restricted_by_row". A block of size `n` indicates that a row can only be permuted within a block of `n` adjacent rows. If NULL, defaults to the 20% rows of the shortest time series in `tsl`. Minimum value is 2, and maximum value is 50% rows of the shortest time series in `tsl`. Default: NULL. 5 | #' 6 | #' @return integer 7 | #' @export 8 | #' @autoglobal 9 | #' @family distantia_support 10 | utils_block_size <- function( 11 | tsl = NULL, 12 | block_size = NULL 13 | ){ 14 | 15 | min_tsl_row <- tsl |> 16 | tsl_nrow() |> 17 | unlist() |> 18 | min() 19 | 20 | #default value 21 | default_block_size <- floor(min_tsl_row / 5) 22 | 23 | if(is.null(block_size)){ 24 | 25 | return(default_block_size) 26 | 27 | } 28 | 29 | block_size <- as.integer(block_size) 30 | 31 | if(any(!is.integer(block_size))){ 32 | 33 | return(default_block_size) 34 | 35 | } 36 | 37 | #remove extremes 38 | block_size <- block_size[ 39 | block_size >= 2 & 40 | block_size <= floor(min_tsl_row / 2) 41 | ] 42 | 43 | block_size 44 | 45 | } 46 | -------------------------------------------------------------------------------- /R/utils_check_list_class.R: -------------------------------------------------------------------------------- 1 | #' Checks Classes of List Elements Against Expectation 2 | #' 3 | #' @param x (required, list) Default: NULL 4 | #' @param expected_class (required, class name). One of "data.frame", "matrix", or "vector". Default: "data.frame". 5 | #' 6 | #' @return side effects 7 | #' @autoglobal 8 | #' @export 9 | #' @family internal 10 | utils_check_list_class <- function( 11 | x = NULL, 12 | expected_class = "data.frame" 13 | ){ 14 | 15 | if(inherits(x = x, what = "list") == FALSE){ 16 | stop("distantia::utils_check_list_class(): argument 'x' is not a list.", call. = FALSE) 17 | } 18 | 19 | expected_class <- match.arg( 20 | arg = expected_class, 21 | choices = c( 22 | "data.frame", 23 | "matrix", 24 | "vector" 25 | ), 26 | several.ok = FALSE 27 | ) 28 | 29 | 30 | if(expected_class != "vector"){ 31 | 32 | #check element class 33 | x.class <- lapply( 34 | X = x, 35 | FUN = class 36 | ) |> 37 | unlist() |> 38 | as.data.frame() 39 | 40 | } else { 41 | 42 | #check element class 43 | x.class <- lapply( 44 | X = x, 45 | FUN = function(x) 46 | if(is.vector(x)){ 47 | return("vector") 48 | } else { 49 | return(class(x)[1]) 50 | } 51 | ) |> 52 | unlist() |> 53 | as.data.frame() 54 | 55 | } 56 | 57 | colnames(x.class) <- "class" 58 | 59 | if(any(x.class$class %in% expected_class)){ 60 | 61 | return(TRUE) 62 | 63 | } else { 64 | 65 | return(FALSE) 66 | 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /R/utils_color_breaks.R: -------------------------------------------------------------------------------- 1 | #' Auto Breaks for Matrix Plotting Functions 2 | #' 3 | #' @param m (required, numeric matrix) distance or cost matrix generated by [psi_distance_matrix()] or [psi_cost_matrix()], but any numeric matrix will work. Default: NULL 4 | #' @param n (required, integer) number of colors to compute the breaks for. Default: 100 5 | #' 6 | #' @return numeric vector 7 | #' @autoglobal 8 | #' @export 9 | #' @family internal_plotting 10 | utils_color_breaks <- function( 11 | m = NULL, 12 | n = 100 13 | ){ 14 | 15 | m <- utils_check_args_matrix(m = m) 16 | 17 | m.range <- range(m, na.rm = TRUE) 18 | 19 | a <- seq( 20 | from = m.range[1], 21 | to = m.range[2], 22 | length.out = n 23 | ) 24 | 25 | b <- (a[2]- a[1])/2 26 | 27 | breaks <- c(a[1] - b, a + b) 28 | 29 | breaks 30 | 31 | } 32 | -------------------------------------------------------------------------------- /R/utils_digits.R: -------------------------------------------------------------------------------- 1 | #' Number of Decimal Places 2 | #' 3 | #' @param x (required, numeric) Default: NULL 4 | #' 5 | #' @return integer 6 | #' @export 7 | #' @autoglobal 8 | #' @examples 9 | #' utils_digits(x = 0.234) 10 | #' @family internal 11 | utils_digits <- function( 12 | x = NULL 13 | ){ 14 | 15 | out <- 0 16 | 17 | if(abs(x - round(x)) > .Machine$double.eps^0.5){ 18 | 19 | #remove terminal zeros 20 | x <- sub( 21 | pattern = '0+$', 22 | replacement = '', 23 | x = as.character(x) 24 | ) 25 | 26 | #number of decimals 27 | out <- nchar( 28 | x = strsplit( 29 | x = x, 30 | split = ".", 31 | fixed = TRUE 32 | )[[1]][[2]] 33 | ) 34 | 35 | } 36 | 37 | out 38 | 39 | } 40 | -------------------------------------------------------------------------------- /R/utils_drop_geometry.R: -------------------------------------------------------------------------------- 1 | #' Removes Geometry Column from SF Data Frames 2 | #' 3 | #' Replicates the functionality of `sf::st_drop_geometry()` without depending on the `sf` package. 4 | #' 5 | #'@param df (required, data frame) Input data frame. Default: NULL. 6 | #' 7 | #' @return data frame 8 | #' @autoglobal 9 | #' @export 10 | #' @family tsl_processing_internal 11 | utils_drop_geometry <- function( 12 | df = NULL 13 | ){ 14 | 15 | #remove geometry column from df 16 | sf.column <- attributes(df)$sf_column 17 | 18 | if(!is.null(sf.column)){ 19 | 20 | df <- as.data.frame(df) 21 | df[[sf.column]] <- NULL 22 | attr(df, "sf_column") <- NULL 23 | 24 | } 25 | 26 | df 27 | 28 | } 29 | -------------------------------------------------------------------------------- /R/utils_is_time.R: -------------------------------------------------------------------------------- 1 | #' Title 2 | #' 3 | #' @param x (required, vector) Vector to test. If the class of the vector elements is 'numeric', 'POSIXct', or 'Date', the function returns TRUE. Default: NULL. 4 | #' 5 | #' @return logical 6 | #' @export 7 | #' @autoglobal 8 | #' @examples 9 | #' 10 | #' utils_is_time( 11 | #' x = c("2024-01-01", "2024-02-01") 12 | #' ) 13 | #' 14 | #' utils_is_time( 15 | #' x = utils_as_time( 16 | #' x = c("2024-01-01", "2024-02-01") 17 | #' ) 18 | #' ) 19 | #' @family internal_time_handling 20 | utils_is_time <- function( 21 | x = NULL 22 | ){ 23 | 24 | x_class <- class(x) 25 | if("POSIXct" %in% x_class){ 26 | x_class <- "POSIXct" 27 | } 28 | 29 | #x is valid time class 30 | if(x_class %in% c( 31 | "integer", 32 | "numeric", 33 | "Date", 34 | "POSIXct" 35 | )){ 36 | return(TRUE) 37 | } 38 | 39 | FALSE 40 | 41 | } 42 | -------------------------------------------------------------------------------- /R/utils_prepare_matrix.R: -------------------------------------------------------------------------------- 1 | #' Convert Matrix to Data Frame 2 | #' 3 | #' @param x (required, matrix) Default: NULL 4 | #' 5 | #' @return A data frame 6 | #' @export 7 | #' @autoglobal 8 | #' @family internal 9 | utils_prepare_matrix <- function( 10 | x = NULL 11 | ){ 12 | 13 | if(inherits(x = x, what = "matrix") == FALSE){ 14 | return(x) 15 | } 16 | 17 | #coerce to numeric 18 | x.numeric <- apply( 19 | X = x, 20 | MARGIN = 2, 21 | FUN = as.numeric 22 | ) |> 23 | suppressWarnings() |> 24 | as.data.frame() 25 | 26 | #identify columns with all NA 27 | x.na.names <- apply( 28 | X = x.numeric, 29 | MARGIN = 2, 30 | FUN = function(x){ 31 | if(sum(is.na(x)) == length(x)){ 32 | return(TRUE) 33 | } else { 34 | FALSE 35 | } 36 | } 37 | ) 38 | 39 | x.na.names <- names(x.na.names[x.na.names == TRUE]) 40 | 41 | #convert x to data frame 42 | x <- as.data.frame(x) 43 | 44 | #add non numerics to x.numeric 45 | if(length(x.na.names) > 0){ 46 | for(i in x.na.names){ 47 | x.numeric[[i]] <- x[[i]] 48 | } 49 | } 50 | 51 | x.numeric 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /R/utils_prepare_matrix_list.R: -------------------------------------------------------------------------------- 1 | #' Convert List of Matrices to List of Data Frames 2 | #' 3 | #' @param x (required, list of matrices) Default: NULL 4 | #' 5 | #' @return List of Data Frames 6 | #' @export 7 | #' @autoglobal 8 | #' @family internal 9 | utils_prepare_matrix_list <- function( 10 | x = NULL 11 | ){ 12 | 13 | if( 14 | utils_check_list_class( 15 | x = x, 16 | expected_class = "matrix" 17 | ) == FALSE 18 | ){ 19 | 20 | return(x) 21 | 22 | } 23 | 24 | x <- lapply( 25 | X = x, 26 | FUN = function(x){ 27 | if(is.null(colnames(x))){ 28 | colnames(x) <- paste0("x", seq_len(ncol(x))) 29 | } 30 | x <- as.data.frame(x) 31 | 32 | return(x) 33 | } 34 | ) 35 | 36 | x 37 | 38 | } 39 | -------------------------------------------------------------------------------- /R/utils_prepare_vector_list.R: -------------------------------------------------------------------------------- 1 | #' Convert List of Vectors to List of Data Frames 2 | #' 3 | #' @param x (required, list of vectors) Default: NULL 4 | #' 5 | #' @return List of data frames 6 | #' @export 7 | #' @autoglobal 8 | #' @family internal 9 | utils_prepare_vector_list <- function( 10 | x = NULL 11 | ){ 12 | 13 | if( 14 | utils_check_list_class( 15 | x = x, 16 | expected_class = "vector" 17 | ) == FALSE 18 | ){ 19 | 20 | return(x) 21 | 22 | } 23 | 24 | x <- lapply( 25 | X = x, 26 | FUN = function(x){ 27 | data.frame( 28 | x = x 29 | ) 30 | } 31 | ) 32 | 33 | x 34 | 35 | 36 | } 37 | -------------------------------------------------------------------------------- /R/utils_rescale_vector.R: -------------------------------------------------------------------------------- 1 | #' Rescale Numeric Vector to a New Data Range 2 | #' @param x (required, numeric vector) Numeric vector. Default: `NULL` 3 | #' @param new_min (optional, numeric) New minimum value. Default: `0` 4 | #' @param new_max (optional_numeric) New maximum value. Default: `1` 5 | #' @param old_min (optional, numeric) Old minimum value. Default: `NULL` 6 | #' @param old_max (optional_numeric) Old maximum value. Default: `NULL` 7 | #' @return numeric vector 8 | #' @examples 9 | #' 10 | #' out <- utils_rescale_vector( 11 | #' x = stats::rnorm(100), 12 | #' new_min = 0, 13 | #' new_max = 100, 14 | #' ) 15 | #' 16 | #' out 17 | #' 18 | #' @export 19 | #' @autoglobal 20 | #' @family tsl_processing_internal 21 | utils_rescale_vector <- function( 22 | x = NULL, 23 | new_min = 0, 24 | new_max = 1, 25 | old_min = NULL, 26 | old_max = NULL 27 | ){ 28 | 29 | if(!is.vector(x) || !is.numeric(x)){ 30 | stop("distantia::utils_rescale_vector(): x must be a numeric vector.", call. = FALSE) 31 | } 32 | 33 | if(is.null(old_min)){ 34 | old_min <- min(x, na.rm = TRUE) 35 | } 36 | 37 | if(is.null(old_max)){ 38 | old_max <- max(x, na.rm = TRUE) 39 | } 40 | 41 | ((x - old_min) / (old_max - old_min)) * (new_max - new_min) + new_min 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /R/zoo_to_tsl.R: -------------------------------------------------------------------------------- 1 | #' Convert Individual Zoo Objects to Time Series List 2 | #' 3 | #' @description 4 | #' Internal function to wrap a zoo object into a time series list. 5 | #' 6 | #' @param x (required, zoo object) Time series. Default: NULL 7 | #' 8 | #' @return time series list of length one. 9 | #' @export 10 | #' @autoglobal 11 | #' @examples 12 | #' #create zoo object 13 | #' x <- zoo_simulate() 14 | #' class(x) 15 | #' 16 | #' #to time series list 17 | #' tsl <- zoo_to_tsl( 18 | #' x = x 19 | #' ) 20 | #' 21 | #' class(tsl) 22 | #' class(tsl[[1]]) 23 | #' names(tsl) 24 | #' attributes(tsl[[1]])$name 25 | #' @family zoo_functions 26 | zoo_to_tsl <- function( 27 | x = NULL 28 | ){ 29 | 30 | if(!zoo::is.zoo(x)){ 31 | stop("distantia::zoo_to_tsl(): argument 'x' must be a zoo time series.", call. = FALSE) 32 | } 33 | 34 | x_name <- attributes(x)$name 35 | if(is.null(x_name)){ 36 | x_name <- "" 37 | } 38 | 39 | x <- zoo_name_set( 40 | x = x, 41 | name = x_name 42 | ) 43 | 44 | out_tsl <- list(x) 45 | 46 | names(out_tsl) <- x_name 47 | 48 | out_tsl 49 | 50 | } 51 | -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | #' @useDynLib distantia, .registration = TRUE 2 | #' @importFrom Rcpp evalCpp 3 | NULL 4 | -------------------------------------------------------------------------------- /data/albatross.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/data/albatross.rda -------------------------------------------------------------------------------- /data/cities_coordinates.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/data/cities_coordinates.rda -------------------------------------------------------------------------------- /data/cities_temperature.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/data/cities_temperature.rda -------------------------------------------------------------------------------- /data/covid_counties.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/data/covid_counties.rda -------------------------------------------------------------------------------- /data/covid_prevalence.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/data/covid_prevalence.rda -------------------------------------------------------------------------------- /data/distances.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/data/distances.rda -------------------------------------------------------------------------------- /data/eemian_coordinates.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/data/eemian_coordinates.rda -------------------------------------------------------------------------------- /data/eemian_pollen.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/data/eemian_pollen.rda -------------------------------------------------------------------------------- /data/fagus_coordinates.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/data/fagus_coordinates.rda -------------------------------------------------------------------------------- /data/fagus_dynamics.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/data/fagus_dynamics.rda -------------------------------------------------------------------------------- /data/honeycomb_climate.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/data/honeycomb_climate.rda -------------------------------------------------------------------------------- /data/honeycomb_polygons.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/data/honeycomb_polygons.rda -------------------------------------------------------------------------------- /data_full/albatross.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/data_full/albatross.rda -------------------------------------------------------------------------------- /data_full/cities_coordinates.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/data_full/cities_coordinates.rda -------------------------------------------------------------------------------- /data_full/cities_temperature.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/data_full/cities_temperature.rda -------------------------------------------------------------------------------- /data_full/covid_coordinates.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/data_full/covid_coordinates.rda -------------------------------------------------------------------------------- /data_full/covid_polygons.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/data_full/covid_polygons.rda -------------------------------------------------------------------------------- /data_full/covid_prevalence.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/data_full/covid_prevalence.rda -------------------------------------------------------------------------------- /data_full/honeycomb_climate.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/data_full/honeycomb_climate.rda -------------------------------------------------------------------------------- /data_full/honeycomb_distantia.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/data_full/honeycomb_distantia.RData -------------------------------------------------------------------------------- /data_full/honeycomb_polygons.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/data_full/honeycomb_polygons.rda -------------------------------------------------------------------------------- /data_full/waxwings/XC449649 - Ampelis europeo - Bombycilla garrulus.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/data_full/waxwings/XC449649 - Ampelis europeo - Bombycilla garrulus.mp3 -------------------------------------------------------------------------------- /data_full/waxwings/XC83651 - Ampelis europeo - Bombycilla garrulus.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/data_full/waxwings/XC83651 - Ampelis europeo - Bombycilla garrulus.mp3 -------------------------------------------------------------------------------- /data_full/waxwings/files.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/data_full/waxwings/files.txt -------------------------------------------------------------------------------- /data_full/waxwings/processing.R: -------------------------------------------------------------------------------- 1 | install.packages("av") 2 | library(av) 3 | 4 | 5 | # https://ropensci.org/blog/2020/02/03/av-audio/ 6 | 7 | mp3 <- "data_full/waxwings/XC83651 - Ampelis europeo - Bombycilla garrulus.mp3" 8 | 9 | pcm_data <- read_audio_bin(wonderland, channels = 1, end_time = 2.0) 10 | 11 | 12 | mp3_to_zoo <- function(mp3 = NULL){ 13 | 14 | wave <- mp3 |> 15 | tuneR::readMP3() |> 16 | tuneR::normalize() 17 | 18 | spectrogram <- signal::specgram( 19 | x = wave@left, 20 | Fs = wave@samp.rate 21 | ) 22 | 23 | m <- abs(spectrogram$S) 24 | 25 | t <- spectrogram$t 26 | 27 | x <- zoo::zoo( 28 | x = m, 29 | order.by = t 30 | ) 31 | 32 | x <- distantia::zoo_name_set( 33 | x = x, 34 | name = "a" 35 | ) 36 | 37 | } 38 | 39 | 40 | 41 | # Step 4: Divide into bandwidths and create time series 42 | freqs <- spectrogram$freq # Frequency bins 43 | times <- spectrogram$time # Time bins 44 | amplitudes <- spectrogram$S # Spectrogram matrix 45 | 46 | # Define bandwidths (example: Low, Mid, High) 47 | low_band <- freqs[freqs < 500] 48 | mid_band <- freqs[freqs >= 500 & freqs < 2000] 49 | high_band <- freqs[freqs >= 2000] 50 | 51 | # Compute mean amplitude for each bandwidth over time 52 | low_amplitude <- rowMeans(amplitudes[freqs < 500, ]) 53 | mid_amplitude <- rowMeans(amplitudes[freqs >= 500 & freqs < 2000, ]) 54 | high_amplitude <- rowMeans(amplitudes[freqs >= 2000, ]) 55 | 56 | # Combine into a data frame 57 | time_series <- data.frame( 58 | time = times, 59 | low_band = low_amplitude, 60 | mid_band = mid_amplitude, 61 | high_band = high_amplitude 62 | ) 63 | 64 | # View time series 65 | head(time_series) 66 | -------------------------------------------------------------------------------- /dev_scripts/albatross.R: -------------------------------------------------------------------------------- 1 | download.file( 2 | url = "https://datarepository.movebank.org/bitstreams/72f33630-876d-44a1-92c8-7ff15e252162/download", 3 | destfile = "dev_scripts/albatross.csv" 4 | ) 5 | 6 | df <- data.table::fread("dev_scripts/albatross.csv") |> 7 | janitor::clean_names() 8 | 9 | albatross <- df |> 10 | dplyr::transmute( 11 | id = tag_local_identifier, 12 | time = timestamp, 13 | latitude = location_lat, 14 | longitude = location_long, 15 | speed = ground_speed, 16 | temperature = eobs_temperature, 17 | heading 18 | ) |> 19 | na.omit() |> 20 | #select individuals with ~1000 observations 21 | dplyr::filter( 22 | id %in% c(156, 136, 153, 132, 134) 23 | ) |> 24 | #filter anomalous speeds 25 | dplyr::filter( 26 | speed < quantile(x = speed, probs = 0.95) 27 | ) 28 | 29 | usethis::use_data(albatross, overwrite = TRUE) 30 | 31 | #load as tsl 32 | #scale al variables 33 | #aggregate to daily resolution 34 | tsl <- tsl_initialize( 35 | x = albatross, 36 | name_column = "name", 37 | time_column = "time" 38 | ) |> 39 | tsl_transform( 40 | f = f_scale_local 41 | ) |> 42 | tsl_aggregate( 43 | new_time = "days" 44 | ) 45 | 46 | if(interactive()){ 47 | tsl_plot( 48 | tsl = tsl, 49 | guide_columns = 5 50 | ) 51 | } 52 | 53 | 54 | distantia(tsl = tsl, lock_step = FALSE) 55 | 56 | tsl_time(tsl) 57 | -------------------------------------------------------------------------------- /dev_scripts/check_as_cran.sh: -------------------------------------------------------------------------------- 1 | export _R_CHECK_CRAN_INCOMING_=TRUE 2 | export _R_CHECK_FORCE_SUGGESTS_=TRUE 3 | export R_USE_VALGRIND=1 4 | export VALGRIND_OPTS="--leak-check=full --track-origins=yes" 5 | R CMD check --as-cran --use-valgrind /home/blas/Dropbox/GITHUB/R_packages/distantia_2.0.0.tar.gz 6 | -------------------------------------------------------------------------------- /dev_scripts/code_coverage.R: -------------------------------------------------------------------------------- 1 | library(covr) 2 | library(codetools) 3 | 4 | #distantia() 94.87 5 | covr::report( 6 | x = covr::file_coverage( 7 | source_files = c( 8 | "R/distantia.R", 9 | "R/distantia_ls.R", 10 | "R/distantia_dtw.R" 11 | ), 12 | test_files = "tests/testthat/test-distantia.R" 13 | ) 14 | ) 15 | 16 | #momentum() 85.77 17 | covr::report( 18 | x = covr::file_coverage( 19 | source_files = c( 20 | "R/momentum.R", 21 | "R/momentum_ls.R", 22 | "R/momentum_dtw.R" 23 | ), 24 | test_files = "tests/testthat/test-momentum.R" 25 | ) 26 | ) 27 | 28 | #run all tests with coverage 29 | covr::with_coverage( 30 | testthat::test_dir("path/to/test/directory"), 31 | covr::package_coverage() 32 | ) 33 | 34 | # get list of functions called by a particular function 35 | codetools::findGlobals(fun = distantia) 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /dev_scripts/create_test_files.R: -------------------------------------------------------------------------------- 1 | library(exampletestr) 2 | exampletestr::make_tests_shells_pkg() 3 | -------------------------------------------------------------------------------- /dev_scripts/dependencies_graph.R: -------------------------------------------------------------------------------- 1 | #function dependencies 2 | ######################################## 3 | devtools::install_github("datastorm-open/DependenciesGraphs") 4 | library(DependenciesGraphs) 5 | 6 | #full package 7 | dep <- DependenciesGraphs::envirDependencies('package:distantia') 8 | plot(dep) 9 | 10 | #a single function 11 | dep <- DependenciesGraphs::funDependencies( 12 | envir = 'package:distantia', 13 | name.function = "momentum" 14 | ) 15 | plot(dep) 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /dev_scripts/github_actions.R: -------------------------------------------------------------------------------- 1 | library(usethis) 2 | usethis::use_github_action("check-standard") 3 | usethis::use_github_action("pkgdown") 4 | -------------------------------------------------------------------------------- /dev_scripts/install.R: -------------------------------------------------------------------------------- 1 | library(Rcpp) 2 | library(devtools) 3 | 4 | Rcpp::compileAttributes() 5 | devtools::document() 6 | devtools::install() 7 | library(distantia) 8 | -------------------------------------------------------------------------------- /dev_scripts/linting.R: -------------------------------------------------------------------------------- 1 | # install.packages("lintr") 2 | library(lintr) 3 | lintr::use_lintr(type = "tidyverse") 4 | lintr::lint_package() 5 | -------------------------------------------------------------------------------- /dev_scripts/logo.R: -------------------------------------------------------------------------------- 1 | tsl <- tsl_simulate( 2 | n = 2, 3 | rows = 10 4 | ) 5 | 6 | m.dist <- psi_distance_matrix( 7 | x = tsl[[1]], 8 | y = tsl[[2]] 9 | ) 10 | 11 | m.cost <- psi_cost_matrix( 12 | dist_matrix = m.dist, 13 | diagonal = FALSE 14 | ) 15 | 16 | m.cost.path <- psi_cost_path( 17 | dist_matrix = m.dist, 18 | cost_matrix = m.cost, 19 | diagonal = FALSE 20 | ) 21 | 22 | utils_matrix_plot( 23 | m = m.cost, 24 | path = m.cost.path, 25 | path_width = 3, 26 | path_color = "gray30", 27 | diagonal = FALSE, 28 | guide = FALSE 29 | ) 30 | -------------------------------------------------------------------------------- /dev_scripts/logo.odp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/dev_scripts/logo.odp -------------------------------------------------------------------------------- /dev_scripts/rhub.R: -------------------------------------------------------------------------------- 1 | install.packages("rhub") 2 | Sys.setenv(GITHUB_PAT = "my_pat") 3 | rhub::rhub_setup() 4 | rhub::rhub_doctor() 5 | 6 | #full check 7 | rhub::rhub_check( 8 | platforms = c( 9 | "linux", 10 | "macos", 11 | "macos-arm64", 12 | "windows", 13 | "atlas", 14 | "c23", 15 | "clang-asan", 16 | "clang16", 17 | "clang17", 18 | "clang18", 19 | "clang19", 20 | "gcc13", 21 | "gcc14", 22 | "intel", 23 | "mkl", 24 | "nold", 25 | "ubuntu-clang", 26 | "ubuntu-gcc12", 27 | "ubuntu-next", 28 | "ubuntu-release" 29 | ) 30 | ) 31 | -------------------------------------------------------------------------------- /dev_scripts/roxyglobals.R: -------------------------------------------------------------------------------- 1 | # Add to current R package 2 | library(roxyglobals) 3 | roxyglobals::use_roxyglobals() 4 | -------------------------------------------------------------------------------- /dev_scripts/valgrind.R: -------------------------------------------------------------------------------- 1 | # https://www.r-bloggers.com/2020/06/testing-rcpp-packages/ 2 | #https://francoismichonneau.net/2014/03/how-to-do-ubsan-tests-r-package/ 3 | 4 | #https://stackoverflow.com/questions/76181893/cant-solve-valgrind-memory-issues-in-rcpp-code 5 | 6 | #TIPS 7 | # Do not turn on leak checking initially. 8 | # Fix all errors from the top down. 9 | # When you have no more errors, turn on leak checking. 10 | # Fix the leaks from the bottom up (the largest leaks are at the end). 11 | 12 | #build source 13 | devtools::build() 14 | 15 | #test as cran 16 | R CMD check --as-cran --use-valgrind /home/blas/Dropbox/GITHUB/R_packages/distantia_2.0.0.tar.gz 17 | 18 | #run specific file 19 | R -d valgrind --vanilla > tests/myTest1.R 20 | 21 | #specific test file 22 | R -d "valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all --track-origins=yes" -f tests/testthat/test-auto_sum.R 23 | 24 | #full test 25 | R -d "valgrind --tool=memcheck --leak-check=full --show-leak-kinds=all --track-origins=yes" -e "devtools::test()" 26 | 27 | -------------------------------------------------------------------------------- /distantia.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | -------------------------------------------------------------------------------- /inst/CITATION: -------------------------------------------------------------------------------- 1 | citHeader("To cite the R package 'distantia' in publications, please use:") 2 | 3 | bibentry( 4 | bibtype = "Article", 5 | author = c( 6 | person(given = "Blas M.", family = "Benito"), 7 | person(given = "H. John B.", family = "Birks") 8 | ), 9 | title = "distantia: an open-source toolset to quantify dissimilarity between multivariate ecological time-series", 10 | journal = "Ecography", 11 | volume = "43", 12 | number = "5", 13 | pages = "660-667", 14 | doi = "10.1111/ecog.04895", 15 | url = "https://nsojournals.onlinelibrary.wiley.com/doi/abs/10.1111/ecog.04895", 16 | eprint = "https://nsojournals.onlinelibrary.wiley.com/doi/pdf/10.1111/ecog.04895", 17 | year = "2020" 18 | ) 19 | 20 | bibentry( 21 | bibtype = "Manual", 22 | title = "distantia: A Toolset for Time Series Dissimilarity Analysis", 23 | author = person(given = "Blas M.", family = "Benito"), 24 | year = "2024", 25 | note = "R package version 2.0", 26 | url = "https://blasbenito.github.io/distantia/", 27 | ) 28 | -------------------------------------------------------------------------------- /inst/WORDLIST: -------------------------------------------------------------------------------- 1 | Birks 2 | Blas 3 | CMD 4 | Carpinus 5 | Changelog 6 | Chebyshev 7 | Compositional 8 | Coredata 9 | Covid 10 | DOI 11 | DTW 12 | Detrending 13 | Differencing 14 | Ecography 15 | Eemian 16 | Fagus 17 | Frangula 18 | HH 19 | Hellinger 20 | Interglacial 21 | Itakura 22 | Jaccard 23 | LINESTRING 24 | Loess 25 | MULTIPOLYGON 26 | Minimalistic 27 | Multiplicator 28 | Nychka 29 | Okabe 30 | POSIXct 31 | Parallelization 32 | Phoebastria 33 | Polychrome 34 | Rao 35 | Rcpp 36 | Rescale 37 | Rescaling 38 | Rmarkdown 39 | Rowwise 40 | Sørensen 41 | TSL 42 | TSLs 43 | Toolset 44 | UPGMA 45 | UPGMC 46 | Uurope 47 | WPGMA 48 | WPGMC 49 | YYYY 50 | Zissou 51 | alingment 52 | autodistances 53 | blasbenito 54 | bottomleft 55 | bottomright 56 | cardinality 57 | compositional 58 | coredata 59 | detrend 60 | detrending 61 | df 62 | differencing 63 | doi 64 | downsampling 65 | dtw 66 | ecog 67 | gam 68 | gmail 69 | hclust 70 | healthdata 71 | hellinger 72 | interglacial 73 | intergration 74 | iq 75 | irrorata 76 | kmeans 77 | loess 78 | mcquitty 79 | misalignments 80 | multipanel 81 | multiplicator 82 | nrow 83 | obect 84 | overfitted 85 | parallelization 86 | phenological 87 | pre 88 | progressr 89 | replicability 90 | rescale 91 | rescaling 92 | rmse 93 | sd 94 | sensical 95 | strenght 96 | sylvatica 97 | tailedness 98 | th 99 | timme 100 | toolset 101 | topleft 102 | topright 103 | tsl 104 | twoway 105 | uncalibrated 106 | upsampling 107 | workflowImportance 108 | workflowPsi 109 | workflowPsiHP 110 | workflowSlotting 111 | workflowTransfer 112 | xy 113 | -------------------------------------------------------------------------------- /man/auto_distance_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{auto_distance_cpp} 4 | \alias{auto_distance_cpp} 5 | \title{(C++) Sum Distances Between Consecutive Samples in a Time Series} 6 | \usage{ 7 | auto_distance_cpp(x, distance = "euclidean") 8 | } 9 | \arguments{ 10 | \item{x}{(required, numeric matrix) univariate or multivariate time series.} 11 | 12 | \item{distance}{(optional, character string) distance name from the "names" 13 | column of the dataset \code{distances} (see \code{distances$name}). Default: "euclidean"} 14 | } 15 | \value{ 16 | numeric 17 | } 18 | \description{ 19 | Computes the cumulative sum of distances between consecutive 20 | samples in a univariate or multivariate time series. 21 | NA values should be removed before using this function. 22 | } 23 | \examples{ 24 | #simulate a time series 25 | x <- zoo_simulate() 26 | 27 | #compute auto distance 28 | auto_distance_cpp( 29 | x = x, 30 | distance = "euclidean" 31 | ) 32 | } 33 | \seealso{ 34 | Other Rcpp_auto_sum: 35 | \code{\link{auto_sum_cpp}()}, 36 | \code{\link{auto_sum_full_cpp}()}, 37 | \code{\link{auto_sum_path_cpp}()}, 38 | \code{\link{subset_matrix_by_rows_cpp}()} 39 | } 40 | \concept{Rcpp_auto_sum} 41 | -------------------------------------------------------------------------------- /man/auto_sum_full_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{auto_sum_full_cpp} 4 | \alias{auto_sum_full_cpp} 5 | \title{(C++) Sum Distances Between All Consecutive Samples in Two Time Series} 6 | \usage{ 7 | auto_sum_full_cpp(x, y, distance = "euclidean") 8 | } 9 | \arguments{ 10 | \item{x}{(required, numeric matrix) univariate or multivariate time series.} 11 | 12 | \item{y}{(required, numeric matrix) univariate or multivariate time series 13 | with the same number of columns as 'x'.} 14 | 15 | \item{distance}{(optional, character string) distance name from the "names" 16 | column of the dataset \code{distances} (see \code{distances$name}). Default: "euclidean"} 17 | } 18 | \value{ 19 | numeric 20 | } 21 | \description{ 22 | Computes the cumulative auto sum of autodistances of two time series. 23 | The output value is used as normalization factor when computing dissimilarity scores. 24 | } 25 | \examples{ 26 | #simulate two time series 27 | x <- zoo_simulate(seed = 1) 28 | y <- zoo_simulate(seed = 2) 29 | 30 | #auto sum 31 | auto_sum_full_cpp( 32 | x = x, 33 | y = y, 34 | distance = "euclidean" 35 | ) 36 | } 37 | \seealso{ 38 | Other Rcpp_auto_sum: 39 | \code{\link{auto_distance_cpp}()}, 40 | \code{\link{auto_sum_cpp}()}, 41 | \code{\link{auto_sum_path_cpp}()}, 42 | \code{\link{subset_matrix_by_rows_cpp}()} 43 | } 44 | \concept{Rcpp_auto_sum} 45 | -------------------------------------------------------------------------------- /man/cities_coordinates.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{cities_coordinates} 5 | \alias{cities_coordinates} 6 | \title{Coordinates of 100 Major Cities} 7 | \format{ 8 | sf data frame with 5 columns and 100 rows. 9 | } 10 | \usage{ 11 | data(cities_coordinates) 12 | } 13 | \description{ 14 | City coordinates and several environmental variables for the dataset \code{cities_temperature}. 15 | 16 | The full dataset with 100 cities can be downloaded from \url{https://github.com/BlasBenito/distantia/blob/main/data_full/cities_coordinates.rda} (use the "Download raw file" button). 17 | } 18 | \seealso{ 19 | Other example_data: 20 | \code{\link{albatross}}, 21 | \code{\link{cities_temperature}}, 22 | \code{\link{covid_counties}}, 23 | \code{\link{covid_prevalence}}, 24 | \code{\link{eemian_coordinates}}, 25 | \code{\link{eemian_pollen}}, 26 | \code{\link{fagus_coordinates}}, 27 | \code{\link{fagus_dynamics}}, 28 | \code{\link{honeycomb_climate}}, 29 | \code{\link{honeycomb_polygons}} 30 | 31 | Other example_data: 32 | \code{\link{albatross}}, 33 | \code{\link{cities_temperature}}, 34 | \code{\link{covid_counties}}, 35 | \code{\link{covid_prevalence}}, 36 | \code{\link{eemian_coordinates}}, 37 | \code{\link{eemian_pollen}}, 38 | \code{\link{fagus_coordinates}}, 39 | \code{\link{fagus_dynamics}}, 40 | \code{\link{honeycomb_climate}}, 41 | \code{\link{honeycomb_polygons}} 42 | } 43 | \concept{example_data} 44 | \keyword{datasets} 45 | -------------------------------------------------------------------------------- /man/color_continuous.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/color_continuous.R 3 | \name{color_continuous} 4 | \alias{color_continuous} 5 | \title{Default Continuous Color Palette} 6 | \usage{ 7 | color_continuous(n = 5, palette = "Zissou 1", rev = FALSE) 8 | } 9 | \arguments{ 10 | \item{n}{(required, integer) number of colors to generate. Default = NULL} 11 | 12 | \item{palette}{(required, character string) Argument \code{palette} of \code{\link[grDevices:palettes]{grDevices::hcl.colors()}}. Default: "Zissou 1"} 13 | 14 | \item{rev}{(optional, logical) If TRUE, the color palette is reversed. Default: FALSE} 15 | } 16 | \value{ 17 | color vector 18 | } 19 | \description{ 20 | Uses the function \code{\link[grDevices:palettes]{grDevices::hcl.colors()}} to generate a continuous color palette. 21 | } 22 | \examples{ 23 | 24 | color_continuous(n = 20) 25 | 26 | } 27 | \seealso{ 28 | Other internal_plotting: 29 | \code{\link{color_discrete}()}, 30 | \code{\link{utils_color_breaks}()}, 31 | \code{\link{utils_line_color}()}, 32 | \code{\link{utils_line_guide}()}, 33 | \code{\link{utils_matrix_guide}()}, 34 | \code{\link{utils_matrix_plot}()} 35 | } 36 | \concept{internal_plotting} 37 | -------------------------------------------------------------------------------- /man/color_discrete.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/color_discrete.R 3 | \name{color_discrete} 4 | \alias{color_discrete} 5 | \title{Default Discrete Color Palettes} 6 | \usage{ 7 | color_discrete(n = NULL, rev = FALSE) 8 | } 9 | \arguments{ 10 | \item{n}{(required, integer) number of colors to generate. Default = NULL} 11 | 12 | \item{rev}{(optional, logical) If TRUE, the color palette is reversed. Default: FALSE} 13 | } 14 | \value{ 15 | color vector 16 | } 17 | \description{ 18 | Uses the function \code{\link[grDevices:palette]{grDevices::palette.colors()}} to generate discrete color palettes using the following rules: 19 | \itemize{ 20 | \item \code{n <= 9}: "Okabe-Ito". 21 | \item \code{n == 10}: "Tableau 10" 22 | \item \code{n > 10 && n <= 12}: "Paired" 23 | \item \code{n > 12 && n <= 26}: "Alphabet" 24 | \item \code{n > 26 && n <= 36}: "Polychrome 36" 25 | } 26 | } 27 | \examples{ 28 | 29 | color_discrete(n = 9) 30 | } 31 | \seealso{ 32 | Other internal_plotting: 33 | \code{\link{color_continuous}()}, 34 | \code{\link{utils_color_breaks}()}, 35 | \code{\link{utils_line_color}()}, 36 | \code{\link{utils_line_guide}()}, 37 | \code{\link{utils_matrix_guide}()}, 38 | \code{\link{utils_matrix_plot}()} 39 | } 40 | \concept{internal_plotting} 41 | -------------------------------------------------------------------------------- /man/cost_matrix_diagonal_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{cost_matrix_diagonal_cpp} 4 | \alias{cost_matrix_diagonal_cpp} 5 | \title{(C++) Compute Orthogonal and Diagonal Least Cost Matrix from a Distance Matrix} 6 | \usage{ 7 | cost_matrix_diagonal_cpp(dist_matrix) 8 | } 9 | \arguments{ 10 | \item{dist_matrix}{(required, distance matrix). Square distance matrix, output of \code{\link[=distance_matrix_cpp]{distance_matrix_cpp()}}.} 11 | } 12 | \value{ 13 | Least cost matrix. 14 | } 15 | \description{ 16 | Computes the least cost matrix from a distance matrix. 17 | Considers diagonals during computation of least-costs. 18 | } 19 | \seealso{ 20 | Other Rcpp_matrix: 21 | \code{\link{cost_matrix_diagonal_weighted_cpp}()}, 22 | \code{\link{cost_matrix_orthogonal_cpp}()}, 23 | \code{\link{distance_ls_cpp}()}, 24 | \code{\link{distance_matrix_cpp}()} 25 | } 26 | \concept{Rcpp_matrix} 27 | -------------------------------------------------------------------------------- /man/cost_matrix_diagonal_weighted_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{cost_matrix_diagonal_weighted_cpp} 4 | \alias{cost_matrix_diagonal_weighted_cpp} 5 | \title{(C++) Compute Orthogonal and Weighted Diagonal Least Cost Matrix from a Distance Matrix} 6 | \usage{ 7 | cost_matrix_diagonal_weighted_cpp(dist_matrix) 8 | } 9 | \arguments{ 10 | \item{dist_matrix}{(required, distance matrix). Distance matrix.} 11 | } 12 | \value{ 13 | Least cost matrix. 14 | } 15 | \description{ 16 | Computes the least cost matrix from a distance matrix. 17 | Weights diagonals by a factor of 1.414214 (square root of 2) with respect to orthogonal paths. 18 | } 19 | \seealso{ 20 | Other Rcpp_matrix: 21 | \code{\link{cost_matrix_diagonal_cpp}()}, 22 | \code{\link{cost_matrix_orthogonal_cpp}()}, 23 | \code{\link{distance_ls_cpp}()}, 24 | \code{\link{distance_matrix_cpp}()} 25 | } 26 | \concept{Rcpp_matrix} 27 | -------------------------------------------------------------------------------- /man/cost_matrix_orthogonal_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{cost_matrix_orthogonal_cpp} 4 | \alias{cost_matrix_orthogonal_cpp} 5 | \title{(C++) Compute Orthogonal Least Cost Matrix from a Distance Matrix} 6 | \usage{ 7 | cost_matrix_orthogonal_cpp(dist_matrix) 8 | } 9 | \arguments{ 10 | \item{dist_matrix}{(required, distance matrix). Output of \code{\link[=distance_matrix_cpp]{distance_matrix_cpp()}}.} 11 | } 12 | \value{ 13 | Least cost matrix. 14 | } 15 | \description{ 16 | Computes the least cost matrix from a distance matrix. 17 | } 18 | \seealso{ 19 | Other Rcpp_matrix: 20 | \code{\link{cost_matrix_diagonal_cpp}()}, 21 | \code{\link{cost_matrix_diagonal_weighted_cpp}()}, 22 | \code{\link{distance_ls_cpp}()}, 23 | \code{\link{distance_matrix_cpp}()} 24 | } 25 | \concept{Rcpp_matrix} 26 | -------------------------------------------------------------------------------- /man/cost_path_diagonal_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{cost_path_diagonal_cpp} 4 | \alias{cost_path_diagonal_cpp} 5 | \title{(C++) Orthogonal and Diagonal Least Cost Path} 6 | \usage{ 7 | cost_path_diagonal_cpp(dist_matrix, cost_matrix) 8 | } 9 | \arguments{ 10 | \item{dist_matrix}{(required, numeric matrix). Distance matrix between two 11 | time series.} 12 | 13 | \item{cost_matrix}{(required, numeric matrix). Cost matrix generated from 14 | \code{dist_matrix}.} 15 | } 16 | \value{ 17 | data frame 18 | } 19 | \description{ 20 | Computes the least cost matrix from a distance matrix. 21 | Considers diagonals during computation of least-costs. In case of ties, 22 | diagonals are favored. 23 | } 24 | \examples{ 25 | #simulate two time series 26 | x <- zoo_simulate(seed = 1) 27 | y <- zoo_simulate(seed = 2) 28 | 29 | #distance matrix 30 | dist_matrix <- distance_matrix_cpp( 31 | x = x, 32 | y = y, 33 | distance = "euclidean" 34 | ) 35 | 36 | #least cost matrix 37 | cost_matrix <- cost_matrix_orthogonal_cpp( 38 | dist_matrix = dist_matrix 39 | ) 40 | 41 | #least cost path 42 | cost_path <- cost_path_diagonal_cpp( 43 | dist_matrix = dist_matrix, 44 | cost_matrix = cost_matrix 45 | ) 46 | 47 | cost_path 48 | } 49 | \seealso{ 50 | Other Rcpp_cost_path: 51 | \code{\link{cost_path_cpp}()}, 52 | \code{\link{cost_path_diagonal_bandwidth_cpp}()}, 53 | \code{\link{cost_path_orthogonal_bandwidth_cpp}()}, 54 | \code{\link{cost_path_orthogonal_cpp}()}, 55 | \code{\link{cost_path_slotting_cpp}()}, 56 | \code{\link{cost_path_sum_cpp}()}, 57 | \code{\link{cost_path_trim_cpp}()} 58 | } 59 | \concept{Rcpp_cost_path} 60 | -------------------------------------------------------------------------------- /man/cost_path_orthogonal_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{cost_path_orthogonal_cpp} 4 | \alias{cost_path_orthogonal_cpp} 5 | \title{(C++) Orthogonal Least Cost Path} 6 | \usage{ 7 | cost_path_orthogonal_cpp(dist_matrix, cost_matrix) 8 | } 9 | \arguments{ 10 | \item{dist_matrix}{(required, numeric matrix). Distance matrix between two 11 | time series.} 12 | 13 | \item{cost_matrix}{(required, numeric matrix). Cost matrix generated from 14 | \code{dist_matrix}.} 15 | } 16 | \value{ 17 | data frame 18 | } 19 | \description{ 20 | Computes an orthogonal least-cost path within a cost matrix. Each steps within 21 | the least-cost path either moves in the x or the y direction, but never diagonally. 22 | } 23 | \examples{ 24 | #simulate two time series 25 | x <- zoo_simulate(seed = 1) 26 | y <- zoo_simulate(seed = 2) 27 | 28 | #distance matrix 29 | dist_matrix <- distance_matrix_cpp( 30 | x = x, 31 | y = y, 32 | distance = "euclidean" 33 | ) 34 | 35 | #least cost matrix 36 | cost_matrix <- cost_matrix_orthogonal_cpp( 37 | dist_matrix = dist_matrix 38 | ) 39 | 40 | #least cost path 41 | cost_path <- cost_path_orthogonal_cpp( 42 | dist_matrix = dist_matrix, 43 | cost_matrix = cost_matrix 44 | ) 45 | 46 | cost_path 47 | } 48 | \seealso{ 49 | Other Rcpp_cost_path: 50 | \code{\link{cost_path_cpp}()}, 51 | \code{\link{cost_path_diagonal_bandwidth_cpp}()}, 52 | \code{\link{cost_path_diagonal_cpp}()}, 53 | \code{\link{cost_path_orthogonal_bandwidth_cpp}()}, 54 | \code{\link{cost_path_slotting_cpp}()}, 55 | \code{\link{cost_path_sum_cpp}()}, 56 | \code{\link{cost_path_trim_cpp}()} 57 | } 58 | \concept{Rcpp_cost_path} 59 | -------------------------------------------------------------------------------- /man/cost_path_sum_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{cost_path_sum_cpp} 4 | \alias{cost_path_sum_cpp} 5 | \title{(C++) Sum Distances in a Least Cost Path} 6 | \usage{ 7 | cost_path_sum_cpp(path) 8 | } 9 | \arguments{ 10 | \item{path}{(required, data frame) least-cost path produced by \code{\link[=cost_path_orthogonal_cpp]{cost_path_orthogonal_cpp()}}.} 11 | } 12 | \value{ 13 | numeric 14 | } 15 | \description{ 16 | (C++) Sum Distances in a Least Cost Path 17 | } 18 | \examples{ 19 | #simulate two time series 20 | x <- zoo_simulate(seed = 1) 21 | y <- zoo_simulate(seed = 2) 22 | 23 | #distance matrix 24 | dist_matrix <- distance_matrix_cpp( 25 | x = x, 26 | y = y, 27 | distance = "euclidean" 28 | ) 29 | 30 | #least cost matrix 31 | cost_matrix <- cost_matrix_orthogonal_cpp( 32 | dist_matrix = dist_matrix 33 | ) 34 | 35 | #least cost path 36 | cost_path <- cost_path_slotting_cpp( 37 | dist_matrix = dist_matrix, 38 | cost_matrix = cost_matrix 39 | ) 40 | 41 | cost_path_sum_cpp( 42 | path = cost_path 43 | ) 44 | } 45 | \seealso{ 46 | Other Rcpp_cost_path: 47 | \code{\link{cost_path_cpp}()}, 48 | \code{\link{cost_path_diagonal_bandwidth_cpp}()}, 49 | \code{\link{cost_path_diagonal_cpp}()}, 50 | \code{\link{cost_path_orthogonal_bandwidth_cpp}()}, 51 | \code{\link{cost_path_orthogonal_cpp}()}, 52 | \code{\link{cost_path_slotting_cpp}()}, 53 | \code{\link{cost_path_trim_cpp}()} 54 | } 55 | \concept{Rcpp_cost_path} 56 | -------------------------------------------------------------------------------- /man/cost_path_trim_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{cost_path_trim_cpp} 4 | \alias{cost_path_trim_cpp} 5 | \title{(C++) Remove Blocks from a Least Cost Path} 6 | \usage{ 7 | cost_path_trim_cpp(path) 8 | } 9 | \arguments{ 10 | \item{path}{(required, data frame) least-cost path produced by \code{\link[=cost_path_orthogonal_cpp]{cost_path_orthogonal_cpp()}}.} 11 | } 12 | \value{ 13 | data frame 14 | } 15 | \description{ 16 | (C++) Remove Blocks from a Least Cost Path 17 | } 18 | \examples{ 19 | #simulate two time series 20 | x <- zoo_simulate(seed = 1) 21 | y <- zoo_simulate(seed = 2) 22 | 23 | #distance matrix 24 | dist_matrix <- distance_matrix_cpp( 25 | x = x, 26 | y = y, 27 | distance = "euclidean" 28 | ) 29 | 30 | #least cost matrix 31 | cost_matrix <- cost_matrix_orthogonal_cpp( 32 | dist_matrix = dist_matrix 33 | ) 34 | 35 | #least cost path 36 | cost_path <- cost_path_slotting_cpp( 37 | dist_matrix = dist_matrix, 38 | cost_matrix = cost_matrix 39 | ) 40 | 41 | nrow(cost_path) 42 | 43 | #remove blocks from least-cost path 44 | cost_path_trimmed <- cost_path_trim_cpp( 45 | path = cost_path 46 | ) 47 | 48 | nrow(cost_path_trimmed) 49 | } 50 | \seealso{ 51 | Other Rcpp_cost_path: 52 | \code{\link{cost_path_cpp}()}, 53 | \code{\link{cost_path_diagonal_bandwidth_cpp}()}, 54 | \code{\link{cost_path_diagonal_cpp}()}, 55 | \code{\link{cost_path_orthogonal_bandwidth_cpp}()}, 56 | \code{\link{cost_path_orthogonal_cpp}()}, 57 | \code{\link{cost_path_slotting_cpp}()}, 58 | \code{\link{cost_path_sum_cpp}()} 59 | } 60 | \concept{Rcpp_cost_path} 61 | -------------------------------------------------------------------------------- /man/covid_counties.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{covid_counties} 5 | \alias{covid_counties} 6 | \title{County Coordinates of the Covid Prevalence Dataset} 7 | \format{ 8 | sf data frame with county polygons and census data. 9 | } 10 | \usage{ 11 | data(covid_counties) 12 | } 13 | \description{ 14 | County Coordinates of the Covid Prevalence Dataset 15 | } 16 | \seealso{ 17 | Other example_data: 18 | \code{\link{albatross}}, 19 | \code{\link{cities_coordinates}}, 20 | \code{\link{cities_temperature}}, 21 | \code{\link{covid_prevalence}}, 22 | \code{\link{eemian_coordinates}}, 23 | \code{\link{eemian_pollen}}, 24 | \code{\link{fagus_coordinates}}, 25 | \code{\link{fagus_dynamics}}, 26 | \code{\link{honeycomb_climate}}, 27 | \code{\link{honeycomb_polygons}} 28 | } 29 | \concept{example_data} 30 | \keyword{datasets} 31 | -------------------------------------------------------------------------------- /man/covid_prevalence.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{covid_prevalence} 5 | \alias{covid_prevalence} 6 | \title{Time Series of Covid Prevalence in California Counties} 7 | \format{ 8 | data frame with 3 columns and 51048 rows 9 | } 10 | \usage{ 11 | data(covid_prevalence) 12 | } 13 | \description{ 14 | Dataset with Covid19 maximum weekly prevalence in California counties between 2020 and 2024, from healthdata.gov. 15 | } 16 | \details{ 17 | County polygons and additional data for this dataset are in \link{covid_counties}. 18 | 19 | The full dataset at daily resolution can be downloaded from \url{https://github.com/BlasBenito/distantia/blob/main/data_full/covid_prevalence.rda} (use the "Download raw file" button). 20 | } 21 | \examples{ 22 | #to time series list 23 | tsl <- tsl_initialize( 24 | x = covid_prevalence, 25 | name_column = "name", 26 | time_column = "time" 27 | ) 28 | 29 | #time series plot 30 | if(interactive()){ 31 | 32 | #subset to avoid margin errors 33 | tsl_plot( 34 | tsl = tsl_subset( 35 | tsl = tsl, 36 | names = 1:4 37 | ), 38 | guide = FALSE 39 | ) 40 | 41 | } 42 | } 43 | \seealso{ 44 | Other example_data: 45 | \code{\link{albatross}}, 46 | \code{\link{cities_coordinates}}, 47 | \code{\link{cities_temperature}}, 48 | \code{\link{covid_counties}}, 49 | \code{\link{eemian_coordinates}}, 50 | \code{\link{eemian_pollen}}, 51 | \code{\link{fagus_coordinates}}, 52 | \code{\link{fagus_dynamics}}, 53 | \code{\link{honeycomb_climate}}, 54 | \code{\link{honeycomb_polygons}} 55 | } 56 | \concept{example_data} 57 | \keyword{datasets} 58 | -------------------------------------------------------------------------------- /man/distance.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/distance.R 3 | \name{distance} 4 | \alias{distance} 5 | \title{Distance Between Two Numeric Vectors} 6 | \usage{ 7 | distance(x = NULL, y = NULL, distance = "euclidean") 8 | } 9 | \arguments{ 10 | \item{x}{(required, numeric vector).} 11 | 12 | \item{y}{(required, numeric vector) of same length as \code{x}.} 13 | 14 | \item{distance}{(optional, character string) name or abbreviation of the distance method. Valid values are in the columns "names" and "abbreviation" of the dataset \code{distances}. Default: "euclidean".} 15 | } 16 | \value{ 17 | numeric value 18 | } 19 | \description{ 20 | Computes the distance between two numeric vectors with a distance metric included in the data frame \code{distantia::distances}. 21 | } 22 | \examples{ 23 | 24 | distance( 25 | x = runif(100), 26 | y = runif(100), 27 | distance = "euclidean" 28 | ) 29 | 30 | } 31 | \seealso{ 32 | Other distances: 33 | \code{\link{distance_matrix}()}, 34 | \code{\link{distances}} 35 | } 36 | \concept{distances} 37 | -------------------------------------------------------------------------------- /man/distance_bray_curtis_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{distance_bray_curtis_cpp} 4 | \alias{distance_bray_curtis_cpp} 5 | \title{(C++) Bray-Curtis Distance Between Two Vectors} 6 | \usage{ 7 | distance_bray_curtis_cpp(x, y) 8 | } 9 | \arguments{ 10 | \item{x}{(required, numeric vector).} 11 | 12 | \item{y}{(required, numeric vector) of same length as \code{x}.} 13 | } 14 | \value{ 15 | numeric 16 | } 17 | \description{ 18 | Computes the Bray-Curtis distance, suitable for species abundance data. 19 | } 20 | \examples{ 21 | distance_bray_curtis_cpp(x = runif(100), y = runif(100)) 22 | } 23 | \seealso{ 24 | Other Rcpp_distance_methods: 25 | \code{\link{distance_canberra_cpp}()}, 26 | \code{\link{distance_chebyshev_cpp}()}, 27 | \code{\link{distance_chi_cpp}()}, 28 | \code{\link{distance_cosine_cpp}()}, 29 | \code{\link{distance_euclidean_cpp}()}, 30 | \code{\link{distance_hamming_cpp}()}, 31 | \code{\link{distance_hellinger_cpp}()}, 32 | \code{\link{distance_jaccard_cpp}()}, 33 | \code{\link{distance_manhattan_cpp}()}, 34 | \code{\link{distance_russelrao_cpp}()}, 35 | \code{\link{distance_sorensen_cpp}()} 36 | } 37 | \concept{Rcpp_distance_methods} 38 | -------------------------------------------------------------------------------- /man/distance_canberra_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{distance_canberra_cpp} 4 | \alias{distance_canberra_cpp} 5 | \title{(C++) Canberra Distance Between Two Binary Vectors} 6 | \usage{ 7 | distance_canberra_cpp(x, y) 8 | } 9 | \arguments{ 10 | \item{x}{(required, numeric vector).} 11 | 12 | \item{y}{(required, numeric vector) of same length as \code{x}.} 13 | } 14 | \value{ 15 | numeric 16 | } 17 | \description{ 18 | Computes the Canberra distance between two binary vectors. 19 | } 20 | \examples{ 21 | distance_canberra_cpp(c(0, 1, 0, 1), c(1, 1, 0, 0)) 22 | } 23 | \seealso{ 24 | Other Rcpp_distance_methods: 25 | \code{\link{distance_bray_curtis_cpp}()}, 26 | \code{\link{distance_chebyshev_cpp}()}, 27 | \code{\link{distance_chi_cpp}()}, 28 | \code{\link{distance_cosine_cpp}()}, 29 | \code{\link{distance_euclidean_cpp}()}, 30 | \code{\link{distance_hamming_cpp}()}, 31 | \code{\link{distance_hellinger_cpp}()}, 32 | \code{\link{distance_jaccard_cpp}()}, 33 | \code{\link{distance_manhattan_cpp}()}, 34 | \code{\link{distance_russelrao_cpp}()}, 35 | \code{\link{distance_sorensen_cpp}()} 36 | } 37 | \concept{Rcpp_distance_methods} 38 | -------------------------------------------------------------------------------- /man/distance_chebyshev_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{distance_chebyshev_cpp} 4 | \alias{distance_chebyshev_cpp} 5 | \title{(C++) Chebyshev Distance Between Two Vectors} 6 | \usage{ 7 | distance_chebyshev_cpp(x, y) 8 | } 9 | \arguments{ 10 | \item{x}{(required, numeric vector).} 11 | 12 | \item{y}{(required, numeric vector) of same length as \code{x}.} 13 | } 14 | \value{ 15 | numeric 16 | } 17 | \description{ 18 | Computed as: \code{max(abs(x - y))}. Cannot handle NA values. 19 | } 20 | \examples{ 21 | distance_chebyshev_cpp(x = runif(100), y = runif(100)) 22 | } 23 | \seealso{ 24 | Other Rcpp_distance_methods: 25 | \code{\link{distance_bray_curtis_cpp}()}, 26 | \code{\link{distance_canberra_cpp}()}, 27 | \code{\link{distance_chi_cpp}()}, 28 | \code{\link{distance_cosine_cpp}()}, 29 | \code{\link{distance_euclidean_cpp}()}, 30 | \code{\link{distance_hamming_cpp}()}, 31 | \code{\link{distance_hellinger_cpp}()}, 32 | \code{\link{distance_jaccard_cpp}()}, 33 | \code{\link{distance_manhattan_cpp}()}, 34 | \code{\link{distance_russelrao_cpp}()}, 35 | \code{\link{distance_sorensen_cpp}()} 36 | } 37 | \concept{Rcpp_distance_methods} 38 | -------------------------------------------------------------------------------- /man/distance_chi_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{distance_chi_cpp} 4 | \alias{distance_chi_cpp} 5 | \title{(C++) Normalized Chi Distance Between Two Vectors} 6 | \usage{ 7 | distance_chi_cpp(x, y) 8 | } 9 | \arguments{ 10 | \item{x}{(required, numeric vector).} 11 | 12 | \item{y}{(required, numeric vector) of same length as \code{x}.} 13 | } 14 | \value{ 15 | numeric 16 | } 17 | \description{ 18 | Computed as: 19 | \code{xy <- x + y} 20 | \code{y. <- y / sum(y)} 21 | \code{x. <- x / sum(x)} 22 | \code{sqrt(sum(((x. - y.)^2) / (xy / sum(xy))))}. 23 | Cannot handle NA values. When \code{x} and \code{y} have zeros in the same 24 | position, \code{NaNs} are produced. Please replace these zeros with 25 | pseudo-zeros (i.e. 0.0001) if you wish to use this distance metric. 26 | } 27 | \examples{ 28 | distance_chi_cpp(x = runif(100), y = runif(100)) 29 | } 30 | \seealso{ 31 | Other Rcpp_distance_methods: 32 | \code{\link{distance_bray_curtis_cpp}()}, 33 | \code{\link{distance_canberra_cpp}()}, 34 | \code{\link{distance_chebyshev_cpp}()}, 35 | \code{\link{distance_cosine_cpp}()}, 36 | \code{\link{distance_euclidean_cpp}()}, 37 | \code{\link{distance_hamming_cpp}()}, 38 | \code{\link{distance_hellinger_cpp}()}, 39 | \code{\link{distance_jaccard_cpp}()}, 40 | \code{\link{distance_manhattan_cpp}()}, 41 | \code{\link{distance_russelrao_cpp}()}, 42 | \code{\link{distance_sorensen_cpp}()} 43 | } 44 | \concept{Rcpp_distance_methods} 45 | -------------------------------------------------------------------------------- /man/distance_cosine_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{distance_cosine_cpp} 4 | \alias{distance_cosine_cpp} 5 | \title{(C++) Cosine Dissimilarity Between Two Vectors} 6 | \usage{ 7 | distance_cosine_cpp(x, y) 8 | } 9 | \arguments{ 10 | \item{x}{(required, numeric vector).} 11 | 12 | \item{y}{(required, numeric vector) of same length as \code{x}.} 13 | } 14 | \value{ 15 | numeric 16 | } 17 | \description{ 18 | Computes the cosine dissimilarity between two numeric vectors. 19 | } 20 | \examples{ 21 | distance_cosine_cpp(c(0.2, 0.4, 0.5), c(0.1, 0.8, 0.2)) 22 | } 23 | \seealso{ 24 | Other Rcpp_distance_methods: 25 | \code{\link{distance_bray_curtis_cpp}()}, 26 | \code{\link{distance_canberra_cpp}()}, 27 | \code{\link{distance_chebyshev_cpp}()}, 28 | \code{\link{distance_chi_cpp}()}, 29 | \code{\link{distance_euclidean_cpp}()}, 30 | \code{\link{distance_hamming_cpp}()}, 31 | \code{\link{distance_hellinger_cpp}()}, 32 | \code{\link{distance_jaccard_cpp}()}, 33 | \code{\link{distance_manhattan_cpp}()}, 34 | \code{\link{distance_russelrao_cpp}()}, 35 | \code{\link{distance_sorensen_cpp}()} 36 | } 37 | \concept{Rcpp_distance_methods} 38 | -------------------------------------------------------------------------------- /man/distance_euclidean_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{distance_euclidean_cpp} 4 | \alias{distance_euclidean_cpp} 5 | \title{(C++) Euclidean Distance Between Two Vectors} 6 | \usage{ 7 | distance_euclidean_cpp(x, y) 8 | } 9 | \arguments{ 10 | \item{x}{(required, numeric vector).} 11 | 12 | \item{y}{(required, numeric vector) of same length as \code{x}.} 13 | } 14 | \value{ 15 | numeric 16 | } 17 | \description{ 18 | Computed as: \code{sqrt(sum((x - y)^2)}. Cannot handle NA values. 19 | } 20 | \examples{ 21 | distance_euclidean_cpp(x = runif(100), y = runif(100)) 22 | } 23 | \seealso{ 24 | Other Rcpp_distance_methods: 25 | \code{\link{distance_bray_curtis_cpp}()}, 26 | \code{\link{distance_canberra_cpp}()}, 27 | \code{\link{distance_chebyshev_cpp}()}, 28 | \code{\link{distance_chi_cpp}()}, 29 | \code{\link{distance_cosine_cpp}()}, 30 | \code{\link{distance_hamming_cpp}()}, 31 | \code{\link{distance_hellinger_cpp}()}, 32 | \code{\link{distance_jaccard_cpp}()}, 33 | \code{\link{distance_manhattan_cpp}()}, 34 | \code{\link{distance_russelrao_cpp}()}, 35 | \code{\link{distance_sorensen_cpp}()} 36 | } 37 | \concept{Rcpp_distance_methods} 38 | -------------------------------------------------------------------------------- /man/distance_hamming_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{distance_hamming_cpp} 4 | \alias{distance_hamming_cpp} 5 | \title{(C++) Hamming Distance Between Two Binary Vectors} 6 | \usage{ 7 | distance_hamming_cpp(x, y) 8 | } 9 | \arguments{ 10 | \item{x}{(required, numeric vector).} 11 | 12 | \item{y}{(required, numeric vector) of same length as \code{x}.} 13 | } 14 | \value{ 15 | numeric 16 | } 17 | \description{ 18 | Computes the Hamming distance between two binary vectors. 19 | } 20 | \examples{ 21 | distance_hamming_cpp(c(0, 1, 0, 1), c(1, 1, 0, 0)) 22 | } 23 | \seealso{ 24 | Other Rcpp_distance_methods: 25 | \code{\link{distance_bray_curtis_cpp}()}, 26 | \code{\link{distance_canberra_cpp}()}, 27 | \code{\link{distance_chebyshev_cpp}()}, 28 | \code{\link{distance_chi_cpp}()}, 29 | \code{\link{distance_cosine_cpp}()}, 30 | \code{\link{distance_euclidean_cpp}()}, 31 | \code{\link{distance_hellinger_cpp}()}, 32 | \code{\link{distance_jaccard_cpp}()}, 33 | \code{\link{distance_manhattan_cpp}()}, 34 | \code{\link{distance_russelrao_cpp}()}, 35 | \code{\link{distance_sorensen_cpp}()} 36 | } 37 | \concept{Rcpp_distance_methods} 38 | -------------------------------------------------------------------------------- /man/distance_hellinger_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{distance_hellinger_cpp} 4 | \alias{distance_hellinger_cpp} 5 | \title{(C++) Hellinger Distance Between Two Vectors} 6 | \usage{ 7 | distance_hellinger_cpp(x, y) 8 | } 9 | \arguments{ 10 | \item{x}{(required, numeric vector).} 11 | 12 | \item{y}{(required, numeric vector) of same length as \code{x}.} 13 | } 14 | \value{ 15 | numeric 16 | } 17 | \description{ 18 | Computed as: \code{sqrt(1/2 * sum((sqrt(x) - sqrt(y))^2))}. 19 | Cannot handle NA values. 20 | } 21 | \examples{ 22 | distance_hellinger_cpp(x = runif(100), y = runif(100)) 23 | } 24 | \seealso{ 25 | Other Rcpp_distance_methods: 26 | \code{\link{distance_bray_curtis_cpp}()}, 27 | \code{\link{distance_canberra_cpp}()}, 28 | \code{\link{distance_chebyshev_cpp}()}, 29 | \code{\link{distance_chi_cpp}()}, 30 | \code{\link{distance_cosine_cpp}()}, 31 | \code{\link{distance_euclidean_cpp}()}, 32 | \code{\link{distance_hamming_cpp}()}, 33 | \code{\link{distance_jaccard_cpp}()}, 34 | \code{\link{distance_manhattan_cpp}()}, 35 | \code{\link{distance_russelrao_cpp}()}, 36 | \code{\link{distance_sorensen_cpp}()} 37 | } 38 | \concept{Rcpp_distance_methods} 39 | -------------------------------------------------------------------------------- /man/distance_jaccard_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{distance_jaccard_cpp} 4 | \alias{distance_jaccard_cpp} 5 | \title{(C++) Jaccard Distance Between Two Binary Vectors} 6 | \usage{ 7 | distance_jaccard_cpp(x, y) 8 | } 9 | \arguments{ 10 | \item{x}{(required, numeric vector).} 11 | 12 | \item{y}{(required, numeric vector) of same length as \code{x}.} 13 | } 14 | \value{ 15 | numeric 16 | } 17 | \description{ 18 | Computes the Jaccard distance between two binary vectors. 19 | } 20 | \examples{ 21 | distance_jaccard_cpp(x = c(0, 1, 0, 1), y = c(1, 1, 0, 0)) 22 | } 23 | \seealso{ 24 | Other Rcpp_distance_methods: 25 | \code{\link{distance_bray_curtis_cpp}()}, 26 | \code{\link{distance_canberra_cpp}()}, 27 | \code{\link{distance_chebyshev_cpp}()}, 28 | \code{\link{distance_chi_cpp}()}, 29 | \code{\link{distance_cosine_cpp}()}, 30 | \code{\link{distance_euclidean_cpp}()}, 31 | \code{\link{distance_hamming_cpp}()}, 32 | \code{\link{distance_hellinger_cpp}()}, 33 | \code{\link{distance_manhattan_cpp}()}, 34 | \code{\link{distance_russelrao_cpp}()}, 35 | \code{\link{distance_sorensen_cpp}()} 36 | } 37 | \concept{Rcpp_distance_methods} 38 | -------------------------------------------------------------------------------- /man/distance_manhattan_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{distance_manhattan_cpp} 4 | \alias{distance_manhattan_cpp} 5 | \title{(C++) Manhattan Distance Between Two Vectors} 6 | \usage{ 7 | distance_manhattan_cpp(x, y) 8 | } 9 | \arguments{ 10 | \item{x}{(required, numeric vector).} 11 | 12 | \item{y}{(required, numeric vector) of same length as \code{x}.} 13 | } 14 | \value{ 15 | numeric 16 | } 17 | \description{ 18 | Computed as: \code{sum(abs(x - y))}. Cannot handle NA values. 19 | } 20 | \examples{ 21 | distance_manhattan_cpp(x = runif(100), y = runif(100)) 22 | } 23 | \seealso{ 24 | Other Rcpp_distance_methods: 25 | \code{\link{distance_bray_curtis_cpp}()}, 26 | \code{\link{distance_canberra_cpp}()}, 27 | \code{\link{distance_chebyshev_cpp}()}, 28 | \code{\link{distance_chi_cpp}()}, 29 | \code{\link{distance_cosine_cpp}()}, 30 | \code{\link{distance_euclidean_cpp}()}, 31 | \code{\link{distance_hamming_cpp}()}, 32 | \code{\link{distance_hellinger_cpp}()}, 33 | \code{\link{distance_jaccard_cpp}()}, 34 | \code{\link{distance_russelrao_cpp}()}, 35 | \code{\link{distance_sorensen_cpp}()} 36 | } 37 | \concept{Rcpp_distance_methods} 38 | -------------------------------------------------------------------------------- /man/distance_matrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/distance_matrix.R 3 | \name{distance_matrix} 4 | \alias{distance_matrix} 5 | \title{Data Frame to Distance Matrix} 6 | \usage{ 7 | distance_matrix(df = NULL, name_column = NULL, distance = "euclidean") 8 | } 9 | \arguments{ 10 | \item{df}{(required, data frame) Data frame with numeric columns to transform into a distance matrix. Default: NULL} 11 | 12 | \item{name_column}{(optional, column name) Column naming individual time series. Numeric names are converted to character with the prefix "X". Default: NULL} 13 | 14 | \item{distance}{(optional, character vector) name or abbreviation of the distance method. Valid values are in the columns "names" and "abbreviation" of the dataset \link{distances}. Default: "euclidean".} 15 | } 16 | \value{ 17 | square matrix 18 | } 19 | \description{ 20 | Data Frame to Distance Matrix 21 | } 22 | \examples{ 23 | #compute distance matrix 24 | m <- distance_matrix( 25 | df = cities_coordinates, 26 | name_column = "name", 27 | distance = "euclidean" 28 | ) 29 | 30 | #get data used to compute the matrix 31 | attributes(m)$df 32 | 33 | #check matrix 34 | m 35 | 36 | } 37 | \seealso{ 38 | Other distances: 39 | \code{\link{distance}()}, 40 | \code{\link{distances}} 41 | } 42 | \concept{distances} 43 | -------------------------------------------------------------------------------- /man/distance_matrix_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{distance_matrix_cpp} 4 | \alias{distance_matrix_cpp} 5 | \title{(C++) Distance Matrix of Two Time Series} 6 | \usage{ 7 | distance_matrix_cpp(x, y, distance = "euclidean") 8 | } 9 | \arguments{ 10 | \item{x}{(required, numeric matrix) univariate or multivariate time series.} 11 | 12 | \item{y}{(required, numeric matrix) univariate or multivariate time series 13 | with the same number of columns as 'x'.} 14 | 15 | \item{distance}{(optional, character string) distance name from the "names" 16 | column of the dataset \code{distances} (see \code{distances$name}). Default: "euclidean".} 17 | } 18 | \value{ 19 | numeric matrix 20 | } 21 | \description{ 22 | Computes the distance matrix between the rows of two matrices 23 | \code{y} and \code{x} representing regular or irregular time series with the same number of 24 | columns. NA values should be removed before using this function. If the selected distance function is "chi" or "cosine", pairs of zeros should 25 | be either removed or replaced with pseudo-zeros (i.e. 0.00001). 26 | } 27 | \examples{ 28 | #simulate two time series 29 | x <- zoo_simulate(seed = 1) 30 | y <- zoo_simulate(seed = 2) 31 | 32 | #distance matrix 33 | dist_matrix <- distance_matrix_cpp( 34 | x = x, 35 | y = y, 36 | distance = "euclidean" 37 | ) 38 | } 39 | \seealso{ 40 | Other Rcpp_matrix: 41 | \code{\link{cost_matrix_diagonal_cpp}()}, 42 | \code{\link{cost_matrix_diagonal_weighted_cpp}()}, 43 | \code{\link{cost_matrix_orthogonal_cpp}()}, 44 | \code{\link{distance_ls_cpp}()} 45 | } 46 | \concept{Rcpp_matrix} 47 | -------------------------------------------------------------------------------- /man/distance_russelrao_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{distance_russelrao_cpp} 4 | \alias{distance_russelrao_cpp} 5 | \title{(C++) Russell-Rao Distance Between Two Binary Vectors} 6 | \usage{ 7 | distance_russelrao_cpp(x, y) 8 | } 9 | \arguments{ 10 | \item{x}{(required, numeric). Binary vector of 1s and 0s.} 11 | 12 | \item{y}{(required, numeric) Binary vector of 1s and 0s of same length as \code{x}.} 13 | } 14 | \value{ 15 | numeric 16 | } 17 | \description{ 18 | Computes the Russell-Rao distance between two binary vectors. 19 | } 20 | \examples{ 21 | distance_russelrao_cpp(c(0, 1, 0, 1), c(1, 1, 0, 0)) 22 | } 23 | \seealso{ 24 | Other Rcpp_distance_methods: 25 | \code{\link{distance_bray_curtis_cpp}()}, 26 | \code{\link{distance_canberra_cpp}()}, 27 | \code{\link{distance_chebyshev_cpp}()}, 28 | \code{\link{distance_chi_cpp}()}, 29 | \code{\link{distance_cosine_cpp}()}, 30 | \code{\link{distance_euclidean_cpp}()}, 31 | \code{\link{distance_hamming_cpp}()}, 32 | \code{\link{distance_hellinger_cpp}()}, 33 | \code{\link{distance_jaccard_cpp}()}, 34 | \code{\link{distance_manhattan_cpp}()}, 35 | \code{\link{distance_sorensen_cpp}()} 36 | } 37 | \concept{Rcpp_distance_methods} 38 | -------------------------------------------------------------------------------- /man/distance_sorensen_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{distance_sorensen_cpp} 4 | \alias{distance_sorensen_cpp} 5 | \title{(C++) Sørensen Distance Between Two Binary Vectors} 6 | \usage{ 7 | distance_sorensen_cpp(x, y) 8 | } 9 | \arguments{ 10 | \item{x}{(required, numeric vector).} 11 | 12 | \item{y}{(required, numeric vector) of same length as \code{x}.} 13 | } 14 | \value{ 15 | numeric 16 | } 17 | \description{ 18 | Computes the Sørensen distance, suitable for presence/absence data. 19 | } 20 | \examples{ 21 | distance_sorensen_cpp(x = c(0, 1, 1, 0), y = c(1, 1, 0, 0)) 22 | } 23 | \seealso{ 24 | Other Rcpp_distance_methods: 25 | \code{\link{distance_bray_curtis_cpp}()}, 26 | \code{\link{distance_canberra_cpp}()}, 27 | \code{\link{distance_chebyshev_cpp}()}, 28 | \code{\link{distance_chi_cpp}()}, 29 | \code{\link{distance_cosine_cpp}()}, 30 | \code{\link{distance_euclidean_cpp}()}, 31 | \code{\link{distance_hamming_cpp}()}, 32 | \code{\link{distance_hellinger_cpp}()}, 33 | \code{\link{distance_jaccard_cpp}()}, 34 | \code{\link{distance_manhattan_cpp}()}, 35 | \code{\link{distance_russelrao_cpp}()} 36 | } 37 | \concept{Rcpp_distance_methods} 38 | -------------------------------------------------------------------------------- /man/distances.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{distances} 5 | \alias{distances} 6 | \title{Distance Methods} 7 | \format{ 8 | data frame with 5 columns and 10 rows 9 | } 10 | \usage{ 11 | data(distances) 12 | } 13 | \description{ 14 | Data frame with the names, abbreviations, and expressions of the distance metrics implemented in the package. 15 | } 16 | \seealso{ 17 | Other distances: 18 | \code{\link{distance}()}, 19 | \code{\link{distance_matrix}()} 20 | } 21 | \concept{distances} 22 | \keyword{datasets} 23 | -------------------------------------------------------------------------------- /man/distantia-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/distantia-package.R 3 | \docType{package} 4 | \name{distantia-package} 5 | \alias{distantia-package} 6 | \title{distantia: A Toolset for Time Series Dissimilarity Analysis} 7 | \description{ 8 | Fast C++ implementation of Dynamic Time Warping for time series dissimilarity analysis, with applications in environmental monitoring and sensor data analysis, climate science, signal processing and pattern recognition, and financial data analysis. Built upon the ideas presented in Benito and Birks (2020) \url{doi:doi.org/10.1111/ecog.04895}, provides tools for analyzing time series of varying lengths and structures, including irregular multivariate time series. Key features include individual variable contribution analysis, restricted permutation tests for statistical significance, and imputation of missing data via GAMs. Additionally, the package provides an ample set of tools to prepare and manage time series data. 9 | } 10 | \seealso{ 11 | Useful links: 12 | \itemize{ 13 | \item \url{https://blasbenito.github.io/distantia/} 14 | \item Report bugs at \url{https://github.com/BlasBenito/distantia/issues} 15 | } 16 | 17 | } 18 | \author{ 19 | Blas Benito \href{mailto:blasbenito@gmail.com}{blasbenito@gmail.com} 20 | } 21 | \keyword{internal} 22 | -------------------------------------------------------------------------------- /man/distantia_stats.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/distantia_stats.R 3 | \name{distantia_stats} 4 | \alias{distantia_stats} 5 | \title{Stats of Dissimilarity Data Frame} 6 | \usage{ 7 | distantia_stats(df = NULL) 8 | } 9 | \arguments{ 10 | \item{df}{(required, data frame) Output of \code{\link[=distantia]{distantia()}}, \code{\link[=distantia_ls]{distantia_ls()}}, \code{\link[=distantia_dtw]{distantia_dtw()}}, or \code{\link[=distantia_time_delay]{distantia_time_delay()}}. Default: NULL} 11 | } 12 | \value{ 13 | data frame 14 | } 15 | \description{ 16 | Takes the output of \code{\link[=distantia]{distantia()}} to return a data frame with one row per time series with the stats of its dissimilarity scores with all other time series. 17 | } 18 | \examples{ 19 | tsl <- tsl_simulate( 20 | n = 5, 21 | irregular = FALSE 22 | ) 23 | 24 | df <- distantia( 25 | tsl = tsl, 26 | lock_step = TRUE 27 | ) 28 | 29 | df_stats <- distantia_stats(df = df) 30 | 31 | df_stats 32 | } 33 | \seealso{ 34 | Other distantia_support: 35 | \code{\link{distantia_aggregate}()}, 36 | \code{\link{distantia_boxplot}()}, 37 | \code{\link{distantia_cluster_hclust}()}, 38 | \code{\link{distantia_cluster_kmeans}()}, 39 | \code{\link{distantia_matrix}()}, 40 | \code{\link{distantia_model_frame}()}, 41 | \code{\link{distantia_spatial}()}, 42 | \code{\link{distantia_time_delay}()}, 43 | \code{\link{utils_block_size}()}, 44 | \code{\link{utils_cluster_hclust_optimizer}()}, 45 | \code{\link{utils_cluster_kmeans_optimizer}()}, 46 | \code{\link{utils_cluster_silhouette}()} 47 | } 48 | \concept{distantia_support} 49 | -------------------------------------------------------------------------------- /man/eemian_coordinates.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{eemian_coordinates} 5 | \alias{eemian_coordinates} 6 | \title{Site Coordinates of Nine Interglacial Sites in Central Europe} 7 | \format{ 8 | sf data frame with 4 columns and 9 rows. 9 | } 10 | \usage{ 11 | data(eemian_coordinates) 12 | } 13 | \description{ 14 | Site Coordinates of Nine Interglacial Sites in Central Europe 15 | } 16 | \seealso{ 17 | Other example_data: 18 | \code{\link{albatross}}, 19 | \code{\link{cities_coordinates}}, 20 | \code{\link{cities_temperature}}, 21 | \code{\link{covid_counties}}, 22 | \code{\link{covid_prevalence}}, 23 | \code{\link{eemian_pollen}}, 24 | \code{\link{fagus_coordinates}}, 25 | \code{\link{fagus_dynamics}}, 26 | \code{\link{honeycomb_climate}}, 27 | \code{\link{honeycomb_polygons}} 28 | 29 | Other example_data: 30 | \code{\link{albatross}}, 31 | \code{\link{cities_coordinates}}, 32 | \code{\link{cities_temperature}}, 33 | \code{\link{covid_counties}}, 34 | \code{\link{covid_prevalence}}, 35 | \code{\link{eemian_pollen}}, 36 | \code{\link{fagus_coordinates}}, 37 | \code{\link{fagus_dynamics}}, 38 | \code{\link{honeycomb_climate}}, 39 | \code{\link{honeycomb_polygons}} 40 | } 41 | \concept{example_data} 42 | \keyword{datasets} 43 | -------------------------------------------------------------------------------- /man/eemian_pollen.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{eemian_pollen} 5 | \alias{eemian_pollen} 6 | \title{Pollen Counts of Nine Interglacial Sites in Central Europe} 7 | \format{ 8 | data frame with 24 columns and 376 rows. 9 | } 10 | \usage{ 11 | data(eemian_pollen) 12 | } 13 | \description{ 14 | Pollen counts of nine interglacial sites in central Europe. 15 | 16 | Site coordinates for this dataset are in \link{eemian_coordinates}. 17 | } 18 | \examples{ 19 | data("eemian_pollen") 20 | 21 | #to time series list 22 | tsl <- tsl_initialize( 23 | x = eemian_pollen, 24 | name_column = "name", 25 | time_column = "time" 26 | ) 27 | 28 | #time series plot 29 | if(interactive()){ 30 | 31 | tsl_plot( 32 | tsl = tsl_subset( 33 | tsl = tsl, 34 | names = 1:3 35 | ), 36 | columns = 2, 37 | guide_columns = 2 38 | ) 39 | 40 | } 41 | 42 | } 43 | \seealso{ 44 | Other example_data: 45 | \code{\link{albatross}}, 46 | \code{\link{cities_coordinates}}, 47 | \code{\link{cities_temperature}}, 48 | \code{\link{covid_counties}}, 49 | \code{\link{covid_prevalence}}, 50 | \code{\link{eemian_coordinates}}, 51 | \code{\link{fagus_coordinates}}, 52 | \code{\link{fagus_dynamics}}, 53 | \code{\link{honeycomb_climate}}, 54 | \code{\link{honeycomb_polygons}} 55 | } 56 | \concept{example_data} 57 | \keyword{datasets} 58 | -------------------------------------------------------------------------------- /man/f_binary.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/transformations.R 3 | \name{f_binary} 4 | \alias{f_binary} 5 | \title{Transform Zoo Object to Binary} 6 | \usage{ 7 | f_binary(x = NULL, threshold = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{(required, zoo object) Zoo time series object to transform.} 11 | 12 | \item{threshold}{(required, numeric) Values greater than this number become 1, others become 0. Set to the mean of the time series by default. Default: NULL} 13 | } 14 | \value{ 15 | zoo object 16 | } 17 | \description{ 18 | Converts a zoo object to binary (1 and 0) based on a given threshold. 19 | } 20 | \examples{ 21 | x <- zoo_simulate( 22 | data_range = c(0, 1) 23 | ) 24 | 25 | y <- f_binary( 26 | x = x, 27 | threshold = 0.5 28 | ) 29 | 30 | if(interactive()){ 31 | zoo_plot(x) 32 | zoo_plot(y) 33 | } 34 | } 35 | \seealso{ 36 | Other tsl_transformation: 37 | \code{\link{f_clr}()}, 38 | \code{\link{f_detrend_difference}()}, 39 | \code{\link{f_detrend_linear}()}, 40 | \code{\link{f_detrend_poly}()}, 41 | \code{\link{f_hellinger}()}, 42 | \code{\link{f_list}()}, 43 | \code{\link{f_log}()}, 44 | \code{\link{f_percent}()}, 45 | \code{\link{f_proportion}()}, 46 | \code{\link{f_proportion_sqrt}()}, 47 | \code{\link{f_rescale_global}()}, 48 | \code{\link{f_rescale_local}()}, 49 | \code{\link{f_scale_global}()}, 50 | \code{\link{f_scale_local}()}, 51 | \code{\link{f_trend_linear}()}, 52 | \code{\link{f_trend_poly}()} 53 | } 54 | \concept{tsl_transformation} 55 | -------------------------------------------------------------------------------- /man/f_clr.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/transformations.R 3 | \name{f_clr} 4 | \alias{f_clr} 5 | \title{Data Transformation: Rowwise Centered Log-Ratio} 6 | \usage{ 7 | f_clr(x = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{x}{(required, zoo object) Zoo time series object to transform.} 11 | 12 | \item{...}{(optional, additional arguments) Ignored in this function.} 13 | } 14 | \value{ 15 | zoo object 16 | } 17 | \description{ 18 | Centers log-transformed proportions by subtracting the geometric mean of the row. 19 | } 20 | \examples{ 21 | x <- zoo_simulate( 22 | cols = 5, 23 | data_range = c(0, 500) 24 | ) 25 | 26 | y <- f_clr( 27 | x = x 28 | ) 29 | 30 | if(interactive()){ 31 | zoo_plot(x) 32 | zoo_plot(y) 33 | } 34 | } 35 | \seealso{ 36 | Other tsl_transformation: 37 | \code{\link{f_binary}()}, 38 | \code{\link{f_detrend_difference}()}, 39 | \code{\link{f_detrend_linear}()}, 40 | \code{\link{f_detrend_poly}()}, 41 | \code{\link{f_hellinger}()}, 42 | \code{\link{f_list}()}, 43 | \code{\link{f_log}()}, 44 | \code{\link{f_percent}()}, 45 | \code{\link{f_proportion}()}, 46 | \code{\link{f_proportion_sqrt}()}, 47 | \code{\link{f_rescale_global}()}, 48 | \code{\link{f_rescale_local}()}, 49 | \code{\link{f_scale_global}()}, 50 | \code{\link{f_scale_local}()}, 51 | \code{\link{f_trend_linear}()}, 52 | \code{\link{f_trend_poly}()} 53 | } 54 | \concept{tsl_transformation} 55 | -------------------------------------------------------------------------------- /man/f_hellinger.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/transformations.R 3 | \name{f_hellinger} 4 | \alias{f_hellinger} 5 | \title{Data Transformation: Rowwise Hellinger Transformation} 6 | \usage{ 7 | f_hellinger(x = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{x}{(required, zoo object) Zoo time series object to transform.} 11 | 12 | \item{...}{(optional, additional arguments) Ignored in this function.} 13 | } 14 | \value{ 15 | zoo object 16 | } 17 | \description{ 18 | Transforms the input zoo object to proportions via \link{f_proportion} and then applies the Hellinger transformation. 19 | } 20 | \examples{ 21 | x <- zoo_simulate( 22 | cols = 5, 23 | data_range = c(0, 500) 24 | ) 25 | 26 | y <- f_hellinger( 27 | x = x 28 | ) 29 | 30 | if(interactive()){ 31 | zoo_plot(x) 32 | zoo_plot(y) 33 | } 34 | } 35 | \seealso{ 36 | Other tsl_transformation: 37 | \code{\link{f_binary}()}, 38 | \code{\link{f_clr}()}, 39 | \code{\link{f_detrend_difference}()}, 40 | \code{\link{f_detrend_linear}()}, 41 | \code{\link{f_detrend_poly}()}, 42 | \code{\link{f_list}()}, 43 | \code{\link{f_log}()}, 44 | \code{\link{f_percent}()}, 45 | \code{\link{f_proportion}()}, 46 | \code{\link{f_proportion_sqrt}()}, 47 | \code{\link{f_rescale_global}()}, 48 | \code{\link{f_rescale_local}()}, 49 | \code{\link{f_scale_global}()}, 50 | \code{\link{f_scale_local}()}, 51 | \code{\link{f_trend_linear}()}, 52 | \code{\link{f_trend_poly}()} 53 | } 54 | \concept{tsl_transformation} 55 | -------------------------------------------------------------------------------- /man/f_list.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/transformations.R 3 | \name{f_list} 4 | \alias{f_list} 5 | \title{Lists Available Transformation Functions} 6 | \usage{ 7 | f_list() 8 | } 9 | \value{ 10 | character vector 11 | } 12 | \description{ 13 | Lists Available Transformation Functions 14 | } 15 | \examples{ 16 | f_list() 17 | } 18 | \seealso{ 19 | Other tsl_transformation: 20 | \code{\link{f_binary}()}, 21 | \code{\link{f_clr}()}, 22 | \code{\link{f_detrend_difference}()}, 23 | \code{\link{f_detrend_linear}()}, 24 | \code{\link{f_detrend_poly}()}, 25 | \code{\link{f_hellinger}()}, 26 | \code{\link{f_log}()}, 27 | \code{\link{f_percent}()}, 28 | \code{\link{f_proportion}()}, 29 | \code{\link{f_proportion_sqrt}()}, 30 | \code{\link{f_rescale_global}()}, 31 | \code{\link{f_rescale_local}()}, 32 | \code{\link{f_scale_global}()}, 33 | \code{\link{f_scale_local}()}, 34 | \code{\link{f_trend_linear}()}, 35 | \code{\link{f_trend_poly}()} 36 | } 37 | \concept{tsl_transformation} 38 | -------------------------------------------------------------------------------- /man/f_log.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/transformations.R 3 | \name{f_log} 4 | \alias{f_log} 5 | \title{Data Transformation: Log} 6 | \usage{ 7 | f_log(x = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{x}{(required, zoo object) Zoo time series object to transform.} 11 | 12 | \item{...}{(optional, additional arguments) Ignored in this function.} 13 | } 14 | \value{ 15 | zoo object 16 | } 17 | \description{ 18 | Applies logarithmic transformation to data to reduce skewness. 19 | } 20 | \examples{ 21 | x <- zoo_simulate( 22 | cols = 5, 23 | data_range = c(0, 500) 24 | ) 25 | 26 | y <- f_log( 27 | x = x 28 | ) 29 | 30 | if(interactive()){ 31 | zoo_plot(x) 32 | zoo_plot(y) 33 | } 34 | } 35 | \seealso{ 36 | Other tsl_transformation: 37 | \code{\link{f_binary}()}, 38 | \code{\link{f_clr}()}, 39 | \code{\link{f_detrend_difference}()}, 40 | \code{\link{f_detrend_linear}()}, 41 | \code{\link{f_detrend_poly}()}, 42 | \code{\link{f_hellinger}()}, 43 | \code{\link{f_list}()}, 44 | \code{\link{f_percent}()}, 45 | \code{\link{f_proportion}()}, 46 | \code{\link{f_proportion_sqrt}()}, 47 | \code{\link{f_rescale_global}()}, 48 | \code{\link{f_rescale_local}()}, 49 | \code{\link{f_scale_global}()}, 50 | \code{\link{f_scale_local}()}, 51 | \code{\link{f_trend_linear}()}, 52 | \code{\link{f_trend_poly}()} 53 | } 54 | \concept{tsl_transformation} 55 | -------------------------------------------------------------------------------- /man/f_percent.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/transformations.R 3 | \name{f_percent} 4 | \alias{f_percent} 5 | \title{Data Transformation: Rowwise Percentages} 6 | \usage{ 7 | f_percent(x = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{x}{(required, zoo object) Zoo time series object to transform.} 11 | 12 | \item{...}{(optional, additional arguments) Ignored in this function.} 13 | } 14 | \value{ 15 | zoo object 16 | } 17 | \description{ 18 | Data Transformation: Rowwise Percentages 19 | } 20 | \examples{ 21 | x <- zoo_simulate(cols = 2) 22 | 23 | y <- f_percent( 24 | x = x 25 | ) 26 | 27 | if(interactive()){ 28 | zoo_plot(x) 29 | zoo_plot(y) 30 | } 31 | } 32 | \seealso{ 33 | Other tsl_transformation: 34 | \code{\link{f_binary}()}, 35 | \code{\link{f_clr}()}, 36 | \code{\link{f_detrend_difference}()}, 37 | \code{\link{f_detrend_linear}()}, 38 | \code{\link{f_detrend_poly}()}, 39 | \code{\link{f_hellinger}()}, 40 | \code{\link{f_list}()}, 41 | \code{\link{f_log}()}, 42 | \code{\link{f_proportion}()}, 43 | \code{\link{f_proportion_sqrt}()}, 44 | \code{\link{f_rescale_global}()}, 45 | \code{\link{f_rescale_local}()}, 46 | \code{\link{f_scale_global}()}, 47 | \code{\link{f_scale_local}()}, 48 | \code{\link{f_trend_linear}()}, 49 | \code{\link{f_trend_poly}()} 50 | } 51 | \concept{tsl_transformation} 52 | -------------------------------------------------------------------------------- /man/f_proportion.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/transformations.R 3 | \name{f_proportion} 4 | \alias{f_proportion} 5 | \title{Data Transformation: Rowwise Proportions} 6 | \usage{ 7 | f_proportion(x = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{x}{(required, zoo object) Zoo time series object to transform.} 11 | 12 | \item{...}{(optional, additional arguments) Ignored in this function.} 13 | } 14 | \value{ 15 | zoo object 16 | } 17 | \description{ 18 | Data Transformation: Rowwise Proportions 19 | } 20 | \examples{ 21 | x <- zoo_simulate(cols = 2) 22 | 23 | y <- f_proportion( 24 | x = x 25 | ) 26 | 27 | if(interactive()){ 28 | zoo_plot(x) 29 | zoo_plot(y) 30 | } 31 | } 32 | \seealso{ 33 | Other tsl_transformation: 34 | \code{\link{f_binary}()}, 35 | \code{\link{f_clr}()}, 36 | \code{\link{f_detrend_difference}()}, 37 | \code{\link{f_detrend_linear}()}, 38 | \code{\link{f_detrend_poly}()}, 39 | \code{\link{f_hellinger}()}, 40 | \code{\link{f_list}()}, 41 | \code{\link{f_log}()}, 42 | \code{\link{f_percent}()}, 43 | \code{\link{f_proportion_sqrt}()}, 44 | \code{\link{f_rescale_global}()}, 45 | \code{\link{f_rescale_local}()}, 46 | \code{\link{f_scale_global}()}, 47 | \code{\link{f_scale_local}()}, 48 | \code{\link{f_trend_linear}()}, 49 | \code{\link{f_trend_poly}()} 50 | } 51 | \concept{tsl_transformation} 52 | -------------------------------------------------------------------------------- /man/f_proportion_sqrt.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/transformations.R 3 | \name{f_proportion_sqrt} 4 | \alias{f_proportion_sqrt} 5 | \title{Data Transformation: Rowwise Square Root of Proportions} 6 | \usage{ 7 | f_proportion_sqrt(x = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{x}{(required, zoo object) Zoo time series object to transform.} 11 | 12 | \item{...}{(optional, additional arguments) Ignored in this function.} 13 | } 14 | \value{ 15 | zoo object 16 | } 17 | \description{ 18 | Data Transformation: Rowwise Square Root of Proportions 19 | } 20 | \examples{ 21 | x <- zoo_simulate(cols = 2) 22 | 23 | y <- f_proportion_sqrt( 24 | x = x 25 | ) 26 | 27 | if(interactive()){ 28 | zoo_plot(x) 29 | zoo_plot(y) 30 | } 31 | } 32 | \seealso{ 33 | Other tsl_transformation: 34 | \code{\link{f_binary}()}, 35 | \code{\link{f_clr}()}, 36 | \code{\link{f_detrend_difference}()}, 37 | \code{\link{f_detrend_linear}()}, 38 | \code{\link{f_detrend_poly}()}, 39 | \code{\link{f_hellinger}()}, 40 | \code{\link{f_list}()}, 41 | \code{\link{f_log}()}, 42 | \code{\link{f_percent}()}, 43 | \code{\link{f_proportion}()}, 44 | \code{\link{f_rescale_global}()}, 45 | \code{\link{f_rescale_local}()}, 46 | \code{\link{f_scale_global}()}, 47 | \code{\link{f_scale_local}()}, 48 | \code{\link{f_trend_linear}()}, 49 | \code{\link{f_trend_poly}()} 50 | } 51 | \concept{tsl_transformation} 52 | -------------------------------------------------------------------------------- /man/f_trend_linear.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/transformations.R 3 | \name{f_trend_linear} 4 | \alias{f_trend_linear} 5 | \title{Data Transformation: Linear Trend of Zoo Time Series} 6 | \usage{ 7 | f_trend_linear(x = NULL, center = TRUE, ...) 8 | } 9 | \arguments{ 10 | \item{x}{(required, zoo object) Zoo time series object to transform.} 11 | 12 | \item{center}{(required, logical) If TRUE, the output is centered at zero. If FALSE, it is centered at the data mean. Default: TRUE} 13 | 14 | \item{...}{(optional, additional arguments) Ignored in this function.} 15 | } 16 | \value{ 17 | zoo object 18 | } 19 | \description{ 20 | Fits a linear model on each column of a zoo object using time as a predictor, and predicts the outcome. 21 | } 22 | \examples{ 23 | x <- zoo_simulate(cols = 2) 24 | 25 | y <- f_trend_linear( 26 | x = x 27 | ) 28 | 29 | if(interactive()){ 30 | zoo_plot(x) 31 | zoo_plot(y) 32 | } 33 | } 34 | \seealso{ 35 | Other tsl_transformation: 36 | \code{\link{f_binary}()}, 37 | \code{\link{f_clr}()}, 38 | \code{\link{f_detrend_difference}()}, 39 | \code{\link{f_detrend_linear}()}, 40 | \code{\link{f_detrend_poly}()}, 41 | \code{\link{f_hellinger}()}, 42 | \code{\link{f_list}()}, 43 | \code{\link{f_log}()}, 44 | \code{\link{f_percent}()}, 45 | \code{\link{f_proportion}()}, 46 | \code{\link{f_proportion_sqrt}()}, 47 | \code{\link{f_rescale_global}()}, 48 | \code{\link{f_rescale_local}()}, 49 | \code{\link{f_scale_global}()}, 50 | \code{\link{f_scale_local}()}, 51 | \code{\link{f_trend_poly}()} 52 | } 53 | \concept{tsl_transformation} 54 | -------------------------------------------------------------------------------- /man/fagus_coordinates.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{fagus_coordinates} 5 | \alias{fagus_coordinates} 6 | \title{Site Coordinates of Fagus sylvatica Stands} 7 | \format{ 8 | sf data frame with 3 rows and 4 columns 9 | } 10 | \usage{ 11 | data(fagus_coordinates) 12 | } 13 | \description{ 14 | Site Coordinates of Fagus sylvatica Stands 15 | } 16 | \seealso{ 17 | Other example_data: 18 | \code{\link{albatross}}, 19 | \code{\link{cities_coordinates}}, 20 | \code{\link{cities_temperature}}, 21 | \code{\link{covid_counties}}, 22 | \code{\link{covid_prevalence}}, 23 | \code{\link{eemian_coordinates}}, 24 | \code{\link{eemian_pollen}}, 25 | \code{\link{fagus_dynamics}}, 26 | \code{\link{honeycomb_climate}}, 27 | \code{\link{honeycomb_polygons}} 28 | } 29 | \concept{example_data} 30 | \keyword{datasets} 31 | -------------------------------------------------------------------------------- /man/fagus_dynamics.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{fagus_dynamics} 5 | \alias{fagus_dynamics} 6 | \title{Time Series Data from Three Fagus sylvatica Stands} 7 | \format{ 8 | data frame with 5 columns and 648 rows. 9 | } 10 | \usage{ 11 | data(fagus_dynamics) 12 | } 13 | \description{ 14 | A data frame with 648 rows representing enhanced vegetation index, rainfall and temperature in three stands of Fagus sylvatica in Spain, Germany, and Sweden. 15 | } 16 | \details{ 17 | Site coordinates for this dataset are in \link{fagus_coordinates}. 18 | } 19 | \examples{ 20 | data("fagus_dynamics") 21 | 22 | #to time series list 23 | fagus <- tsl_initialize( 24 | x = fagus_dynamics, 25 | name_column = "name", 26 | time_column = "time" 27 | ) 28 | 29 | #time series plot 30 | if(interactive()){ 31 | 32 | tsl_plot( 33 | tsl = fagus 34 | ) 35 | 36 | } 37 | 38 | } 39 | \seealso{ 40 | Other example_data: 41 | \code{\link{albatross}}, 42 | \code{\link{cities_coordinates}}, 43 | \code{\link{cities_temperature}}, 44 | \code{\link{covid_counties}}, 45 | \code{\link{covid_prevalence}}, 46 | \code{\link{eemian_coordinates}}, 47 | \code{\link{eemian_pollen}}, 48 | \code{\link{fagus_coordinates}}, 49 | \code{\link{honeycomb_climate}}, 50 | \code{\link{honeycomb_polygons}} 51 | } 52 | \concept{example_data} 53 | \keyword{datasets} 54 | -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-11-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/man/figures/README-unnamed-chunk-11-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-12-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/man/figures/README-unnamed-chunk-12-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-13-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/man/figures/README-unnamed-chunk-13-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-4-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/man/figures/README-unnamed-chunk-4-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/man/figures/README-unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/man/figures/README-unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/man/figures/README-unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/man/figures/README-unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-9-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/man/figures/README-unnamed-chunk-9-1.png -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/man/figures/logo.png -------------------------------------------------------------------------------- /man/honeycomb_climate.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{honeycomb_climate} 5 | \alias{honeycomb_climate} 6 | \title{Rainfall and Temperature in The Americas} 7 | \format{ 8 | An object of class \code{tbl_df} (inherits from \code{tbl}, \code{data.frame}) with 9432 rows and 4 columns. 9 | } 10 | \usage{ 11 | data(honeycomb_climate) 12 | } 13 | \description{ 14 | Monthly temperature and rainfall between 2009 and 2019 in 72 hexagonal cells covering The Americas. 15 | } 16 | \seealso{ 17 | Other example_data: 18 | \code{\link{albatross}}, 19 | \code{\link{cities_coordinates}}, 20 | \code{\link{cities_temperature}}, 21 | \code{\link{covid_counties}}, 22 | \code{\link{covid_prevalence}}, 23 | \code{\link{eemian_coordinates}}, 24 | \code{\link{eemian_pollen}}, 25 | \code{\link{fagus_coordinates}}, 26 | \code{\link{fagus_dynamics}}, 27 | \code{\link{honeycomb_polygons}} 28 | } 29 | \concept{example_data} 30 | \keyword{datasets} 31 | -------------------------------------------------------------------------------- /man/honeycomb_polygons.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/data.R 3 | \docType{data} 4 | \name{honeycomb_polygons} 5 | \alias{honeycomb_polygons} 6 | \title{Hexagonal Grid} 7 | \format{ 8 | An object of class \code{sf} (inherits from \code{data.frame}) with 72 rows and 2 columns. 9 | } 10 | \usage{ 11 | data(honeycomb_polygons) 12 | } 13 | \description{ 14 | Sf data frame with hexagonal grid of the dataset \link{honeycomb_climate}. 15 | } 16 | \seealso{ 17 | Other example_data: 18 | \code{\link{albatross}}, 19 | \code{\link{cities_coordinates}}, 20 | \code{\link{cities_temperature}}, 21 | \code{\link{covid_counties}}, 22 | \code{\link{covid_prevalence}}, 23 | \code{\link{eemian_coordinates}}, 24 | \code{\link{eemian_pollen}}, 25 | \code{\link{fagus_coordinates}}, 26 | \code{\link{fagus_dynamics}}, 27 | \code{\link{honeycomb_climate}} 28 | } 29 | \concept{example_data} 30 | \keyword{datasets} 31 | -------------------------------------------------------------------------------- /man/momentum_stats.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/momentum_stats.R 3 | \name{momentum_stats} 4 | \alias{momentum_stats} 5 | \title{Stats of Dissimilarity Data Frame} 6 | \usage{ 7 | momentum_stats(df = NULL) 8 | } 9 | \arguments{ 10 | \item{df}{(required, data frame) Output of \code{\link[=momentum]{momentum()}}, \code{\link[=momentum_ls]{momentum_ls()}}, or \code{\link[=momentum_dtw]{momentum_dtw()}}. Default: NULL} 11 | } 12 | \value{ 13 | data frame 14 | } 15 | \description{ 16 | Takes the output of \code{\link[=distantia]{distantia()}} to return a data frame with one row per time series with the stats of its dissimilarity scores with all other time series. 17 | } 18 | \examples{ 19 | tsl <- tsl_simulate( 20 | n = 5, 21 | irregular = FALSE 22 | ) 23 | 24 | df <- distantia( 25 | tsl = tsl, 26 | lock_step = TRUE 27 | ) 28 | 29 | df_stats <- distantia_stats(df = df) 30 | 31 | df_stats 32 | 33 | } 34 | \seealso{ 35 | Other momentum_support: 36 | \code{\link{momentum_aggregate}()}, 37 | \code{\link{momentum_boxplot}()}, 38 | \code{\link{momentum_model_frame}()}, 39 | \code{\link{momentum_spatial}()}, 40 | \code{\link{momentum_to_wide}()} 41 | } 42 | \concept{momentum_support} 43 | -------------------------------------------------------------------------------- /man/permute_free_by_row_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{permute_free_by_row_cpp} 4 | \alias{permute_free_by_row_cpp} 5 | \title{(C++) Unrestricted Permutation of Complete Rows} 6 | \usage{ 7 | permute_free_by_row_cpp(x, block_size, seed = 1L) 8 | } 9 | \arguments{ 10 | \item{x}{(required, numeric matrix). Numeric matrix to permute.} 11 | 12 | \item{block_size}{(optional, integer) this function ignores this argument and sets it to x.nrow().} 13 | 14 | \item{seed}{(optional, integer) random seed to use.} 15 | } 16 | \value{ 17 | numeric matrix 18 | } 19 | \description{ 20 | Unrestricted shuffling of rows within the whole sequence. 21 | } 22 | \seealso{ 23 | Other Rcpp_permutation: 24 | \code{\link{permute_free_cpp}()}, 25 | \code{\link{permute_restricted_by_row_cpp}()}, 26 | \code{\link{permute_restricted_cpp}()} 27 | } 28 | \concept{Rcpp_permutation} 29 | -------------------------------------------------------------------------------- /man/permute_free_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{permute_free_cpp} 4 | \alias{permute_free_cpp} 5 | \title{(C++) Unrestricted Permutation of Cases} 6 | \usage{ 7 | permute_free_cpp(x, block_size, seed = 1L) 8 | } 9 | \arguments{ 10 | \item{x}{(required, numeric matrix). Numeric matrix to permute.} 11 | 12 | \item{block_size}{(optional, integer) this function ignores this argument and sets it to x.nrow().} 13 | 14 | \item{seed}{(optional, integer) random seed to use.} 15 | } 16 | \value{ 17 | numeric matrix 18 | } 19 | \description{ 20 | Unrestricted shuffling of cases within the whole sequence. 21 | } 22 | \seealso{ 23 | Other Rcpp_permutation: 24 | \code{\link{permute_free_by_row_cpp}()}, 25 | \code{\link{permute_restricted_by_row_cpp}()}, 26 | \code{\link{permute_restricted_cpp}()} 27 | } 28 | \concept{Rcpp_permutation} 29 | -------------------------------------------------------------------------------- /man/permute_restricted_by_row_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{permute_restricted_by_row_cpp} 4 | \alias{permute_restricted_by_row_cpp} 5 | \title{(C++) Restricted Permutation of Complete Rows Within Blocks} 6 | \usage{ 7 | permute_restricted_by_row_cpp(x, block_size, seed = 1L) 8 | } 9 | \arguments{ 10 | \item{x}{(required, numeric matrix). Numeric matrix to permute.} 11 | 12 | \item{block_size}{(optional, integer) block size in number of rows. 13 | Minimum value is 2, and maximum value is nrow(x).} 14 | 15 | \item{seed}{(optional, integer) random seed to use.} 16 | } 17 | \value{ 18 | numeric matrix 19 | } 20 | \description{ 21 | Divides a sequence in blocks of a given size and permutes rows 22 | within these blocks. 23 | Larger block sizes increasingly disrupt the data structure over time. 24 | } 25 | \seealso{ 26 | Other Rcpp_permutation: 27 | \code{\link{permute_free_by_row_cpp}()}, 28 | \code{\link{permute_free_cpp}()}, 29 | \code{\link{permute_restricted_cpp}()} 30 | } 31 | \concept{Rcpp_permutation} 32 | -------------------------------------------------------------------------------- /man/permute_restricted_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{permute_restricted_cpp} 4 | \alias{permute_restricted_cpp} 5 | \title{(C++) Restricted Permutation of Cases Within Blocks} 6 | \usage{ 7 | permute_restricted_cpp(x, block_size, seed = 1L) 8 | } 9 | \arguments{ 10 | \item{x}{(required, numeric matrix). Numeric matrix to permute.} 11 | 12 | \item{block_size}{(optional, integer) block size in number of rows. 13 | Minimum value is 2, and maximum value is nrow(x).} 14 | 15 | \item{seed}{(optional, integer) random seed to use.} 16 | } 17 | \value{ 18 | numeric matrix 19 | } 20 | \description{ 21 | Divides a sequence or time series in blocks and permutes cases 22 | within these blocks. This function does not preserve rows, and should not be 23 | used if the sequence has dependent columns. 24 | Larger block sizes increasingly disrupt the data structure over time. 25 | } 26 | \seealso{ 27 | Other Rcpp_permutation: 28 | \code{\link{permute_free_by_row_cpp}()}, 29 | \code{\link{permute_free_cpp}()}, 30 | \code{\link{permute_restricted_by_row_cpp}()} 31 | } 32 | \concept{Rcpp_permutation} 33 | -------------------------------------------------------------------------------- /man/psi_auto_distance.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/psi_auto_distance.R 3 | \name{psi_auto_distance} 4 | \alias{psi_auto_distance} 5 | \title{Cumulative Sum of Distances Between Consecutive Cases in a Time Series} 6 | \usage{ 7 | psi_auto_distance(x = NULL, distance = "euclidean") 8 | } 9 | \arguments{ 10 | \item{x}{(required, zoo object or matrix) univariate or multivariate time series with no NAs. Default: NULL} 11 | 12 | \item{distance}{(optional, character vector) name or abbreviation of the distance method. Valid values are in the columns "names" and "abbreviation" of the dataset \link{distances}. Default: "euclidean".} 13 | } 14 | \value{ 15 | numeric value 16 | } 17 | \description{ 18 | Demonstration function to compute the sum of distances between consecutive cases in a time series. 19 | } 20 | \examples{ 21 | #distance metric 22 | d <- "euclidean" 23 | 24 | #simulate zoo time series 25 | x <- zoo_simulate( 26 | name = "x", 27 | rows = 100, 28 | seasons = 2, 29 | seed = 1 30 | ) 31 | 32 | #sum distance between consecutive samples 33 | psi_auto_distance( 34 | x = x, 35 | distance = d 36 | ) 37 | } 38 | \seealso{ 39 | Other psi_demo: 40 | \code{\link{psi_auto_sum}()}, 41 | \code{\link{psi_cost_matrix}()}, 42 | \code{\link{psi_cost_path}()}, 43 | \code{\link{psi_cost_path_sum}()}, 44 | \code{\link{psi_distance_lock_step}()}, 45 | \code{\link{psi_distance_matrix}()}, 46 | \code{\link{psi_equation}()} 47 | } 48 | \concept{psi_demo} 49 | -------------------------------------------------------------------------------- /man/psi_equation_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{psi_equation_cpp} 4 | \alias{psi_equation_cpp} 5 | \title{(C++) Equation of the Psi Dissimilarity Score} 6 | \usage{ 7 | psi_equation_cpp(a, b, diagonal = TRUE) 8 | } 9 | \arguments{ 10 | \item{a}{(required, numeric) output of \code{\link[=cost_path_sum_cpp]{cost_path_sum_cpp()}} on a least cost path.} 11 | 12 | \item{b}{(required, numeric) auto sum of both sequences, 13 | result of \code{\link[=auto_sum_cpp]{auto_sum_cpp()}}.} 14 | 15 | \item{diagonal}{(optional, logical). Must be TRUE when diagonals are used in 16 | dynamic time warping and for lock-step distances. Default: FALSE.} 17 | } 18 | \value{ 19 | numeric 20 | } 21 | \description{ 22 | Equation to compute the \code{psi} dissimilarity score 23 | (Birks and Gordon 1985). Psi is computed as \eqn{\psi = (2a / b) - 1}, 24 | where \eqn{a} is the sum of distances between the relevant samples of two 25 | time series, and \eqn{b} is the cumulative sum of distances between 26 | consecutive samples in the two time series. 27 | If \code{a} is computed with dynamic time warping, and diagonals are used in the 28 | computation of the least cost path, then one is added to the result of the equation above. 29 | } 30 | \seealso{ 31 | Other Rcpp_dissimilarity_analysis: 32 | \code{\link{psi_dtw_cpp}()}, 33 | \code{\link{psi_ls_cpp}()}, 34 | \code{\link{psi_null_dtw_cpp}()}, 35 | \code{\link{psi_null_ls_cpp}()} 36 | } 37 | \concept{Rcpp_dissimilarity_analysis} 38 | -------------------------------------------------------------------------------- /man/psi_ls_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{psi_ls_cpp} 4 | \alias{psi_ls_cpp} 5 | \title{(C++) Psi Dissimilarity Score of Two Aligned Time Series} 6 | \usage{ 7 | psi_ls_cpp(x, y, distance = "euclidean") 8 | } 9 | \arguments{ 10 | \item{x}{(required, numeric matrix) of same number of columns as 'y'.} 11 | 12 | \item{y}{(required, numeric matrix) of same number of columns as 'x'.} 13 | 14 | \item{distance}{(optional, character string) distance name from the "names" 15 | column of the dataset \code{distances} (see \code{distances$name}). Default: "euclidean".} 16 | } 17 | \value{ 18 | numeric 19 | } 20 | \description{ 21 | Computes the psi dissimilarity score between two time series 22 | observed at the same times. Time series \code{y} and \code{x} with the same 23 | number of columns and rows. NA values should be removed before using this function. 24 | If the selected distance function is "chi" or "cosine", pairs of zeros should 25 | be either removed or replaced with pseudo-zeros (i.e. 0.00001). 26 | } 27 | \seealso{ 28 | Other Rcpp_dissimilarity_analysis: 29 | \code{\link{psi_dtw_cpp}()}, 30 | \code{\link{psi_equation_cpp}()}, 31 | \code{\link{psi_null_dtw_cpp}()}, 32 | \code{\link{psi_null_ls_cpp}()} 33 | } 34 | \concept{Rcpp_dissimilarity_analysis} 35 | -------------------------------------------------------------------------------- /man/subset_matrix_by_rows_cpp.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RcppExports.R 3 | \name{subset_matrix_by_rows_cpp} 4 | \alias{subset_matrix_by_rows_cpp} 5 | \title{(C++) Subset Matrix by Rows} 6 | \usage{ 7 | subset_matrix_by_rows_cpp(m, rows) 8 | } 9 | \arguments{ 10 | \item{m}{(required, numeric matrix) a univariate or multivariate time series.} 11 | 12 | \item{rows}{(required, integer vector) vector of rows to subset from a 13 | least-cost path data frame.} 14 | } 15 | \value{ 16 | numeric matrix 17 | } 18 | \description{ 19 | Subsets a time series matrix to the coordinates of a trimmed 20 | least-cost path when blocks are ignored during a dissimilarity analysis. 21 | } 22 | \examples{ 23 | #simulate a time series 24 | m <- zoo_simulate(seed = 1) 25 | 26 | #sample some rows 27 | rows <- sample( 28 | x = nrow(m), 29 | size = 10 30 | ) |> 31 | sort() 32 | 33 | #subset by rows 34 | m_subset <- subset_matrix_by_rows_cpp( 35 | m = m, 36 | rows = rows 37 | ) 38 | 39 | #compare with original 40 | m[rows, ] 41 | 42 | } 43 | \seealso{ 44 | Other Rcpp_auto_sum: 45 | \code{\link{auto_distance_cpp}()}, 46 | \code{\link{auto_sum_cpp}()}, 47 | \code{\link{auto_sum_full_cpp}()}, 48 | \code{\link{auto_sum_path_cpp}()} 49 | } 50 | \concept{Rcpp_auto_sum} 51 | -------------------------------------------------------------------------------- /man/tsl_colnames_prefix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tsl_colnames.R 3 | \name{tsl_colnames_prefix} 4 | \alias{tsl_colnames_prefix} 5 | \title{Append Prefix to Column Names of Time Series List} 6 | \usage{ 7 | tsl_colnames_prefix(tsl = NULL, prefix = NULL) 8 | } 9 | \arguments{ 10 | \item{tsl}{(required, list) Time series list. Default: NULL} 11 | 12 | \item{prefix}{(optional, character string) String to prepend to the column names. Default: NULL.} 13 | } 14 | \value{ 15 | time series list 16 | } 17 | \description{ 18 | Append Prefix to Column Names of Time Series List 19 | } 20 | \examples{ 21 | tsl <- tsl_simulate() 22 | 23 | tsl_colnames_get(tsl = tsl) 24 | 25 | tsl <- tsl_colnames_prefix( 26 | tsl = tsl, 27 | prefix = "my_prefix_" 28 | ) 29 | 30 | tsl_colnames_get(tsl = tsl) 31 | } 32 | \seealso{ 33 | Other tsl_management: 34 | \code{\link{tsl_burst}()}, 35 | \code{\link{tsl_colnames_clean}()}, 36 | \code{\link{tsl_colnames_get}()}, 37 | \code{\link{tsl_colnames_set}()}, 38 | \code{\link{tsl_colnames_suffix}()}, 39 | \code{\link{tsl_count_NA}()}, 40 | \code{\link{tsl_diagnose}()}, 41 | \code{\link{tsl_handle_NA}()}, 42 | \code{\link{tsl_join}()}, 43 | \code{\link{tsl_names_clean}()}, 44 | \code{\link{tsl_names_get}()}, 45 | \code{\link{tsl_names_set}()}, 46 | \code{\link{tsl_names_test}()}, 47 | \code{\link{tsl_ncol}()}, 48 | \code{\link{tsl_nrow}()}, 49 | \code{\link{tsl_repair}()}, 50 | \code{\link{tsl_subset}()}, 51 | \code{\link{tsl_time}()}, 52 | \code{\link{tsl_to_df}()} 53 | } 54 | \concept{tsl_management} 55 | -------------------------------------------------------------------------------- /man/tsl_colnames_suffix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tsl_colnames.R 3 | \name{tsl_colnames_suffix} 4 | \alias{tsl_colnames_suffix} 5 | \title{Append Suffix to Column Names of Time Series List} 6 | \usage{ 7 | tsl_colnames_suffix(tsl = NULL, suffix = NULL) 8 | } 9 | \arguments{ 10 | \item{tsl}{(required, list) Time series list. Default: NULL} 11 | 12 | \item{suffix}{(optional, character string) String to append to the column names. Default: NULL.} 13 | } 14 | \value{ 15 | time series list 16 | } 17 | \description{ 18 | Append Suffix to Column Names of Time Series List 19 | } 20 | \examples{ 21 | tsl <- tsl_simulate() 22 | 23 | tsl_colnames_get(tsl = tsl) 24 | 25 | tsl <- tsl_colnames_suffix( 26 | tsl = tsl, 27 | suffix = "_my_suffix" 28 | ) 29 | 30 | tsl_colnames_get(tsl = tsl) 31 | } 32 | \seealso{ 33 | Other tsl_management: 34 | \code{\link{tsl_burst}()}, 35 | \code{\link{tsl_colnames_clean}()}, 36 | \code{\link{tsl_colnames_get}()}, 37 | \code{\link{tsl_colnames_prefix}()}, 38 | \code{\link{tsl_colnames_set}()}, 39 | \code{\link{tsl_count_NA}()}, 40 | \code{\link{tsl_diagnose}()}, 41 | \code{\link{tsl_handle_NA}()}, 42 | \code{\link{tsl_join}()}, 43 | \code{\link{tsl_names_clean}()}, 44 | \code{\link{tsl_names_get}()}, 45 | \code{\link{tsl_names_set}()}, 46 | \code{\link{tsl_names_test}()}, 47 | \code{\link{tsl_ncol}()}, 48 | \code{\link{tsl_nrow}()}, 49 | \code{\link{tsl_repair}()}, 50 | \code{\link{tsl_subset}()}, 51 | \code{\link{tsl_time}()}, 52 | \code{\link{tsl_to_df}()} 53 | } 54 | \concept{tsl_management} 55 | -------------------------------------------------------------------------------- /man/tsl_ncol.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tsl_ncol.R 3 | \name{tsl_ncol} 4 | \alias{tsl_ncol} 5 | \title{Get Number of Columns in Time Series Lists} 6 | \usage{ 7 | tsl_ncol(tsl = NULL) 8 | } 9 | \arguments{ 10 | \item{tsl}{(required, list) Time series list. Default: NULL} 11 | } 12 | \value{ 13 | list 14 | } 15 | \description{ 16 | Get Number of Columns in Time Series Lists 17 | } 18 | \examples{ 19 | #initialize time series list 20 | tsl <- tsl_simulate( 21 | n = 2, 22 | cols = 6 23 | ) 24 | 25 | #number of columns per zoo object 26 | tsl_ncol(tsl = tsl) 27 | } 28 | \seealso{ 29 | Other tsl_management: 30 | \code{\link{tsl_burst}()}, 31 | \code{\link{tsl_colnames_clean}()}, 32 | \code{\link{tsl_colnames_get}()}, 33 | \code{\link{tsl_colnames_prefix}()}, 34 | \code{\link{tsl_colnames_set}()}, 35 | \code{\link{tsl_colnames_suffix}()}, 36 | \code{\link{tsl_count_NA}()}, 37 | \code{\link{tsl_diagnose}()}, 38 | \code{\link{tsl_handle_NA}()}, 39 | \code{\link{tsl_join}()}, 40 | \code{\link{tsl_names_clean}()}, 41 | \code{\link{tsl_names_get}()}, 42 | \code{\link{tsl_names_set}()}, 43 | \code{\link{tsl_names_test}()}, 44 | \code{\link{tsl_nrow}()}, 45 | \code{\link{tsl_repair}()}, 46 | \code{\link{tsl_subset}()}, 47 | \code{\link{tsl_time}()}, 48 | \code{\link{tsl_to_df}()} 49 | } 50 | \concept{tsl_management} 51 | -------------------------------------------------------------------------------- /man/tsl_nrow.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tsl_nrow.R 3 | \name{tsl_nrow} 4 | \alias{tsl_nrow} 5 | \title{Get Number of Rows in Time Series Lists} 6 | \usage{ 7 | tsl_nrow(tsl = NULL) 8 | } 9 | \arguments{ 10 | \item{tsl}{(required, list) Time series list. Default: NULL} 11 | } 12 | \value{ 13 | list 14 | } 15 | \description{ 16 | Get Number of Rows in Time Series Lists 17 | } 18 | \examples{ 19 | #simulate zoo time series 20 | tsl <- tsl_simulate( 21 | rows = 150 22 | ) 23 | 24 | #count rows 25 | tsl_nrow( 26 | tsl = tsl 27 | ) 28 | } 29 | \seealso{ 30 | Other tsl_management: 31 | \code{\link{tsl_burst}()}, 32 | \code{\link{tsl_colnames_clean}()}, 33 | \code{\link{tsl_colnames_get}()}, 34 | \code{\link{tsl_colnames_prefix}()}, 35 | \code{\link{tsl_colnames_set}()}, 36 | \code{\link{tsl_colnames_suffix}()}, 37 | \code{\link{tsl_count_NA}()}, 38 | \code{\link{tsl_diagnose}()}, 39 | \code{\link{tsl_handle_NA}()}, 40 | \code{\link{tsl_join}()}, 41 | \code{\link{tsl_names_clean}()}, 42 | \code{\link{tsl_names_get}()}, 43 | \code{\link{tsl_names_set}()}, 44 | \code{\link{tsl_names_test}()}, 45 | \code{\link{tsl_ncol}()}, 46 | \code{\link{tsl_repair}()}, 47 | \code{\link{tsl_subset}()}, 48 | \code{\link{tsl_time}()}, 49 | \code{\link{tsl_to_df}()} 50 | } 51 | \concept{tsl_management} 52 | -------------------------------------------------------------------------------- /man/tsl_to_df.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/tsl_to_df.R 3 | \name{tsl_to_df} 4 | \alias{tsl_to_df} 5 | \title{Transform Time Series List to Data Frame} 6 | \usage{ 7 | tsl_to_df(tsl = NULL) 8 | } 9 | \arguments{ 10 | \item{tsl}{(required, list) Time series list. Default: NULL} 11 | } 12 | \value{ 13 | data frame 14 | } 15 | \description{ 16 | Transform Time Series List to Data Frame 17 | } 18 | \examples{ 19 | 20 | tsl <- tsl_simulate( 21 | n = 3, 22 | rows = 10, 23 | time_range = c( 24 | "2010-01-01", 25 | "2020-01-01" 26 | ), 27 | irregular = FALSE 28 | ) 29 | 30 | df <- tsl_to_df( 31 | tsl = tsl 32 | ) 33 | 34 | names(df) 35 | nrow(df) 36 | head(df) 37 | } 38 | \seealso{ 39 | Other tsl_management: 40 | \code{\link{tsl_burst}()}, 41 | \code{\link{tsl_colnames_clean}()}, 42 | \code{\link{tsl_colnames_get}()}, 43 | \code{\link{tsl_colnames_prefix}()}, 44 | \code{\link{tsl_colnames_set}()}, 45 | \code{\link{tsl_colnames_suffix}()}, 46 | \code{\link{tsl_count_NA}()}, 47 | \code{\link{tsl_diagnose}()}, 48 | \code{\link{tsl_handle_NA}()}, 49 | \code{\link{tsl_join}()}, 50 | \code{\link{tsl_names_clean}()}, 51 | \code{\link{tsl_names_get}()}, 52 | \code{\link{tsl_names_set}()}, 53 | \code{\link{tsl_names_test}()}, 54 | \code{\link{tsl_ncol}()}, 55 | \code{\link{tsl_nrow}()}, 56 | \code{\link{tsl_repair}()}, 57 | \code{\link{tsl_subset}()}, 58 | \code{\link{tsl_time}()} 59 | } 60 | \concept{tsl_management} 61 | -------------------------------------------------------------------------------- /man/utils_block_size.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils_block_size.R 3 | \name{utils_block_size} 4 | \alias{utils_block_size} 5 | \title{Default Block Size for Restricted Permutation in Dissimilarity Analyses} 6 | \usage{ 7 | utils_block_size(tsl = NULL, block_size = NULL) 8 | } 9 | \arguments{ 10 | \item{tsl}{(required, list) Time series list. Default: NULL} 11 | 12 | \item{block_size}{(optional, integer vector) Row block sizes for restricted permutation tests. Only relevant when permutation methods are "restricted" or "restricted_by_row". A block of size \code{n} indicates that a row can only be permuted within a block of \code{n} adjacent rows. If NULL, defaults to the 20\% rows of the shortest time series in \code{tsl}. Minimum value is 2, and maximum value is 50\% rows of the shortest time series in \code{tsl}. Default: NULL.} 13 | } 14 | \value{ 15 | integer 16 | } 17 | \description{ 18 | Default Block Size for Restricted Permutation in Dissimilarity Analyses 19 | } 20 | \seealso{ 21 | Other distantia_support: 22 | \code{\link{distantia_aggregate}()}, 23 | \code{\link{distantia_boxplot}()}, 24 | \code{\link{distantia_cluster_hclust}()}, 25 | \code{\link{distantia_cluster_kmeans}()}, 26 | \code{\link{distantia_matrix}()}, 27 | \code{\link{distantia_model_frame}()}, 28 | \code{\link{distantia_spatial}()}, 29 | \code{\link{distantia_stats}()}, 30 | \code{\link{distantia_time_delay}()}, 31 | \code{\link{utils_cluster_hclust_optimizer}()}, 32 | \code{\link{utils_cluster_kmeans_optimizer}()}, 33 | \code{\link{utils_cluster_silhouette}()} 34 | } 35 | \concept{distantia_support} 36 | -------------------------------------------------------------------------------- /man/utils_check_args_matrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils_check_args.R 3 | \name{utils_check_args_matrix} 4 | \alias{utils_check_args_matrix} 5 | \title{Checks Input Matrix} 6 | \usage{ 7 | utils_check_args_matrix(m = NULL, arg_name = "m") 8 | } 9 | \arguments{ 10 | \item{m}{(required, matrix) distance or cost matrix resulting from \code{\link[=psi_distance_matrix]{psi_distance_matrix()}} or \code{\link[=psi_cost_matrix]{psi_cost_matrix()}}. Default: NULL} 11 | 12 | \item{arg_name}{(optional, character string) name of the argument being checked. Default: NULL} 13 | } 14 | \value{ 15 | matrix 16 | } 17 | \description{ 18 | Checks Input Matrix 19 | } 20 | \seealso{ 21 | Other internal: 22 | \code{\link{utils_boxplot_common}()}, 23 | \code{\link{utils_check_args_distantia}()}, 24 | \code{\link{utils_check_args_momentum}()}, 25 | \code{\link{utils_check_args_path}()}, 26 | \code{\link{utils_check_args_tsl}()}, 27 | \code{\link{utils_check_args_zoo}()}, 28 | \code{\link{utils_check_distance_args}()}, 29 | \code{\link{utils_check_list_class}()}, 30 | \code{\link{utils_clean_names}()}, 31 | \code{\link{utils_digits}()}, 32 | \code{\link{utils_distantia_df_split}()}, 33 | \code{\link{utils_prepare_df}()}, 34 | \code{\link{utils_prepare_matrix}()}, 35 | \code{\link{utils_prepare_matrix_list}()}, 36 | \code{\link{utils_prepare_time}()}, 37 | \code{\link{utils_prepare_vector_list}()}, 38 | \code{\link{utils_prepare_zoo_list}()}, 39 | \code{\link{utils_tsl_pairs}()} 40 | } 41 | \concept{internal} 42 | -------------------------------------------------------------------------------- /man/utils_check_args_path.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils_check_args.R 3 | \name{utils_check_args_path} 4 | \alias{utils_check_args_path} 5 | \title{Checks Least Cost Path} 6 | \usage{ 7 | utils_check_args_path(path = NULL, arg_name = "path") 8 | } 9 | \arguments{ 10 | \item{path}{(required, data frame) least cost path generated with \code{\link[=psi_cost_path]{psi_cost_path()}}. This data frame must have the attribute \verb{type == "cost_path}, and must have been computed from the same time series used to compute the matrix \code{m}. Default: NULL.} 11 | 12 | \item{arg_name}{(optional, character string) name of the argument being checked. Default: NULL} 13 | } 14 | \value{ 15 | data frame 16 | } 17 | \description{ 18 | Checks Least Cost Path 19 | } 20 | \seealso{ 21 | Other internal: 22 | \code{\link{utils_boxplot_common}()}, 23 | \code{\link{utils_check_args_distantia}()}, 24 | \code{\link{utils_check_args_matrix}()}, 25 | \code{\link{utils_check_args_momentum}()}, 26 | \code{\link{utils_check_args_tsl}()}, 27 | \code{\link{utils_check_args_zoo}()}, 28 | \code{\link{utils_check_distance_args}()}, 29 | \code{\link{utils_check_list_class}()}, 30 | \code{\link{utils_clean_names}()}, 31 | \code{\link{utils_digits}()}, 32 | \code{\link{utils_distantia_df_split}()}, 33 | \code{\link{utils_prepare_df}()}, 34 | \code{\link{utils_prepare_matrix}()}, 35 | \code{\link{utils_prepare_matrix_list}()}, 36 | \code{\link{utils_prepare_time}()}, 37 | \code{\link{utils_prepare_vector_list}()}, 38 | \code{\link{utils_prepare_zoo_list}()}, 39 | \code{\link{utils_tsl_pairs}()} 40 | } 41 | \concept{internal} 42 | -------------------------------------------------------------------------------- /man/utils_check_args_tsl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils_check_args.R 3 | \name{utils_check_args_tsl} 4 | \alias{utils_check_args_tsl} 5 | \title{Structural Check for Time Series Lists} 6 | \usage{ 7 | utils_check_args_tsl(tsl = NULL, min_length = 2) 8 | } 9 | \arguments{ 10 | \item{tsl}{(required, list) list of zoo objects. Default: NULL} 11 | 12 | \item{min_length}{(required, positive integer) minimum number of zoo objects in \code{tsl}. Default: 2} 13 | } 14 | \value{ 15 | error messages (if any) 16 | } 17 | \description{ 18 | Internal function to check that a time series list is a list of zoo objects and has a minimum number of objects. For a more comprehensive test, use \code{\link[=tsl_diagnose]{tsl_diagnose()}}. 19 | } 20 | \seealso{ 21 | Other internal: 22 | \code{\link{utils_boxplot_common}()}, 23 | \code{\link{utils_check_args_distantia}()}, 24 | \code{\link{utils_check_args_matrix}()}, 25 | \code{\link{utils_check_args_momentum}()}, 26 | \code{\link{utils_check_args_path}()}, 27 | \code{\link{utils_check_args_zoo}()}, 28 | \code{\link{utils_check_distance_args}()}, 29 | \code{\link{utils_check_list_class}()}, 30 | \code{\link{utils_clean_names}()}, 31 | \code{\link{utils_digits}()}, 32 | \code{\link{utils_distantia_df_split}()}, 33 | \code{\link{utils_prepare_df}()}, 34 | \code{\link{utils_prepare_matrix}()}, 35 | \code{\link{utils_prepare_matrix_list}()}, 36 | \code{\link{utils_prepare_time}()}, 37 | \code{\link{utils_prepare_vector_list}()}, 38 | \code{\link{utils_prepare_zoo_list}()}, 39 | \code{\link{utils_tsl_pairs}()} 40 | } 41 | \concept{internal} 42 | -------------------------------------------------------------------------------- /man/utils_check_args_zoo.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils_check_args.R 3 | \name{utils_check_args_zoo} 4 | \alias{utils_check_args_zoo} 5 | \title{Checks Argument x} 6 | \usage{ 7 | utils_check_args_zoo(x = NULL, arg_name = "x") 8 | } 9 | \arguments{ 10 | \item{x}{(required, zoo object) zoo time series. Default: NULL} 11 | 12 | \item{arg_name}{(optional, character string) name of the argument being checked. Default: NULL} 13 | } 14 | \value{ 15 | zoo object 16 | } 17 | \description{ 18 | Checks Argument x 19 | } 20 | \seealso{ 21 | Other internal: 22 | \code{\link{utils_boxplot_common}()}, 23 | \code{\link{utils_check_args_distantia}()}, 24 | \code{\link{utils_check_args_matrix}()}, 25 | \code{\link{utils_check_args_momentum}()}, 26 | \code{\link{utils_check_args_path}()}, 27 | \code{\link{utils_check_args_tsl}()}, 28 | \code{\link{utils_check_distance_args}()}, 29 | \code{\link{utils_check_list_class}()}, 30 | \code{\link{utils_clean_names}()}, 31 | \code{\link{utils_digits}()}, 32 | \code{\link{utils_distantia_df_split}()}, 33 | \code{\link{utils_prepare_df}()}, 34 | \code{\link{utils_prepare_matrix}()}, 35 | \code{\link{utils_prepare_matrix_list}()}, 36 | \code{\link{utils_prepare_time}()}, 37 | \code{\link{utils_prepare_vector_list}()}, 38 | \code{\link{utils_prepare_zoo_list}()}, 39 | \code{\link{utils_tsl_pairs}()} 40 | } 41 | \concept{internal} 42 | -------------------------------------------------------------------------------- /man/utils_check_distance_args.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils_check_args.R 3 | \name{utils_check_distance_args} 4 | \alias{utils_check_distance_args} 5 | \title{Check Distance Argument} 6 | \usage{ 7 | utils_check_distance_args(distance = NULL) 8 | } 9 | \arguments{ 10 | \item{distance}{(optional, character vector) name or abbreviation of the distance method. Valid values are in the columns "names" and "abbreviation" of the dataset \code{distances}. Default: "euclidean".} 11 | } 12 | \value{ 13 | character vector 14 | } 15 | \description{ 16 | Check Distance Argument 17 | } 18 | \examples{ 19 | 20 | utils_check_distance_args( 21 | distance = c( 22 | "euclidean", 23 | "euc" 24 | ) 25 | ) 26 | } 27 | \seealso{ 28 | Other internal: 29 | \code{\link{utils_boxplot_common}()}, 30 | \code{\link{utils_check_args_distantia}()}, 31 | \code{\link{utils_check_args_matrix}()}, 32 | \code{\link{utils_check_args_momentum}()}, 33 | \code{\link{utils_check_args_path}()}, 34 | \code{\link{utils_check_args_tsl}()}, 35 | \code{\link{utils_check_args_zoo}()}, 36 | \code{\link{utils_check_list_class}()}, 37 | \code{\link{utils_clean_names}()}, 38 | \code{\link{utils_digits}()}, 39 | \code{\link{utils_distantia_df_split}()}, 40 | \code{\link{utils_prepare_df}()}, 41 | \code{\link{utils_prepare_matrix}()}, 42 | \code{\link{utils_prepare_matrix_list}()}, 43 | \code{\link{utils_prepare_time}()}, 44 | \code{\link{utils_prepare_vector_list}()}, 45 | \code{\link{utils_prepare_zoo_list}()}, 46 | \code{\link{utils_tsl_pairs}()} 47 | } 48 | \concept{internal} 49 | -------------------------------------------------------------------------------- /man/utils_check_list_class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils_check_list_class.R 3 | \name{utils_check_list_class} 4 | \alias{utils_check_list_class} 5 | \title{Checks Classes of List Elements Against Expectation} 6 | \usage{ 7 | utils_check_list_class(x = NULL, expected_class = "data.frame") 8 | } 9 | \arguments{ 10 | \item{x}{(required, list) Default: NULL} 11 | 12 | \item{expected_class}{(required, class name). One of "data.frame", "matrix", or "vector". Default: "data.frame".} 13 | } 14 | \value{ 15 | side effects 16 | } 17 | \description{ 18 | Checks Classes of List Elements Against Expectation 19 | } 20 | \seealso{ 21 | Other internal: 22 | \code{\link{utils_boxplot_common}()}, 23 | \code{\link{utils_check_args_distantia}()}, 24 | \code{\link{utils_check_args_matrix}()}, 25 | \code{\link{utils_check_args_momentum}()}, 26 | \code{\link{utils_check_args_path}()}, 27 | \code{\link{utils_check_args_tsl}()}, 28 | \code{\link{utils_check_args_zoo}()}, 29 | \code{\link{utils_check_distance_args}()}, 30 | \code{\link{utils_clean_names}()}, 31 | \code{\link{utils_digits}()}, 32 | \code{\link{utils_distantia_df_split}()}, 33 | \code{\link{utils_prepare_df}()}, 34 | \code{\link{utils_prepare_matrix}()}, 35 | \code{\link{utils_prepare_matrix_list}()}, 36 | \code{\link{utils_prepare_time}()}, 37 | \code{\link{utils_prepare_vector_list}()}, 38 | \code{\link{utils_prepare_zoo_list}()}, 39 | \code{\link{utils_tsl_pairs}()} 40 | } 41 | \concept{internal} 42 | -------------------------------------------------------------------------------- /man/utils_coerce_time_class.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils_coerce_time_class.R 3 | \name{utils_coerce_time_class} 4 | \alias{utils_coerce_time_class} 5 | \title{Coerces Vector to a Given Time Class} 6 | \usage{ 7 | utils_coerce_time_class(x = NULL, to = "POSIXct") 8 | } 9 | \arguments{ 10 | \item{x}{(required, vector of class Date or POSIXct) time vector to convert. Default: NULL} 11 | 12 | \item{to}{(required, class name) class to coerce \code{x} to. Either "Date", "POSIXct", "integer" or "numeric". Default: "POSIXct"} 13 | } 14 | \value{ 15 | time vector 16 | } 17 | \description{ 18 | Coerces Vector to a Given Time Class 19 | } 20 | \examples{ 21 | x <- utils_coerce_time_class( 22 | x = c("2024-01-01", "2024-02-01"), 23 | to = "Date" 24 | ) 25 | 26 | x 27 | class(x) 28 | 29 | x <- utils_coerce_time_class( 30 | x = c("2024-01-01", "2024-02-01"), 31 | to = "POSIXct" 32 | ) 33 | 34 | x 35 | class(x) 36 | 37 | x <- utils_coerce_time_class( 38 | x = c("2024-01-01", "2024-02-01"), 39 | to = "numeric" 40 | ) 41 | 42 | x 43 | class(x) 44 | } 45 | \seealso{ 46 | Other internal_time_handling: 47 | \code{\link{utils_as_time}()}, 48 | \code{\link{utils_is_time}()}, 49 | \code{\link{utils_new_time}()}, 50 | \code{\link{utils_time_keywords}()}, 51 | \code{\link{utils_time_keywords_dictionary}()}, 52 | \code{\link{utils_time_keywords_translate}()}, 53 | \code{\link{utils_time_units}()} 54 | } 55 | \concept{internal_time_handling} 56 | -------------------------------------------------------------------------------- /man/utils_color_breaks.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils_color_breaks.R 3 | \name{utils_color_breaks} 4 | \alias{utils_color_breaks} 5 | \title{Auto Breaks for Matrix Plotting Functions} 6 | \usage{ 7 | utils_color_breaks(m = NULL, n = 100) 8 | } 9 | \arguments{ 10 | \item{m}{(required, numeric matrix) distance or cost matrix generated by \code{\link[=psi_distance_matrix]{psi_distance_matrix()}} or \code{\link[=psi_cost_matrix]{psi_cost_matrix()}}, but any numeric matrix will work. Default: NULL} 11 | 12 | \item{n}{(required, integer) number of colors to compute the breaks for. Default: 100} 13 | } 14 | \value{ 15 | numeric vector 16 | } 17 | \description{ 18 | Auto Breaks for Matrix Plotting Functions 19 | } 20 | \seealso{ 21 | Other internal_plotting: 22 | \code{\link{color_continuous}()}, 23 | \code{\link{color_discrete}()}, 24 | \code{\link{utils_line_color}()}, 25 | \code{\link{utils_line_guide}()}, 26 | \code{\link{utils_matrix_guide}()}, 27 | \code{\link{utils_matrix_plot}()} 28 | } 29 | \concept{internal_plotting} 30 | -------------------------------------------------------------------------------- /man/utils_digits.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils_digits.R 3 | \name{utils_digits} 4 | \alias{utils_digits} 5 | \title{Number of Decimal Places} 6 | \usage{ 7 | utils_digits(x = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{(required, numeric) Default: NULL} 11 | } 12 | \value{ 13 | integer 14 | } 15 | \description{ 16 | Number of Decimal Places 17 | } 18 | \examples{ 19 | utils_digits(x = 0.234) 20 | } 21 | \seealso{ 22 | Other internal: 23 | \code{\link{utils_boxplot_common}()}, 24 | \code{\link{utils_check_args_distantia}()}, 25 | \code{\link{utils_check_args_matrix}()}, 26 | \code{\link{utils_check_args_momentum}()}, 27 | \code{\link{utils_check_args_path}()}, 28 | \code{\link{utils_check_args_tsl}()}, 29 | \code{\link{utils_check_args_zoo}()}, 30 | \code{\link{utils_check_distance_args}()}, 31 | \code{\link{utils_check_list_class}()}, 32 | \code{\link{utils_clean_names}()}, 33 | \code{\link{utils_distantia_df_split}()}, 34 | \code{\link{utils_prepare_df}()}, 35 | \code{\link{utils_prepare_matrix}()}, 36 | \code{\link{utils_prepare_matrix_list}()}, 37 | \code{\link{utils_prepare_time}()}, 38 | \code{\link{utils_prepare_vector_list}()}, 39 | \code{\link{utils_prepare_zoo_list}()}, 40 | \code{\link{utils_tsl_pairs}()} 41 | } 42 | \concept{internal} 43 | -------------------------------------------------------------------------------- /man/utils_drop_geometry.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils_drop_geometry.R 3 | \name{utils_drop_geometry} 4 | \alias{utils_drop_geometry} 5 | \title{Removes Geometry Column from SF Data Frames} 6 | \usage{ 7 | utils_drop_geometry(df = NULL) 8 | } 9 | \arguments{ 10 | \item{df}{(required, data frame) Input data frame. Default: NULL.} 11 | } 12 | \value{ 13 | data frame 14 | } 15 | \description{ 16 | Replicates the functionality of \code{sf::st_drop_geometry()} without depending on the \code{sf} package. 17 | } 18 | \seealso{ 19 | Other tsl_processing_internal: 20 | \code{\link{utils_global_scaling_params}()}, 21 | \code{\link{utils_optimize_loess}()}, 22 | \code{\link{utils_optimize_spline}()}, 23 | \code{\link{utils_rescale_vector}()} 24 | } 25 | \concept{tsl_processing_internal} 26 | -------------------------------------------------------------------------------- /man/utils_global_scaling_params.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils_global_scaling_params.R 3 | \name{utils_global_scaling_params} 4 | \alias{utils_global_scaling_params} 5 | \title{Global Centering and Scaling Parameters of Time Series Lists} 6 | \usage{ 7 | utils_global_scaling_params(tsl = NULL, f = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{tsl}{(required, list) Time series list. Default: NULL} 11 | 12 | \item{f}{(required, function) function \code{\link[=f_scale_global]{f_scale_global()}}. Default: NULL} 13 | 14 | \item{...}{(optional, arguments of \code{f}) Optional arguments for the transformation function.} 15 | } 16 | \value{ 17 | list 18 | } 19 | \description{ 20 | Internal function to compute global scaling parameters (mean and standard deviation) for time series lists. Used within \code{\link[=tsl_transform]{tsl_transform()}} when the scaling function \code{\link[=f_scale_global]{f_scale_global()}} is used as input for the argument \code{f}. 21 | 22 | Warning: this function removes exclusive columns from the data. See function \code{\link[=tsl_subset]{tsl_subset()}}. 23 | } 24 | \seealso{ 25 | Other tsl_processing_internal: 26 | \code{\link{utils_drop_geometry}()}, 27 | \code{\link{utils_optimize_loess}()}, 28 | \code{\link{utils_optimize_spline}()}, 29 | \code{\link{utils_rescale_vector}()} 30 | } 31 | \concept{tsl_processing_internal} 32 | -------------------------------------------------------------------------------- /man/utils_is_time.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils_is_time.R 3 | \name{utils_is_time} 4 | \alias{utils_is_time} 5 | \title{Title} 6 | \usage{ 7 | utils_is_time(x = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{(required, vector) Vector to test. If the class of the vector elements is 'numeric', 'POSIXct', or 'Date', the function returns TRUE. Default: NULL.} 11 | } 12 | \value{ 13 | logical 14 | } 15 | \description{ 16 | Title 17 | } 18 | \examples{ 19 | 20 | utils_is_time( 21 | x = c("2024-01-01", "2024-02-01") 22 | ) 23 | 24 | utils_is_time( 25 | x = utils_as_time( 26 | x = c("2024-01-01", "2024-02-01") 27 | ) 28 | ) 29 | } 30 | \seealso{ 31 | Other internal_time_handling: 32 | \code{\link{utils_as_time}()}, 33 | \code{\link{utils_coerce_time_class}()}, 34 | \code{\link{utils_new_time}()}, 35 | \code{\link{utils_time_keywords}()}, 36 | \code{\link{utils_time_keywords_dictionary}()}, 37 | \code{\link{utils_time_keywords_translate}()}, 38 | \code{\link{utils_time_units}()} 39 | } 40 | \concept{internal_time_handling} 41 | -------------------------------------------------------------------------------- /man/utils_line_color.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils_line_color.R 3 | \name{utils_line_color} 4 | \alias{utils_line_color} 5 | \title{Handles Line Colors for Sequence Plots} 6 | \usage{ 7 | utils_line_color(x = NULL, line_color = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{(required, sequence) zoo object or time series list. Default: NULL} 11 | 12 | \item{line_color}{(optional, character vector) vector of colors for the time series columns. Selected palette depends on the number of columns to plot. Default: NULL} 13 | } 14 | \value{ 15 | color vector 16 | } 17 | \description{ 18 | This is an internal function, but can be used to better understand how line colors are handled within other plotting functions. 19 | } 20 | \seealso{ 21 | Other internal_plotting: 22 | \code{\link{color_continuous}()}, 23 | \code{\link{color_discrete}()}, 24 | \code{\link{utils_color_breaks}()}, 25 | \code{\link{utils_line_guide}()}, 26 | \code{\link{utils_matrix_guide}()}, 27 | \code{\link{utils_matrix_plot}()} 28 | } 29 | \concept{internal_plotting} 30 | -------------------------------------------------------------------------------- /man/utils_prepare_df.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils_prepare_df.R 3 | \name{utils_prepare_df} 4 | \alias{utils_prepare_df} 5 | \title{Convert Data Frame to a List of Data Frames} 6 | \usage{ 7 | utils_prepare_df(x = NULL, name_column = NULL, time_column = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{(required, data frame) Input data frame. Default: NULL.} 11 | 12 | \item{name_column}{(optional, column name) Column name used to split \code{x} to a list of data frames. If omitted, the split is done by column instead. Default: NULL} 13 | 14 | \item{time_column}{(optional, column name) Name of the column representing time, if any. Default: NULL.} 15 | } 16 | \value{ 17 | List of data frames 18 | } 19 | \description{ 20 | Convert Data Frame to a List of Data Frames 21 | } 22 | \seealso{ 23 | Other internal: 24 | \code{\link{utils_boxplot_common}()}, 25 | \code{\link{utils_check_args_distantia}()}, 26 | \code{\link{utils_check_args_matrix}()}, 27 | \code{\link{utils_check_args_momentum}()}, 28 | \code{\link{utils_check_args_path}()}, 29 | \code{\link{utils_check_args_tsl}()}, 30 | \code{\link{utils_check_args_zoo}()}, 31 | \code{\link{utils_check_distance_args}()}, 32 | \code{\link{utils_check_list_class}()}, 33 | \code{\link{utils_clean_names}()}, 34 | \code{\link{utils_digits}()}, 35 | \code{\link{utils_distantia_df_split}()}, 36 | \code{\link{utils_prepare_matrix}()}, 37 | \code{\link{utils_prepare_matrix_list}()}, 38 | \code{\link{utils_prepare_time}()}, 39 | \code{\link{utils_prepare_vector_list}()}, 40 | \code{\link{utils_prepare_zoo_list}()}, 41 | \code{\link{utils_tsl_pairs}()} 42 | } 43 | \concept{internal} 44 | -------------------------------------------------------------------------------- /man/utils_prepare_matrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils_prepare_matrix.R 3 | \name{utils_prepare_matrix} 4 | \alias{utils_prepare_matrix} 5 | \title{Convert Matrix to Data Frame} 6 | \usage{ 7 | utils_prepare_matrix(x = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{(required, matrix) Default: NULL} 11 | } 12 | \value{ 13 | A data frame 14 | } 15 | \description{ 16 | Convert Matrix to Data Frame 17 | } 18 | \seealso{ 19 | Other internal: 20 | \code{\link{utils_boxplot_common}()}, 21 | \code{\link{utils_check_args_distantia}()}, 22 | \code{\link{utils_check_args_matrix}()}, 23 | \code{\link{utils_check_args_momentum}()}, 24 | \code{\link{utils_check_args_path}()}, 25 | \code{\link{utils_check_args_tsl}()}, 26 | \code{\link{utils_check_args_zoo}()}, 27 | \code{\link{utils_check_distance_args}()}, 28 | \code{\link{utils_check_list_class}()}, 29 | \code{\link{utils_clean_names}()}, 30 | \code{\link{utils_digits}()}, 31 | \code{\link{utils_distantia_df_split}()}, 32 | \code{\link{utils_prepare_df}()}, 33 | \code{\link{utils_prepare_matrix_list}()}, 34 | \code{\link{utils_prepare_time}()}, 35 | \code{\link{utils_prepare_vector_list}()}, 36 | \code{\link{utils_prepare_zoo_list}()}, 37 | \code{\link{utils_tsl_pairs}()} 38 | } 39 | \concept{internal} 40 | -------------------------------------------------------------------------------- /man/utils_prepare_matrix_list.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils_prepare_matrix_list.R 3 | \name{utils_prepare_matrix_list} 4 | \alias{utils_prepare_matrix_list} 5 | \title{Convert List of Matrices to List of Data Frames} 6 | \usage{ 7 | utils_prepare_matrix_list(x = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{(required, list of matrices) Default: NULL} 11 | } 12 | \value{ 13 | List of Data Frames 14 | } 15 | \description{ 16 | Convert List of Matrices to List of Data Frames 17 | } 18 | \seealso{ 19 | Other internal: 20 | \code{\link{utils_boxplot_common}()}, 21 | \code{\link{utils_check_args_distantia}()}, 22 | \code{\link{utils_check_args_matrix}()}, 23 | \code{\link{utils_check_args_momentum}()}, 24 | \code{\link{utils_check_args_path}()}, 25 | \code{\link{utils_check_args_tsl}()}, 26 | \code{\link{utils_check_args_zoo}()}, 27 | \code{\link{utils_check_distance_args}()}, 28 | \code{\link{utils_check_list_class}()}, 29 | \code{\link{utils_clean_names}()}, 30 | \code{\link{utils_digits}()}, 31 | \code{\link{utils_distantia_df_split}()}, 32 | \code{\link{utils_prepare_df}()}, 33 | \code{\link{utils_prepare_matrix}()}, 34 | \code{\link{utils_prepare_time}()}, 35 | \code{\link{utils_prepare_vector_list}()}, 36 | \code{\link{utils_prepare_zoo_list}()}, 37 | \code{\link{utils_tsl_pairs}()} 38 | } 39 | \concept{internal} 40 | -------------------------------------------------------------------------------- /man/utils_prepare_vector_list.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils_prepare_vector_list.R 3 | \name{utils_prepare_vector_list} 4 | \alias{utils_prepare_vector_list} 5 | \title{Convert List of Vectors to List of Data Frames} 6 | \usage{ 7 | utils_prepare_vector_list(x = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{(required, list of vectors) Default: NULL} 11 | } 12 | \value{ 13 | List of data frames 14 | } 15 | \description{ 16 | Convert List of Vectors to List of Data Frames 17 | } 18 | \seealso{ 19 | Other internal: 20 | \code{\link{utils_boxplot_common}()}, 21 | \code{\link{utils_check_args_distantia}()}, 22 | \code{\link{utils_check_args_matrix}()}, 23 | \code{\link{utils_check_args_momentum}()}, 24 | \code{\link{utils_check_args_path}()}, 25 | \code{\link{utils_check_args_tsl}()}, 26 | \code{\link{utils_check_args_zoo}()}, 27 | \code{\link{utils_check_distance_args}()}, 28 | \code{\link{utils_check_list_class}()}, 29 | \code{\link{utils_clean_names}()}, 30 | \code{\link{utils_digits}()}, 31 | \code{\link{utils_distantia_df_split}()}, 32 | \code{\link{utils_prepare_df}()}, 33 | \code{\link{utils_prepare_matrix}()}, 34 | \code{\link{utils_prepare_matrix_list}()}, 35 | \code{\link{utils_prepare_time}()}, 36 | \code{\link{utils_prepare_zoo_list}()}, 37 | \code{\link{utils_tsl_pairs}()} 38 | } 39 | \concept{internal} 40 | -------------------------------------------------------------------------------- /man/utils_rescale_vector.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils_rescale_vector.R 3 | \name{utils_rescale_vector} 4 | \alias{utils_rescale_vector} 5 | \title{Rescale Numeric Vector to a New Data Range} 6 | \usage{ 7 | utils_rescale_vector( 8 | x = NULL, 9 | new_min = 0, 10 | new_max = 1, 11 | old_min = NULL, 12 | old_max = NULL 13 | ) 14 | } 15 | \arguments{ 16 | \item{x}{(required, numeric vector) Numeric vector. Default: \code{NULL}} 17 | 18 | \item{new_min}{(optional, numeric) New minimum value. Default: \code{0}} 19 | 20 | \item{new_max}{(optional_numeric) New maximum value. Default: \code{1}} 21 | 22 | \item{old_min}{(optional, numeric) Old minimum value. Default: \code{NULL}} 23 | 24 | \item{old_max}{(optional_numeric) Old maximum value. Default: \code{NULL}} 25 | } 26 | \value{ 27 | numeric vector 28 | } 29 | \description{ 30 | Rescale Numeric Vector to a New Data Range 31 | } 32 | \examples{ 33 | 34 | out <- utils_rescale_vector( 35 | x = stats::rnorm(100), 36 | new_min = 0, 37 | new_max = 100, 38 | ) 39 | 40 | out 41 | 42 | } 43 | \seealso{ 44 | Other tsl_processing_internal: 45 | \code{\link{utils_drop_geometry}()}, 46 | \code{\link{utils_global_scaling_params}()}, 47 | \code{\link{utils_optimize_loess}()}, 48 | \code{\link{utils_optimize_spline}()} 49 | } 50 | \concept{tsl_processing_internal} 51 | -------------------------------------------------------------------------------- /man/utils_time_keywords_dictionary.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils_time_keywords_dictionary.R 3 | \name{utils_time_keywords_dictionary} 4 | \alias{utils_time_keywords_dictionary} 5 | \title{Dictionary of Time Keywords} 6 | \usage{ 7 | utils_time_keywords_dictionary() 8 | } 9 | \value{ 10 | data frame 11 | } 12 | \description{ 13 | Called by \code{\link[=utils_time_keywords_translate]{utils_time_keywords_translate()}} to generate a data frame that helps translate misnamed or abbreviated time keywords, like "day", "daily", or "d", into correct ones such as "days". 14 | } 15 | \examples{ 16 | df <- utils_time_keywords_dictionary() 17 | } 18 | \seealso{ 19 | Other internal_time_handling: 20 | \code{\link{utils_as_time}()}, 21 | \code{\link{utils_coerce_time_class}()}, 22 | \code{\link{utils_is_time}()}, 23 | \code{\link{utils_new_time}()}, 24 | \code{\link{utils_time_keywords}()}, 25 | \code{\link{utils_time_keywords_translate}()}, 26 | \code{\link{utils_time_units}()} 27 | } 28 | \concept{internal_time_handling} 29 | -------------------------------------------------------------------------------- /man/utils_time_units.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils_time_units.R 3 | \name{utils_time_units} 4 | \alias{utils_time_units} 5 | \title{Data Frame with Supported Time Units} 6 | \usage{ 7 | utils_time_units(all_columns = FALSE, class = NULL) 8 | } 9 | \arguments{ 10 | \item{all_columns}{(optional, logical) If TRUE, all columns are returned. Default: FALSE} 11 | 12 | \item{class}{(optional, class name). Used to filter rows and columns. Accepted values are "numeric", "Date", and "POSIXct". Default: NULL} 13 | } 14 | \value{ 15 | data frame 16 | } 17 | \description{ 18 | Returns a data frame with the names of the supported time units, the classes that can handle each time unit, and a the threshold used to identify what time units can be used when aggregating a time series. 19 | } 20 | \examples{ 21 | 22 | df <- utils_time_units() 23 | head(df) 24 | } 25 | \seealso{ 26 | Other internal_time_handling: 27 | \code{\link{utils_as_time}()}, 28 | \code{\link{utils_coerce_time_class}()}, 29 | \code{\link{utils_is_time}()}, 30 | \code{\link{utils_new_time}()}, 31 | \code{\link{utils_time_keywords}()}, 32 | \code{\link{utils_time_keywords_dictionary}()}, 33 | \code{\link{utils_time_keywords_translate}()} 34 | } 35 | \concept{internal_time_handling} 36 | -------------------------------------------------------------------------------- /man/utils_tsl_pairs.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils_tsl_pairs.R 3 | \name{utils_tsl_pairs} 4 | \alias{utils_tsl_pairs} 5 | \title{Data Frame with Pairs of Time Series in Time Series Lists} 6 | \usage{ 7 | utils_tsl_pairs(tsl = NULL, args_list = NULL) 8 | } 9 | \arguments{ 10 | \item{tsl}{(required, list) Time series list. Default: NULL} 11 | 12 | \item{args_list}{(required, list) arguments to combine with the pairs of time series. Default: NULL} 13 | } 14 | \value{ 15 | data frame 16 | } 17 | \description{ 18 | Internal function used in \code{\link[=distantia]{distantia()}} and \code{\link[=momentum]{momentum()}} to generate a data frame with combinations of time series and function arguments. 19 | } 20 | \seealso{ 21 | Other internal: 22 | \code{\link{utils_boxplot_common}()}, 23 | \code{\link{utils_check_args_distantia}()}, 24 | \code{\link{utils_check_args_matrix}()}, 25 | \code{\link{utils_check_args_momentum}()}, 26 | \code{\link{utils_check_args_path}()}, 27 | \code{\link{utils_check_args_tsl}()}, 28 | \code{\link{utils_check_args_zoo}()}, 29 | \code{\link{utils_check_distance_args}()}, 30 | \code{\link{utils_check_list_class}()}, 31 | \code{\link{utils_clean_names}()}, 32 | \code{\link{utils_digits}()}, 33 | \code{\link{utils_distantia_df_split}()}, 34 | \code{\link{utils_prepare_df}()}, 35 | \code{\link{utils_prepare_matrix}()}, 36 | \code{\link{utils_prepare_matrix_list}()}, 37 | \code{\link{utils_prepare_time}()}, 38 | \code{\link{utils_prepare_vector_list}()}, 39 | \code{\link{utils_prepare_zoo_list}()} 40 | } 41 | \concept{internal} 42 | -------------------------------------------------------------------------------- /man/zoo_name_get.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/zoo_names.R 3 | \name{zoo_name_get} 4 | \alias{zoo_name_get} 5 | \title{Get Name of a Zoo Time Series} 6 | \usage{ 7 | zoo_name_get(x = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{(required, zoo object) Zoo time series to analyze. Default: NULL.} 11 | } 12 | \value{ 13 | character string 14 | } 15 | \description{ 16 | Just a convenient wrapper of \code{attributes(x)$name}. 17 | } 18 | \examples{ 19 | #simulate zoo time series 20 | x <- zoo_simulate() 21 | 22 | #get current name 23 | zoo_name_get(x = x) 24 | 25 | #change name 26 | x <- zoo_name_set( 27 | x = x, 28 | name = "My.New.name" 29 | ) 30 | 31 | zoo_name_get(x = x) 32 | 33 | #clean name 34 | x <- zoo_name_clean( 35 | x = x, 36 | lowercase = TRUE 37 | ) 38 | 39 | zoo_name_get(x = x) 40 | } 41 | \seealso{ 42 | Other zoo_functions: 43 | \code{\link{zoo_aggregate}()}, 44 | \code{\link{zoo_name_clean}()}, 45 | \code{\link{zoo_name_set}()}, 46 | \code{\link{zoo_permute}()}, 47 | \code{\link{zoo_plot}()}, 48 | \code{\link{zoo_resample}()}, 49 | \code{\link{zoo_smooth_exponential}()}, 50 | \code{\link{zoo_smooth_window}()}, 51 | \code{\link{zoo_time}()}, 52 | \code{\link{zoo_to_tsl}()}, 53 | \code{\link{zoo_vector_to_matrix}()} 54 | } 55 | \concept{zoo_functions} 56 | -------------------------------------------------------------------------------- /man/zoo_smooth_exponential.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/zoo_smooth_exponential.R 3 | \name{zoo_smooth_exponential} 4 | \alias{zoo_smooth_exponential} 5 | \title{Exponential Smoothing of Zoo Time Series} 6 | \usage{ 7 | zoo_smooth_exponential(x = NULL, alpha = 0.2) 8 | } 9 | \arguments{ 10 | \item{x}{(required, zoo object) time series to smooth Default: NULL} 11 | 12 | \item{alpha}{(required, numeric) Smoothing factor in the range (0, 1]. Determines the weight of the current value relative to past values. A higher value gives more weight to recent observations, while a lower value gives more weight to past observations. Default: 0.2} 13 | } 14 | \value{ 15 | zoo object 16 | } 17 | \description{ 18 | Applies exponential smoothing to a zoo time series object, where each value is a weighted average of the current value and past smoothed values. This method is useful for reducing noise in time series data while preserving the general trend. 19 | } 20 | \examples{ 21 | x <- zoo_simulate() 22 | 23 | x_smooth <- zoo_smooth_exponential( 24 | x = x, 25 | alpha = 0.2 26 | ) 27 | 28 | if(interactive()){ 29 | zoo_plot(x) 30 | zoo_plot(x_smooth) 31 | } 32 | } 33 | \seealso{ 34 | Other zoo_functions: 35 | \code{\link{zoo_aggregate}()}, 36 | \code{\link{zoo_name_clean}()}, 37 | \code{\link{zoo_name_get}()}, 38 | \code{\link{zoo_name_set}()}, 39 | \code{\link{zoo_permute}()}, 40 | \code{\link{zoo_plot}()}, 41 | \code{\link{zoo_resample}()}, 42 | \code{\link{zoo_smooth_window}()}, 43 | \code{\link{zoo_time}()}, 44 | \code{\link{zoo_to_tsl}()}, 45 | \code{\link{zoo_vector_to_matrix}()} 46 | } 47 | \concept{zoo_functions} 48 | -------------------------------------------------------------------------------- /man/zoo_smooth_window.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/zoo_smooth_window.R 3 | \name{zoo_smooth_window} 4 | \alias{zoo_smooth_window} 5 | \title{Rolling Window Smoothing of Zoo Time Series} 6 | \usage{ 7 | zoo_smooth_window(x = NULL, window = 3, f = mean, ...) 8 | } 9 | \arguments{ 10 | \item{x}{(required, zoo object) Time series to smooth Default: NULL} 11 | 12 | \item{window}{(optional, integer) Smoothing window width, in number of cases. Default: 3} 13 | 14 | \item{f}{(optional, quoted or unquoted function name) Name of a standard or custom function to aggregate numeric vectors. Typical examples are \code{mean}, \code{max},\code{min}, \code{median}, and \code{quantile}. Default: \code{mean}.} 15 | 16 | \item{...}{(optional, additional arguments) additional arguments to \code{f}.} 17 | } 18 | \value{ 19 | zoo object 20 | } 21 | \description{ 22 | Just a fancy wrapper for \code{\link[zoo:rollapply]{zoo::rollapply()}}. 23 | } 24 | \examples{ 25 | x <- zoo_simulate() 26 | 27 | x_smooth <- zoo_smooth_window( 28 | x = x, 29 | window = 5, 30 | f = mean 31 | ) 32 | 33 | if(interactive()){ 34 | zoo_plot(x) 35 | zoo_plot(x_smooth) 36 | } 37 | } 38 | \seealso{ 39 | Other zoo_functions: 40 | \code{\link{zoo_aggregate}()}, 41 | \code{\link{zoo_name_clean}()}, 42 | \code{\link{zoo_name_get}()}, 43 | \code{\link{zoo_name_set}()}, 44 | \code{\link{zoo_permute}()}, 45 | \code{\link{zoo_plot}()}, 46 | \code{\link{zoo_resample}()}, 47 | \code{\link{zoo_smooth_exponential}()}, 48 | \code{\link{zoo_time}()}, 49 | \code{\link{zoo_to_tsl}()}, 50 | \code{\link{zoo_vector_to_matrix}()} 51 | } 52 | \concept{zoo_functions} 53 | -------------------------------------------------------------------------------- /man/zoo_to_tsl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/zoo_to_tsl.R 3 | \name{zoo_to_tsl} 4 | \alias{zoo_to_tsl} 5 | \title{Convert Individual Zoo Objects to Time Series List} 6 | \usage{ 7 | zoo_to_tsl(x = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{(required, zoo object) Time series. Default: NULL} 11 | } 12 | \value{ 13 | time series list of length one. 14 | } 15 | \description{ 16 | Internal function to wrap a zoo object into a time series list. 17 | } 18 | \examples{ 19 | #create zoo object 20 | x <- zoo_simulate() 21 | class(x) 22 | 23 | #to time series list 24 | tsl <- zoo_to_tsl( 25 | x = x 26 | ) 27 | 28 | class(tsl) 29 | class(tsl[[1]]) 30 | names(tsl) 31 | attributes(tsl[[1]])$name 32 | } 33 | \seealso{ 34 | Other zoo_functions: 35 | \code{\link{zoo_aggregate}()}, 36 | \code{\link{zoo_name_clean}()}, 37 | \code{\link{zoo_name_get}()}, 38 | \code{\link{zoo_name_set}()}, 39 | \code{\link{zoo_permute}()}, 40 | \code{\link{zoo_plot}()}, 41 | \code{\link{zoo_resample}()}, 42 | \code{\link{zoo_smooth_exponential}()}, 43 | \code{\link{zoo_smooth_window}()}, 44 | \code{\link{zoo_time}()}, 45 | \code{\link{zoo_vector_to_matrix}()} 46 | } 47 | \concept{zoo_functions} 48 | -------------------------------------------------------------------------------- /man/zoo_vector_to_matrix.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/zoo_vector_to_matrix.R 3 | \name{zoo_vector_to_matrix} 4 | \alias{zoo_vector_to_matrix} 5 | \title{Coerce Coredata of Univariate Zoo Time Series to Matrix} 6 | \usage{ 7 | zoo_vector_to_matrix(x = NULL, name = NULL) 8 | } 9 | \arguments{ 10 | \item{x}{(required, zoo object) zoo time series. Default: NULL} 11 | 12 | \item{name}{(required, character string) name of the matrix column. Default: NULL} 13 | } 14 | \value{ 15 | zoo time series 16 | } 17 | \description{ 18 | Transforms vector coredata of univariate zoo time series to class matrix. If the input zoo time series has the attribute "name", the output inherits the value of such attribute. 19 | 20 | Multivariate zoo objects are returned without changes. 21 | } 22 | \examples{ 23 | #create zoo object from vector 24 | x <- zoo::zoo( 25 | x = runif(100) 26 | ) 27 | 28 | #coredata is not a matrix 29 | is.matrix(zoo::coredata(x)) 30 | 31 | #convert to matrix 32 | y <- zoo_vector_to_matrix( 33 | x = x 34 | ) 35 | 36 | #coredata is now a matrix 37 | is.matrix(zoo::coredata(y)) 38 | } 39 | \seealso{ 40 | Other zoo_functions: 41 | \code{\link{zoo_aggregate}()}, 42 | \code{\link{zoo_name_clean}()}, 43 | \code{\link{zoo_name_get}()}, 44 | \code{\link{zoo_name_set}()}, 45 | \code{\link{zoo_permute}()}, 46 | \code{\link{zoo_plot}()}, 47 | \code{\link{zoo_resample}()}, 48 | \code{\link{zoo_smooth_exponential}()}, 49 | \code{\link{zoo_smooth_window}()}, 50 | \code{\link{zoo_time}()}, 51 | \code{\link{zoo_to_tsl}()} 52 | } 53 | \concept{zoo_functions} 54 | -------------------------------------------------------------------------------- /pkgdown/extra.css: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;700&display=swap'); 2 | 3 | body { 4 | font-family: 'Montserrat', sans-serif; 5 | } 6 | 7 | h1, h2, h3, h4, h5, h6 { 8 | font-family: 'Montserrat', sans-serif; 9 | } 10 | -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/pkgdown/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-96x96.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/pkgdown/favicon/favicon-96x96.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/pkgdown/favicon/favicon.ico -------------------------------------------------------------------------------- /pkgdown/favicon/site.webmanifest: -------------------------------------------------------------------------------- 1 | { 2 | "name": "", 3 | "short_name": "", 4 | "icons": [ 5 | { 6 | "src": "/web-app-manifest-192x192.png", 7 | "sizes": "192x192", 8 | "type": "image/png", 9 | "purpose": "maskable" 10 | }, 11 | { 12 | "src": "/web-app-manifest-512x512.png", 13 | "sizes": "512x512", 14 | "type": "image/png", 15 | "purpose": "maskable" 16 | } 17 | ], 18 | "theme_color": "#ffffff", 19 | "background_color": "#ffffff", 20 | "display": "standalone" 21 | } -------------------------------------------------------------------------------- /pkgdown/favicon/web-app-manifest-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/pkgdown/favicon/web-app-manifest-192x192.png -------------------------------------------------------------------------------- /pkgdown/favicon/web-app-manifest-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/pkgdown/favicon/web-app-manifest-512x512.png -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.so 3 | -------------------------------------------------------------------------------- /src/RcppExports.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/src/RcppExports.o -------------------------------------------------------------------------------- /src/auto_sum.h: -------------------------------------------------------------------------------- 1 | #ifndef AUTO_SUM_H 2 | #define AUTO_SUM_H 3 | 4 | #include 5 | 6 | // Distance matrix function declaration 7 | double auto_distance_cpp( 8 | Rcpp::NumericMatrix m, 9 | const std::string& distance = "euclidean" 10 | ); 11 | 12 | // Subset matrix by rows function declaration 13 | Rcpp::NumericMatrix subset_matrix_by_rows_cpp( 14 | Rcpp::NumericMatrix m, 15 | Rcpp::NumericVector rows 16 | ); 17 | 18 | // Auto-sum function declaration 19 | double auto_sum_path_cpp( 20 | Rcpp::NumericMatrix a, 21 | Rcpp::NumericMatrix b, 22 | Rcpp::DataFrame path, 23 | const std::string& distance = "euclidean" 24 | ); 25 | 26 | double auto_sum_full_cpp( 27 | Rcpp::NumericMatrix a, 28 | Rcpp::NumericMatrix b, 29 | const std::string& distance = "euclidean" 30 | ); 31 | 32 | double auto_sum_cpp( 33 | Rcpp::NumericMatrix a, 34 | Rcpp::NumericMatrix b, 35 | Rcpp::DataFrame path, 36 | const std::string& distance = "euclidean", 37 | bool ignore_blocks = false 38 | ); 39 | 40 | #endif // AUTO_SUM_H 41 | -------------------------------------------------------------------------------- /src/auto_sum.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/src/auto_sum.o -------------------------------------------------------------------------------- /src/cost_matrix.h: -------------------------------------------------------------------------------- 1 | #ifndef COST_MATRIX_H 2 | #define COST_MATRIX_H 3 | 4 | #include 5 | 6 | Rcpp::NumericMatrix cost_matrix_diagonal_cpp(Rcpp::NumericMatrix dist_matrix); 7 | Rcpp::NumericMatrix cost_matrix_diagonal_weighted_cpp(Rcpp::NumericMatrix dist_matrix); 8 | Rcpp::NumericMatrix cost_matrix_orthogonal_cpp(Rcpp::NumericMatrix dist_matrix); 9 | 10 | #endif // COST_MATRIX_H 11 | -------------------------------------------------------------------------------- /src/cost_matrix.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/src/cost_matrix.o -------------------------------------------------------------------------------- /src/cost_path.h: -------------------------------------------------------------------------------- 1 | #ifndef COST_PATH_H 2 | #define COST_PATH_H 3 | 4 | #include 5 | 6 | Rcpp::DataFrame cost_path_orthogonal_cpp( 7 | Rcpp::NumericMatrix dist_matrix, 8 | Rcpp::NumericMatrix cost_matrix 9 | ); 10 | 11 | Rcpp::DataFrame cost_path_diagonal_cpp( 12 | Rcpp::NumericMatrix dist_matrix, 13 | Rcpp::NumericMatrix cost_matrix 14 | ); 15 | 16 | Rcpp::DataFrame cost_path_orthogonal_bandwidth_cpp( 17 | Rcpp::NumericMatrix dist_matrix, 18 | Rcpp::NumericMatrix cost_matrix, 19 | double bandwidth = 0.25 20 | ); 21 | 22 | Rcpp::DataFrame cost_path_diagonal_bandwidth_cpp( 23 | Rcpp::NumericMatrix dist_matrix, 24 | Rcpp::NumericMatrix cost_matrix, 25 | double bandwidth = 0.25 26 | ); 27 | 28 | Rcpp::DataFrame cost_path_trim_cpp( 29 | Rcpp::DataFrame path 30 | ); 31 | 32 | double cost_path_sum_cpp(Rcpp::DataFrame path); 33 | 34 | Rcpp::DataFrame cost_path_cpp( 35 | Rcpp::NumericMatrix a, 36 | Rcpp::NumericMatrix b, 37 | const std::string& distance = "euclidean", 38 | bool diagonal = false, 39 | bool weighted = false, 40 | bool ignore_blocks = false, 41 | double bandwidth = 1 42 | ); 43 | 44 | #endif // COST_PATH_H 45 | -------------------------------------------------------------------------------- /src/cost_path.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/src/cost_path.o -------------------------------------------------------------------------------- /src/distance_matrix.h: -------------------------------------------------------------------------------- 1 | #ifndef DISTANCE_MATRIX_CPP_H 2 | #define DISTANCE_MATRIX_CPP_H 3 | 4 | #include 5 | #include "distance_methods.h" 6 | 7 | Rcpp::NumericMatrix distance_matrix_cpp( 8 | Rcpp::NumericMatrix a, 9 | Rcpp::NumericMatrix b, 10 | const std::string& distance = "euclidean" 11 | ); 12 | 13 | double distance_ls_cpp( 14 | Rcpp::NumericMatrix a, 15 | Rcpp::NumericMatrix b, 16 | const std::string& distance = "euclidean" 17 | ); 18 | 19 | #endif // DISTANCE_MATRIX_CPP_H 20 | 21 | -------------------------------------------------------------------------------- /src/distance_matrix.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/src/distance_matrix.o -------------------------------------------------------------------------------- /src/distance_methods.h: -------------------------------------------------------------------------------- 1 | #ifndef DISTANCE_METHODS_H 2 | #define DISTANCE_METHODS_H 3 | 4 | #include 5 | 6 | // Chebyshev Distance 7 | double distance_chebyshev_cpp(Rcpp::NumericVector x, Rcpp::NumericVector y); 8 | 9 | // Jaccard Distance 10 | double distance_jaccard_cpp(Rcpp::NumericVector x, Rcpp::NumericVector y); 11 | 12 | // Manhattan Distance 13 | double distance_manhattan_cpp(Rcpp::NumericVector x, Rcpp::NumericVector y); 14 | 15 | // Euclidean Distance 16 | double distance_euclidean_cpp(Rcpp::NumericVector x, Rcpp::NumericVector y); 17 | 18 | // Hellinger Distance 19 | double distance_hellinger_cpp(Rcpp::NumericVector x, Rcpp::NumericVector y); 20 | 21 | // Chi Distance 22 | double distance_chi_cpp(Rcpp::NumericVector x, Rcpp::NumericVector y); 23 | 24 | // Canberra Distance 25 | double distance_canberra_cpp(Rcpp::NumericVector x, Rcpp::NumericVector y); 26 | 27 | // Russell-Rao Distance 28 | double distance_russelrao_cpp(Rcpp::NumericVector x, Rcpp::NumericVector y); 29 | 30 | // Cosine Dissimilarity 31 | double distance_cosine_cpp(Rcpp::NumericVector x, Rcpp::NumericVector y); 32 | 33 | // Cosine Hamming 34 | double distance_hamming_cpp(Rcpp::NumericVector x, Rcpp::NumericVector y); 35 | 36 | 37 | // Define the type for the distance function 38 | typedef double (*DistanceFunction)(Rcpp::NumericVector, Rcpp::NumericVector); 39 | 40 | // Internal function to select the distance method 41 | DistanceFunction select_distance_function_cpp(const std::string& distance); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/distance_methods.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/src/distance_methods.o -------------------------------------------------------------------------------- /src/distantia.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/src/distantia.so -------------------------------------------------------------------------------- /src/importance.h: -------------------------------------------------------------------------------- 1 | #ifndef IMPORTANCE_H 2 | #define IMPORTANCE_H 3 | 4 | #include 5 | 6 | // Declarations for functions exported to other C++ files 7 | Rcpp::NumericVector reverse_vector_cpp(Rcpp::NumericVector x); 8 | 9 | Rcpp::DataFrame update_path_dist_cpp( 10 | Rcpp::NumericMatrix a, 11 | Rcpp::NumericMatrix b, 12 | Rcpp::DataFrame path, 13 | const std::string& distance = "euclidean" 14 | ); 15 | 16 | Rcpp::NumericMatrix select_column_cpp( 17 | Rcpp::NumericMatrix x, 18 | int column_index 19 | ); 20 | 21 | Rcpp::NumericMatrix delete_column_cpp( 22 | Rcpp::NumericMatrix x, 23 | int column_index 24 | ); 25 | 26 | Rcpp::DataFrame importance_ls_cpp( 27 | Rcpp::NumericMatrix a, 28 | Rcpp::NumericMatrix b, 29 | const std::string& distance = "euclidean" 30 | ); 31 | 32 | Rcpp::DataFrame importance_dtw_legacy_cpp( 33 | Rcpp::NumericMatrix a, 34 | Rcpp::NumericMatrix b, 35 | const std::string& distance = "euclidean", 36 | bool diagonal = false, 37 | bool weighted = false, 38 | bool ignore_blocks = false, 39 | double bandwidth = 1 40 | ); 41 | 42 | Rcpp::DataFrame importance_dtw_cpp( 43 | Rcpp::NumericMatrix a, 44 | Rcpp::NumericMatrix b, 45 | const std::string& distance = "euclidean", 46 | bool diagonal = false, 47 | bool weighted = false, 48 | bool ignore_blocks = false, 49 | double bandwidth = 1 50 | ); 51 | 52 | #endif // IMPORTANCE_H 53 | -------------------------------------------------------------------------------- /src/importance.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/src/importance.o -------------------------------------------------------------------------------- /src/permute.h: -------------------------------------------------------------------------------- 1 | #ifndef PERMUTE_H 2 | #define PERMUTE_H 3 | 4 | #include 5 | 6 | 7 | Rcpp::NumericMatrix permute_restricted_by_row_cpp( 8 | Rcpp::NumericMatrix x, 9 | int block_size, 10 | int seed 11 | ); 12 | 13 | Rcpp::NumericMatrix permute_free_by_row_cpp( 14 | Rcpp::NumericMatrix x, 15 | int block_size, 16 | int seed 17 | ); 18 | 19 | Rcpp::NumericMatrix permute_restricted_cpp( 20 | Rcpp::NumericMatrix x, 21 | int block_size, 22 | int seed 23 | ); 24 | 25 | Rcpp::NumericMatrix permute_free_cpp( 26 | Rcpp::NumericMatrix x, 27 | int block_size, 28 | int seed 29 | ); 30 | 31 | typedef Rcpp::NumericMatrix (*PermutationFunction)(Rcpp::NumericMatrix, int, int); 32 | 33 | PermutationFunction select_permutation_function_cpp( 34 | const std::string& permutation = "restricted_by_row" 35 | ); 36 | 37 | #endif // PERMUTE_H 38 | -------------------------------------------------------------------------------- /src/permute.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/src/permute.o -------------------------------------------------------------------------------- /src/psi.h: -------------------------------------------------------------------------------- 1 | #ifndef PSI_H 2 | #define PSI_H 3 | 4 | #include 5 | 6 | // Forward declarations of functions 7 | 8 | double psi_equation_cpp( 9 | double cost_path_sum, 10 | double auto_sum, 11 | bool diagonal = false 12 | ); 13 | 14 | double psi_ls_cpp( 15 | Rcpp::NumericMatrix a, 16 | Rcpp::NumericMatrix b, 17 | const std::string& distance = "euclidean" 18 | ); 19 | 20 | Rcpp::NumericVector psi_null_ls_cpp( 21 | Rcpp::NumericMatrix a, 22 | Rcpp::NumericMatrix b, 23 | const std::string& distance = "euclidean", 24 | Rcpp::IntegerVector block_size = Rcpp::IntegerVector::create(2, 3, 4), 25 | int seed = 1, 26 | bool independent_columns = true, 27 | int repetitions = 100 28 | ); 29 | 30 | double psi_dtw_cpp( 31 | Rcpp::NumericMatrix a, 32 | Rcpp::NumericMatrix b, 33 | const std::string& distance = "euclidean", 34 | bool diagonal = false, 35 | bool weighted = false, 36 | bool ignore_blocks = false, 37 | double bandwidth = 1 38 | ); 39 | 40 | Rcpp::NumericVector psi_null_dtw_cpp( 41 | Rcpp::NumericMatrix a, 42 | Rcpp::NumericMatrix b, 43 | const std::string& distance = "euclidean", 44 | bool diagonal = true, 45 | bool weighted = true, 46 | bool ignore_blocks = false, 47 | double bandwidth = 1, 48 | Rcpp::IntegerVector block_size = Rcpp::IntegerVector::create(2, 3, 4), 49 | int seed = 1, 50 | bool independent_columns = true, 51 | int repetitions = 100 52 | ); 53 | 54 | #endif // PSI_H 55 | -------------------------------------------------------------------------------- /src/psi.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BlasBenito/distantia/c5598b7eecb2c856510ca9373330cf670af81e2a/src/psi.o -------------------------------------------------------------------------------- /tests/spelling.R: -------------------------------------------------------------------------------- 1 | if(requireNamespace('spelling', quietly = TRUE)) 2 | spelling::spell_check_test(vignettes = TRUE, error = FALSE, 3 | skip_on_cran = TRUE) 4 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | # This file is part of the standard setup for testthat. 2 | # It is recommended that you do not modify it. 3 | # 4 | # Where should you do additional test configuration? 5 | # Learn more about the roles of various files in: 6 | # * https://r-pkgs.org/testing-design.html#sec-tests-files-overview 7 | # * https://testthat.r-lib.org/articles/special-files.html 8 | 9 | library(testthat) 10 | library(distantia, quietly = TRUE) 11 | 12 | test_check("distantia") 13 | -------------------------------------------------------------------------------- /tests/testthat/test-distance.R: -------------------------------------------------------------------------------- 1 | test_that("`distance()` works", { 2 | expect_true(is.numeric(distance(x = runif(100), y = runif(100), distance = "euclidean"))) 3 | 4 | expect_true(distance(x = 1, y = 1) == 0) 5 | }) 6 | -------------------------------------------------------------------------------- /tests/testthat/test-distance_matrix.R: -------------------------------------------------------------------------------- 1 | test_that("`distance_matrix()` works", { 2 | m <- distance_matrix( 3 | df = cities_coordinates, 4 | name_column = "name", 5 | distance = "euclidean" 6 | ) 7 | expect_equal(attributes(m)$distance, "euclidean") 8 | expect_equal(ncol(m), nrow(cities_coordinates)) 9 | expect_equal(nrow(m), nrow(cities_coordinates)) 10 | }) 11 | -------------------------------------------------------------------------------- /tests/testthat/test-distantia_cluster_hclust.R: -------------------------------------------------------------------------------- 1 | test_that("`distantia_cluster_hclust()` works", { 2 | 3 | tsl <- tsl_initialize( 4 | x = covid_prevalence, 5 | name_column = "name", 6 | time_column = "time" 7 | ) 8 | 9 | tsl <- tsl_subset(tsl = tsl, names = 1:10) 10 | 11 | distantia_df <- distantia( 12 | tsl = tsl, 13 | lock_step = TRUE 14 | ) 15 | 16 | distantia_clust <- distantia_cluster_hclust( 17 | df = distantia_df, 18 | clusters = NULL, 19 | method = NULL 20 | ) 21 | 22 | expect_equal(names(distantia_clust), c("cluster_object", "clusters", "silhouette_width", "df", "d", "optimization")) 23 | 24 | expect_true(class(distantia_clust$cluster_object) == "hclust") 25 | 26 | expect_true(class(distantia_clust$d) == "dist") 27 | 28 | expect_true(class(distantia_clust$df) == "data.frame") 29 | 30 | expect_true(is.numeric(distantia_clust$silhouette_width)) 31 | 32 | }) 33 | -------------------------------------------------------------------------------- /tests/testthat/test-distantia_cluster_kmeans.R: -------------------------------------------------------------------------------- 1 | test_that("`distantia_cluster_kmeans()` works", { 2 | 3 | tsl <- tsl_initialize( 4 | x = covid_prevalence, 5 | name_column = "name", 6 | time_column = "time" 7 | ) 8 | 9 | tsl <- tsl_subset(tsl = tsl, names = 1:10) 10 | 11 | distantia_df <- distantia(tsl = tsl, lock_step = TRUE) 12 | 13 | distantia_kmeans <- distantia_cluster_kmeans( 14 | df = distantia_df, 15 | clusters = NULL 16 | ) 17 | 18 | expect_equal(names(distantia_kmeans), c("cluster_object", "clusters", "silhouette_width", "df", "d", "optimization")) 19 | 20 | expect_true(class(distantia_kmeans$cluster_object) == "kmeans") 21 | 22 | expect_true("matrix" %in% class(distantia_kmeans$d)) 23 | 24 | expect_true(class(distantia_kmeans$df) == "data.frame") 25 | 26 | expect_true(is.numeric(distantia_kmeans$silhouette_width)) 27 | 28 | }) 29 | -------------------------------------------------------------------------------- /tests/testthat/test-distantia_model_frame.R: -------------------------------------------------------------------------------- 1 | test_that("`distantia_model_frame()` works", { 2 | 3 | tsl <- tsl_initialize( 4 | x = covid_prevalence, name_column = "name", 5 | time_column = "time" 6 | ) 7 | 8 | df <- distantia_ls(tsl = tsl) 9 | 10 | composite_predictors <- list(economy = c( 11 | "poverty_percentage", 12 | "median_income", "domestic_product" 13 | )) 14 | 15 | model_frame <- distantia_model_frame( 16 | response_df = df, predictors_df = covid_counties, 17 | composite_predictors = composite_predictors, scale = TRUE 18 | ) 19 | 20 | expect_equal(class(model_frame), "data.frame") 21 | 22 | expect_true("economy" %in% colnames(model_frame)) 23 | 24 | expect_true("geographic_distance" %in% colnames(model_frame)) 25 | 26 | expect_equal(attributes(model_frame)$response, "psi") 27 | 28 | model <- lm(formula = attributes(model_frame)$formula, data = model_frame) 29 | 30 | expect_equal(class(model), "lm") 31 | 32 | }) 33 | -------------------------------------------------------------------------------- /tests/testthat/test-distantia_spatial.R: -------------------------------------------------------------------------------- 1 | test_that("`distantia_spatial()` works", { 2 | 3 | tsl <- distantia::tsl_initialize( 4 | x = distantia::covid_prevalence, 5 | name_column = "name", time_column = "time" 6 | ) 7 | 8 | df_psi <- distantia::distantia_ls(tsl = tsl) 9 | 10 | sf_psi <- distantia::distantia_spatial( 11 | df = df_psi, sf = distantia::covid_counties, 12 | network = TRUE 13 | ) 14 | 15 | expect_true("sf" %in% class(sf_psi)) 16 | 17 | expect_equal(nrow(df_psi), nrow(sf_psi)) 18 | 19 | }) 20 | -------------------------------------------------------------------------------- /tests/testthat/test-distantia_time_shift.R: -------------------------------------------------------------------------------- 1 | test_that("`distantia_time_delay()` works", { 2 | 3 | tsl <- tsl_transform( 4 | tsl_transform( 5 | tsl_init(x = cities_temperature[cities_temperature$name %in% 6 | c("London", "Kinshasa"), ], name = "name", time = "time"), 7 | f = f_scale_local 8 | ), 9 | f = f_detrend_poly, 10 | degree = 35 11 | ) 12 | 13 | df_shift <- distantia_time_delay( 14 | tsl = tsl, 15 | two_way = TRUE 16 | ) 17 | 18 | expect_equal(nrow(df_shift), 2) 19 | 20 | df_shift <- distantia_time_delay( 21 | tsl = tsl, 22 | two_way = FALSE 23 | ) 24 | 25 | expect_equal(nrow(df_shift), 1) 26 | 27 | expect_true(all(colnames(df_shift) %in% c("x", "y", "distance", "units", "mean", "min", "q1", "median", "q3", "max", "sd", "range", "modal"))) 28 | 29 | }) 30 | -------------------------------------------------------------------------------- /tests/testthat/test-tsl_aggregate.R: -------------------------------------------------------------------------------- 1 | test_that("`tsl_aggregate()` works", { 2 | 3 | tsl <- tsl_initialize( 4 | x = cities_temperature, 5 | name_column = "name", 6 | time_column = "time" 7 | ) 8 | 9 | tsl_year <- tsl_aggregate(tsl = tsl, new_time = "year", f = mean) 10 | 11 | expect_true(tsl_time(tsl)$resolution[1] < tsl_time(tsl_year)$resolution[1]) 12 | 13 | expect_true(tsl_nrow(tsl)[[1]] > tsl_nrow(tsl_year)[[1]]) 14 | 15 | }) 16 | -------------------------------------------------------------------------------- /tests/testthat/test-tsl_burst.R: -------------------------------------------------------------------------------- 1 | test_that("`tsl_burst()` works", { 2 | 3 | n = 2 4 | cols = 3 5 | 6 | tsl <- tsl_simulate( 7 | n = n, 8 | time_range = c("2010-01-01", "2024-12-31"), 9 | cols = cols, 10 | seed = 1 11 | ) 12 | 13 | 14 | tsl_ <- tsl_burst(tsl) 15 | 16 | expect_true( 17 | length(tsl_) == n * cols 18 | ) 19 | 20 | expect_true( 21 | unique(unlist(tsl_colnames_get(tsl = tsl_))) == "x" 22 | ) 23 | 24 | }) 25 | -------------------------------------------------------------------------------- /tests/testthat/test-tsl_count_NA.R: -------------------------------------------------------------------------------- 1 | test_that("`tsl_count_NA()` works", { 2 | 3 | tsl <- tsl_simulate(, 4 | seed = 1) 5 | 6 | expect_equal( 7 | sum(unlist(tsl_count_NA(tsl = tsl))), 8 | 0 9 | ) 10 | 11 | tsl <- tsl_simulate(, 12 | seed = 1) 13 | tsl[[1]][1, 1] <- Inf 14 | tsl[[1]][2, 1] <- -Inf 15 | tsl[[1]][3, 1] <- NaN 16 | tsl[[1]][4, 1] <- NaN 17 | 18 | expect_true( 19 | sum(unlist(tsl_count_NA(tsl = tsl))) == 4 20 | ) 21 | 22 | tsl <- tsl_simulate(na_fraction = 0.3, 23 | seed = 1) 24 | 25 | expect_true( 26 | sum(unlist(tsl_count_NA(tsl = tsl))) > 0 27 | ) 28 | 29 | }) 30 | -------------------------------------------------------------------------------- /tests/testthat/test-tsl_diagnose.R: -------------------------------------------------------------------------------- 1 | test_that("`tsl_diagnose()` works", { 2 | 3 | x <- zoo_simulate(name = "x", cols = 1, na_fraction = 0.1, seed = 1) 4 | y <- zoo_simulate(name = "x", cols = 2, seed = 2) 5 | z <- zoo_simulate(name = "z", cols = 1, time_range = c(1, 100), seed = 3) 6 | colnames(x) <- c("b") 7 | 8 | z <- zoo::zoo(x = runif(nrow(z)), order.by = zoo::index(z)) 9 | 10 | tsl <- list(a = x, b = y, c = z) 11 | 12 | expect_message(tsl_diagnose(tsl = tsl)) |> 13 | suppressMessages() 14 | 15 | }) 16 | -------------------------------------------------------------------------------- /tests/testthat/test-tsl_handle_NA.R: -------------------------------------------------------------------------------- 1 | test_that("`tsl_handle_NA()` works", { 2 | 3 | tsl <- tsl_simulate(na_fraction = 0.25, 4 | seed = 1) 5 | 6 | tsl_nrow <- tsl_nrow(tsl = tsl) |> 7 | unlist() |> 8 | sum() 9 | 10 | tsl_no_na <- tsl_handle_NA(tsl = tsl, na_action = "omit") 11 | 12 | expect_true( 13 | tsl_nrow > tsl_nrow(tsl = tsl_no_na) |> 14 | unlist() |> 15 | sum() 16 | ) 17 | 18 | expect_equal(sum(unlist(tsl_count_NA(tsl = tsl_no_na))), 0) 19 | 20 | tsl_no_na <- tsl_handle_NA(tsl = tsl, na_action = "impute") 21 | 22 | expect_true( 23 | tsl_nrow == tsl_nrow(tsl = tsl_no_na) |> 24 | unlist() |> 25 | sum() 26 | ) 27 | 28 | expect_equal(sum(unlist(tsl_count_NA(tsl = tsl_no_na))), 0) 29 | 30 | }) 31 | -------------------------------------------------------------------------------- /tests/testthat/test-tsl_join.R: -------------------------------------------------------------------------------- 1 | test_that("`tsl_join()` works", { 2 | 3 | tsl_a <- tsl_simulate( 4 | n = 2, 5 | cols = 2, 6 | irregular = TRUE, 7 | seed = 1 8 | ) 9 | 10 | tsl_b <- tsl_simulate( 11 | n = 3, 12 | cols = 2, 13 | irregular = TRUE, 14 | seed = 2 15 | ) |> 16 | tsl_colnames_set(names = c("c", "d")) 17 | 18 | #NA interpolation message 19 | expect_message( 20 | tsl <- tsl_join(tsl_a, tsl_b) 21 | ) 22 | 23 | expect_true( 24 | all( 25 | tsl_colnames_get(tsl)$a == c("a", "b", "c", "d") 26 | ) 27 | ) 28 | expect_true( 29 | all( 30 | tsl_colnames_get(tsl)$b == c("a", "b", "c", "d") 31 | ) 32 | ) 33 | 34 | }) 35 | -------------------------------------------------------------------------------- /tests/testthat/test-tsl_names.R: -------------------------------------------------------------------------------- 1 | test_that("`tsl_names` works", { 2 | 3 | tsl <- tsl_initialize( 4 | x = fagus_dynamics, 5 | name_column = "name", 6 | time_column = "time" 7 | ) 8 | 9 | tsl_clean <- tsl_names_clean( 10 | tsl = tsl, 11 | capitalize_first = TRUE, 12 | length = 4 13 | ) 14 | 15 | expect_true( 16 | all(tsl_names_get(tsl = tsl_clean) == c("Grmn", "Span", "Swdn") 17 | ) 18 | ) 19 | 20 | tsl <- tsl_names_set(tsl = tsl, names = c("X", "Y", "Z")) 21 | 22 | expect_true(all(tsl_names_get(tsl = tsl) %in% c("X", "Y", "Z"))) 23 | 24 | }) 25 | -------------------------------------------------------------------------------- /tests/testthat/test-tsl_ncol.R: -------------------------------------------------------------------------------- 1 | test_that("`tsl_ncol()` and `tsl_nrow()` works", { 2 | 3 | tsl <- tsl_simulate( 4 | n = 2, 5 | cols = 6, 6 | irregular = FALSE, 7 | rows = 100, 8 | seed = 1 9 | ) 10 | 11 | expect_equal(tsl_ncol(tsl = tsl)$A, 6) 12 | expect_equal(tsl_ncol(tsl = tsl)$B, 6) 13 | expect_equal(tsl_nrow(tsl = tsl)$A, 100) 14 | expect_equal(tsl_nrow(tsl = tsl)$B, 100) 15 | 16 | }) 17 | -------------------------------------------------------------------------------- /tests/testthat/test-tsl_repair.R: -------------------------------------------------------------------------------- 1 | test_that("`tsl_repair()` works", { 2 | 3 | x <- zoo_simulate(name = "x", cols = 1, na_fraction = 0.1, seed = 1) 4 | y <- zoo_simulate(name = "x", cols = 2, seed = 2) 5 | z <- zoo_simulate(name = "z", cols = 1, time_range = c(1, 100), seed = 3) 6 | colnames(x) <- c("b") 7 | z <- zoo::zoo(x = runif(nrow(z)), order.by = zoo::index(z)) 8 | tsl <- list(a = x, b = y, c = z) 9 | 10 | expect_message( 11 | tsl_diagnose(tsl = tsl, full = TRUE) 12 | ) |> 13 | suppressMessages() 14 | 15 | expect_message( 16 | tsl <- tsl_repair(tsl) 17 | ) |> 18 | suppressMessages() 19 | 20 | }) 21 | -------------------------------------------------------------------------------- /tests/testthat/test-tsl_resample.R: -------------------------------------------------------------------------------- 1 | test_that("`tsl_resample()` works", { 2 | 3 | tsl <- tsl_simulate( 4 | n = 2, 5 | rows = 100, 6 | irregular = TRUE, 7 | seed = 1 8 | ) 9 | 10 | expect_true(tsl_time_summary(tsl)$resolution_min != tsl_time_summary(tsl)$resolution_max) 11 | 12 | expect_message( 13 | tsl <- tsl_resample(tsl = tsl) 14 | ) |> 15 | suppressMessages() 16 | 17 | expect_equal(tsl_time_summary(tsl)$resolution_min, tsl_time_summary(tsl)$resolution_max) 18 | 19 | }) 20 | -------------------------------------------------------------------------------- /tests/testthat/test-tsl_smooth.R: -------------------------------------------------------------------------------- 1 | test_that("`tsl_smooth()` works", { 2 | 3 | tsl <- tsl_simulate(n = 2, 4 | seed = 1) 5 | 6 | tsl_sd <- tsl_stats(tsl = tsl)$sd 7 | 8 | tsl_smooth <- tsl_smooth(tsl = tsl, window = 5, f = mean) 9 | 10 | tsl_smooth_sd <- tsl_stats(tsl = tsl_smooth)$sd 11 | 12 | expect_true( 13 | all( 14 | tsl_sd > tsl_smooth_sd 15 | ) 16 | ) 17 | 18 | }) 19 | -------------------------------------------------------------------------------- /tests/testthat/test-tsl_stats.R: -------------------------------------------------------------------------------- 1 | test_that("`tsl_stats()` works", { 2 | 3 | tsl <- tsl_initialize( 4 | x = fagus_dynamics, 5 | name_column = "name", 6 | time_column = "time" 7 | ) 8 | 9 | df <- tsl_stats(tsl = tsl, lags = 3) 10 | 11 | expect_true( 12 | nrow(df) == 9 13 | ) 14 | 15 | 16 | expect_true( 17 | ncol(df) == 17 18 | ) 19 | 20 | expect_true( 21 | sum(is.na(df)) == 0 22 | ) 23 | 24 | expect_true( 25 | all( 26 | colnames(df) %in% c("name", "variable", "NA_count", "min", "q1", "median", "q3", "max", "mean", "sd", "range", "iq_range", "skewness", "kurtosis", "ac_lag_1", "ac_lag_2", "ac_lag_3") 27 | ) 28 | ) 29 | 30 | }) 31 | -------------------------------------------------------------------------------- /tests/testthat/test-tsl_subset.R: -------------------------------------------------------------------------------- 1 | test_that("`tsl_subset()` works", { 2 | 3 | tsl <- tsl_initialize( 4 | x = fagus_dynamics, 5 | name_column = "name", 6 | time_column = "time" 7 | ) 8 | 9 | tsl_new <- tsl_subset( 10 | tsl = tsl, names = c("Sweden", "Germany"), 11 | colnames = c("rainfall", "temperature"), 12 | time = c( 13 | "2010-01-01", 14 | "2015-01-01" 15 | ) 16 | ) 17 | 18 | expect_true( 19 | all(tsl_names_get(tsl = tsl_new) == c("Sweden", "Germany")) 20 | ) 21 | 22 | expect_equal(tsl_colnames_get(tsl = tsl_new)$Sweden, c("rainfall", "temperature")) 23 | 24 | expect_equal(tsl_colnames_get(tsl = tsl_new)$Germany, c("rainfall", "temperature")) 25 | 26 | expect_equal(unique(tsl_time(tsl = tsl_new)$begin), as.Date("2010-01-01")) 27 | 28 | expect_equal(unique(tsl_time(tsl = tsl_new)$end), as.Date("2015-01-01")) 29 | 30 | }) 31 | -------------------------------------------------------------------------------- /tests/testthat/test-tsl_time.R: -------------------------------------------------------------------------------- 1 | test_that("`tsl_time()` works", { 2 | 3 | tsl <- tsl_simulate( 4 | n = 3, 5 | rows = 150, 6 | time_range = c(Sys.Date() - 7 | 365, Sys.Date()), 8 | irregular = TRUE 9 | ) 10 | 11 | df <- tsl_time(tsl = tsl) 12 | 13 | expect_equal(class(df), "data.frame") 14 | expect_equal(nrow(df), length(tsl)) 15 | expect_true(all(df$name == tsl_names_get(tsl))) 16 | 17 | }) 18 | -------------------------------------------------------------------------------- /tests/testthat/test-tsl_to_df.R: -------------------------------------------------------------------------------- 1 | test_that("`tsl_to_df()` works", { 2 | tsl <- tsl_simulate(n = 3, rows = 10, time_range = c( 3 | "2010-01-01", 4 | "2020-01-01" 5 | ), irregular = FALSE, 6 | seed = 1) 7 | df <- tsl_to_df(tsl = tsl) 8 | expect_equal(class(df), "data.frame") 9 | expect_true(all(unique(unlist(tsl_colnames_get(tsl))) %in% colnames(df))) 10 | expect_equal(nrow(df), sum(unlist(tsl_nrow(tsl = tsl)))) 11 | 12 | }) 13 | -------------------------------------------------------------------------------- /tests/testthat/test-utils_as_time.R: -------------------------------------------------------------------------------- 1 | test_that("`utils_as_time()` works", { 2 | 3 | expect_equal(class(utils_as_time(x = c(-123120, 1200))), "numeric") 4 | 5 | expect_equal(class(utils_as_time(x = c("2022-03-17", "2024-02-05"))), "Date") 6 | 7 | expect_warning(utils_as_time(x = c("2022", "2024"))) 8 | 9 | expect_warning(utils_as_time(x = c("2022-02", "2024-03"))) 10 | 11 | expect_true("POSIXct" %in% class(utils_as_time(x = c("2022-03-17 12:30:45", "2024-02-05 11:15:45")))) 12 | 13 | }) 14 | -------------------------------------------------------------------------------- /tests/testthat/test-utils_clean_names.R: -------------------------------------------------------------------------------- 1 | test_that("`utils_clean_names()` works", { 2 | 3 | x <- c("GerMany", "spain", "SWEDEN") 4 | 5 | expect_true( 6 | all( 7 | utils_clean_names(x = x, capitalize_all = TRUE, length = 4) == c("GRMN", "SPAN", "SWED") 8 | ) 9 | ) 10 | 11 | expect_true( 12 | all( 13 | utils_clean_names( 14 | x = x, capitalize_first = TRUE, separator = "_", 15 | prefix = "my_prefix", suffix = "my_suffix" 16 | ) == c("My_prefix_GerMany_my_suffix", "My_prefix_spain_my_suffix", "My_prefix_SWEDEN_my_suffix") 17 | ) 18 | ) 19 | 20 | }) 21 | -------------------------------------------------------------------------------- /tests/testthat/test-utils_cluster.R: -------------------------------------------------------------------------------- 1 | test_that("`utils_cluster_silhouette()`, `utils_cluster_hclust_optimizer()` and `utils_cluster_kmeans_optimizer()` works", { 2 | 3 | tsl <- tsl_aggregate( 4 | tsl_subset(tsl_initialize( 5 | x = covid_prevalence, 6 | name_column = "name", time_column = "time" 7 | ), names = 1:10), 8 | new_time = "months", fun = max 9 | ) 10 | 11 | psi_matrix <- distantia_matrix(distantia(tsl = tsl, lock_step = TRUE)) 12 | hclust_optimization <- utils_cluster_hclust_optimizer(d = psi_matrix) 13 | 14 | expect_equal(class(hclust_optimization), "data.frame") 15 | expect_equal(colnames(hclust_optimization), c("clusters", "method", "silhouette_mean")) 16 | 17 | psi_hclust <- stats::hclust(d = as.dist(psi_matrix[[1]])) 18 | psi_hclust_labels <- stats::cutree(tree = psi_hclust, k = 3, ) 19 | expect_equal(colnames(utils_cluster_silhouette(labels = psi_hclust_labels, d = psi_matrix)), c("name", "cluster", "silhouette_width")) 20 | 21 | kmeans_optimization <- utils_cluster_kmeans_optimizer(d = psi_matrix) 22 | 23 | expect_equal(class(kmeans_optimization), "data.frame") 24 | expect_equal(colnames(kmeans_optimization), c("clusters", "silhouette_mean")) 25 | 26 | psi_kmeans <- stats::kmeans(x = as.dist(psi_matrix[[1]]), centers = 3) 27 | expect_equal(colnames(utils_cluster_silhouette(labels = psi_kmeans$cluster, d = psi_matrix)), c("name", "cluster", "silhouette_width")) 28 | 29 | }) 30 | -------------------------------------------------------------------------------- /tests/testthat/test-utils_coerce_time_class.R: -------------------------------------------------------------------------------- 1 | test_that("`utils_coerce_time_class()` works", { 2 | x <- utils_coerce_time_class( 3 | x = c("2024-01-01", "2024-02-01"), 4 | to = "Date" 5 | ) 6 | expect_equal(class(x), "Date") 7 | 8 | x <- utils_coerce_time_class( 9 | x = c("2024-01-01", "2024-02-01"), 10 | to = "POSIXct" 11 | ) 12 | expect_true("POSIXct" %in% class(x)) 13 | 14 | 15 | x <- utils_coerce_time_class( 16 | x = c("2024-01-01", "2024-02-01"), 17 | to = "numeric" 18 | ) 19 | expect_equal(class(x), "numeric") 20 | 21 | }) 22 | -------------------------------------------------------------------------------- /tests/testthat/test-utils_digits.R: -------------------------------------------------------------------------------- 1 | test_that("`utils_digits()` works", { 2 | expect_equal(utils_digits(x = 0), 0) 3 | expect_equal(utils_digits(x = 0.2), 1) 4 | expect_equal(utils_digits(x = 0.23), 2) 5 | expect_equal(utils_digits(x = 0.234), 3) 6 | }) 7 | -------------------------------------------------------------------------------- /tests/testthat/test-utils_distantia_df_split.R: -------------------------------------------------------------------------------- 1 | test_that("`utils_distantia_df_split()` works", { 2 | 3 | tsl <- tsl_initialize( 4 | x = fagus_dynamics, 5 | name_column = "name", 6 | time_column = "time" 7 | ) 8 | 9 | df <- distantia( 10 | tsl = tsl, distance = c("euclidean", "manhattan"), 11 | lock_step = c(TRUE, FALSE) 12 | ) 13 | 14 | df_split <- utils_distantia_df_split(df = df) 15 | 16 | expect_equal(length(df_split), 4) 17 | 18 | }) 19 | -------------------------------------------------------------------------------- /tests/testthat/test-utils_is_time.R: -------------------------------------------------------------------------------- 1 | test_that("`utils_is_time()` works", { 2 | 3 | expect_equal(utils_is_time(x = c("2024-01-01", "2024-02-01")), FALSE) 4 | 5 | expect_equal(utils_is_time(x = utils_as_time(x = c("2024-01-01", "2024-02-01"))), TRUE) 6 | 7 | }) 8 | -------------------------------------------------------------------------------- /tests/testthat/test-utils_new_time.R: -------------------------------------------------------------------------------- 1 | test_that("`utils_new_time()` works", { 2 | 3 | tsl <- tsl_initialize( 4 | x = fagus_dynamics, name_column = "name", 5 | time_column = "time" 6 | ) 7 | 8 | expect_equal(tsl_time_summary(tsl = tsl, keywords = "aggregate")$keywords, c("decades", "years", "quarters")) 9 | 10 | expect_message( 11 | new_time <- utils_new_time(tsl = tsl, new_time = NULL, keywords = "aggregate") 12 | ) 13 | 14 | expect_equal( 15 | unique( 16 | as.numeric( 17 | diff(new_time) 18 | ) 19 | ), 20 | c(90, 91, 92) 21 | ) 22 | 23 | }) 24 | -------------------------------------------------------------------------------- /tests/testthat/test-utils_optimize_loess.R: -------------------------------------------------------------------------------- 1 | test_that("`utils_optimize_loess()` works", { 2 | 3 | xy <- zoo_simulate(cols = 1, rows = 30, seed = 1) 4 | 5 | m <- utils_optimize_loess( 6 | x = as.numeric(zoo::index(xy)), 7 | y = xy[,1] 8 | ) 9 | 10 | expect_equal(class(m), "loess") 11 | 12 | }) 13 | -------------------------------------------------------------------------------- /tests/testthat/test-utils_optimize_spline.R: -------------------------------------------------------------------------------- 1 | test_that("`utils_optimize_spline()` works", { 2 | 3 | xy <- zoo_simulate(cols = 1, rows = 30, seed = 1) 4 | 5 | m <- utils_optimize_spline( 6 | x = as.numeric(zoo::index(xy)), 7 | y = xy[,1] 8 | ) 9 | 10 | expect_equal(class(m), "smooth.spline") 11 | 12 | }) 13 | -------------------------------------------------------------------------------- /tests/testthat/test-utils_prepare_zoo_list.R: -------------------------------------------------------------------------------- 1 | test_that("`utils_prepare_zoo_list()` works", { 2 | x <- utils_prepare_zoo_list( 3 | x = list( 4 | spain = fagus_dynamics[fagus_dynamics$name == "Spain", ], 5 | sweden = fagus_dynamics[fagus_dynamics$name == "Sweden", ] 6 | ), 7 | time_column = "time" 8 | ) 9 | 10 | expect_equal(class(x), "list") 11 | expect_equal(names(x), c("spain", "sweden")) 12 | }) 13 | -------------------------------------------------------------------------------- /tests/testthat/test-utils_rescale_vector.R: -------------------------------------------------------------------------------- 1 | test_that("`utils_rescale_vector()` works", { 2 | out <- utils_rescale_vector( 3 | x = stats::rnorm(100), new_min = 0, 4 | new_max = 100, 5 | ) 6 | expect_equal(range(out), c(0, 100)) 7 | }) 8 | -------------------------------------------------------------------------------- /tests/testthat/test-utils_time_keywords.R: -------------------------------------------------------------------------------- 1 | test_that("`utils_time_keywords()` works", { 2 | 3 | tsl <- tsl_simulate(time_range = c(Sys.time() - 60, Sys.time()), 4 | seed = 1) 5 | 6 | expect_equal(utils_time_keywords(tsl = tsl), "seconds") 7 | 8 | tsl <- tsl_simulate(time_range = c(Sys.time() - 600, Sys.time()), 9 | seed = 1) 10 | expect_equal(utils_time_keywords(tsl = tsl), c("minutes", "seconds")) 11 | 12 | tsl <- tsl_simulate(time_range = c(Sys.time() - 6000, Sys.time()), 13 | seed = 1) 14 | expect_equal(utils_time_keywords(tsl = tsl), c("hours", "minutes", "seconds")) 15 | 16 | tsl <- tsl_simulate(time_range = c(Sys.Date() - 10, Sys.Date()), 17 | seed = 1) 18 | expect_equal(utils_time_keywords(tsl = tsl), c("weeks", "days")) 19 | 20 | tsl <- tsl_simulate(time_range = c(Sys.Date() - 3650, Sys.Date()), 21 | seed = 1) 22 | expect_true(all(utils_time_keywords(tsl = tsl) %in% c("years", "quarters", "months", "weeks", "decades"))) 23 | }) 24 | -------------------------------------------------------------------------------- /tests/testthat/test-utils_time_keywords_dictionary.R: -------------------------------------------------------------------------------- 1 | test_that("`utils_time_keywords_dictionary()` works", { 2 | df <- utils_time_keywords_dictionary() 3 | expect_equal(class(df), "data.frame") 4 | expect_equal(colnames(df), c("pattern", "keyword")) 5 | }) 6 | -------------------------------------------------------------------------------- /tests/testthat/test-utils_time_keywords_translate.R: -------------------------------------------------------------------------------- 1 | test_that("`utils_time_keywords_translate()` works", { 2 | 3 | expect_equal(utils_time_keywords_translate(keyword = "1000 years"), "millennia") 4 | expect_equal(utils_time_keywords_translate(keyword = "1000 y"), "millennia") 5 | expect_equal(utils_time_keywords_translate(keyword = "thousands"), "millennia") 6 | expect_equal(utils_time_keywords_translate(keyword = "year"), "years") 7 | expect_equal(utils_time_keywords_translate(keyword = "y"), "years") 8 | expect_equal(utils_time_keywords_translate(keyword = "d"), "days") 9 | expect_equal(utils_time_keywords_translate(keyword = "day"), "days") 10 | expect_equal(utils_time_keywords_translate(keyword = "s"), "seconds") 11 | expect_equal(utils_time_keywords_translate(keyword = "sec"), "seconds") 12 | 13 | }) 14 | -------------------------------------------------------------------------------- /tests/testthat/test-utils_time_units.R: -------------------------------------------------------------------------------- 1 | test_that("`utils_time_units()` works", { 2 | df <- utils_time_units() 3 | expect_equal(class(df), "data.frame") 4 | expect_equal(colnames(df), c("base_units", "units", "Date", "POSIXct", "numeric", "integer")) 5 | }) 6 | -------------------------------------------------------------------------------- /tests/testthat/test-zoo_aggregate.R: -------------------------------------------------------------------------------- 1 | test_that("`zoo_aggregate()` works", { 2 | 3 | x <- zoo_simulate(rows = 1000, time_range = c("0000-01-01", as.character(Sys.Date())), seed = 1) 4 | 5 | x_millennia <- zoo_aggregate(x = x, new_time = "millennia", f = mean) 6 | 7 | expect_equal(nrow(x_millennia), 4) 8 | 9 | x_centuries <- zoo_aggregate(x = x, new_time = "centuries", f = max) 10 | 11 | expect_equal(nrow(x_centuries), 22) 12 | 13 | }) 14 | -------------------------------------------------------------------------------- /tests/testthat/test-zoo_names.R: -------------------------------------------------------------------------------- 1 | test_that("`zoo_name_clean()` works", { 2 | 3 | x <- zoo_simulate(seed = 1) 4 | expect_equal(zoo_name_get(x = x), "A") 5 | 6 | x <- zoo_name_set(x = x, name = "My.New.name") 7 | expect_equal(zoo_name_get(x = x), "My.New.name") 8 | 9 | x <- zoo_name_clean(x = x, lowercase = TRUE) 10 | expect_equal(zoo_name_get(x = x), "my_new_name") 11 | 12 | }) 13 | -------------------------------------------------------------------------------- /tests/testthat/test-zoo_permute.R: -------------------------------------------------------------------------------- 1 | test_that("`zoo_permute()` works", { 2 | 3 | x <- zoo_simulate(cols = 2, seed = 1) 4 | 5 | x_free <- zoo_permute(x = x, permutation = "free", repetitions = 2) 6 | 7 | expect_equal( 8 | length(x_free), 2 9 | ) 10 | 11 | expect_equal( 12 | nrow(x), nrow(x_free[[1]]) 13 | ) 14 | 15 | }) 16 | -------------------------------------------------------------------------------- /tests/testthat/test-zoo_resample.R: -------------------------------------------------------------------------------- 1 | test_that("`zoo_resample()` works", { 2 | 3 | x <- zoo_simulate(cols = 2, rows = 50, time_range = c( 4 | "2010-01-01", 5 | "2020-01-01" 6 | ), irregular = TRUE, 7 | seed = 1 8 | ) 9 | 10 | x_intervals <- diff(zoo::index(x)) 11 | 12 | expect_true(length(unique(x_intervals)) > 1) 13 | 14 | new_time <- seq.Date( 15 | from = min(zoo::index(x)), to = max(zoo::index(x)), 16 | by = floor(min(x_intervals)) 17 | ) 18 | 19 | x_linear <- zoo_resample(x = x, new_time = new_time, method = "linear") 20 | 21 | expect_equal( 22 | new_time, zoo::index(x_linear) 23 | ) 24 | 25 | x_spline <- zoo_resample(x = x, new_time = new_time, method = "spline") 26 | 27 | expect_equal( 28 | new_time, zoo::index(x_spline) 29 | ) 30 | 31 | x_loess <- zoo_resample(x = x, new_time = new_time, method = "loess") 32 | 33 | expect_equal( 34 | new_time, zoo::index(x_loess) 35 | ) 36 | 37 | 38 | }) 39 | -------------------------------------------------------------------------------- /tests/testthat/test-zoo_simulate.R: -------------------------------------------------------------------------------- 1 | test_that("`zoo_simulate()` works", { 2 | x <- zoo_simulate(seed = 1) 3 | expect_equal(class(x), "zoo") 4 | expect_equal(attributes(x)$name, "A") 5 | expect_equal(names(x), c("a", "b", "c", "d", "e")) 6 | }) 7 | -------------------------------------------------------------------------------- /tests/testthat/test-zoo_smooth.R: -------------------------------------------------------------------------------- 1 | test_that("`zoo_smooth()` works", { 2 | 3 | x <- zoo_simulate(cols = 1, seed = 1) 4 | 5 | x_smooth <- zoo_smooth_exponential(x = x, alpha = 0.2) 6 | 7 | expect_true(sd(x[, 1]) > sd(x_smooth[, 1])) 8 | 9 | x_smooth <- zoo_smooth_window(x = x) 10 | 11 | expect_true(sd(x[, 1]) > sd(x_smooth[, 1])) 12 | 13 | }) 14 | -------------------------------------------------------------------------------- /tests/testthat/test-zoo_time.R: -------------------------------------------------------------------------------- 1 | test_that("`zoo_time()` works", { 2 | x <- zoo_simulate(rows = 150, time_range = c( 3 | Sys.Date() - 365, 4 | Sys.Date() 5 | ), irregular = TRUE, seed = 1) 6 | 7 | df <- zoo_time(x = x) 8 | 9 | expect_equal(class(df), "data.frame") 10 | expect_true(all(colnames(df) %in% c("name", "rows", "class", "units", "length", "resolution", "begin", "end", "keywords"))) 11 | }) 12 | -------------------------------------------------------------------------------- /tests/testthat/test-zoo_to_tsl.R: -------------------------------------------------------------------------------- 1 | test_that("`zoo_to_tsl()` works", { 2 | x <- zoo_simulate(seed = 1) 3 | 4 | tsl <- zoo_to_tsl(x = x) 5 | expect_equal(class(tsl), "list") 6 | expect_equal(class(tsl[[1]]), "zoo") 7 | expect_equal(names(tsl), "A") 8 | expect_equal(attributes(tsl[[1]])$name, "A") 9 | }) 10 | -------------------------------------------------------------------------------- /tests/testthat/test-zoo_vector_to_matrix.R: -------------------------------------------------------------------------------- 1 | test_that("`zoo_vector_to_matrix()` works", { 2 | x <- zoo::zoo(x = runif(100)) 3 | expect_equal(is.matrix(zoo::coredata(x)), FALSE) 4 | y <- zoo_vector_to_matrix(x = x) 5 | expect_equal(is.matrix(zoo::coredata(y)), TRUE) 6 | }) 7 | --------------------------------------------------------------------------------