verbose = FALSE)
d3_plot_situation(all_lines, events, samples_pts, continuous_kernel, scales = c(1,1,3))
-
-The larger the bandwidth, the more common links the events share in
+
+The larger the bandwidth, the more common links the events share in
their range.
-
-
+
+
References
diff --git a/docs/articles/web_vignettes/SpaceTimeDBscan.html b/docs/articles/web_vignettes/SpaceTimeDBscan.html
index a90cb1aa..99ef5f49 100644
--- a/docs/articles/web_vignettes/SpaceTimeDBscan.html
+++ b/docs/articles/web_vignettes/SpaceTimeDBscan.html
@@ -110,7 +110,7 @@
-
-And finally, we will plot the time period of each cluster.
+
+And finally, we will plot the time period of each cluster.
diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml
index 316258ee..1adb8b91 100644
--- a/docs/pkgdown.yml
+++ b/docs/pkgdown.yml
@@ -11,5 +11,5 @@ articles:
AdaptiveBW: web_vignettes/AdaptiveBW.html
NKDEdetailed: web_vignettes/NKDEdetailed.html
SpaceTimeDBscan: web_vignettes/SpaceTimeDBscan.html
-last_built: 2023-11-02T00:46Z
+last_built: 2024-01-02T03:23Z
diff --git a/docs/reference/figures/unnamed-chunk-8-1.png b/docs/reference/figures/unnamed-chunk-8-1.png
index 4e9ac0bf..219ffe2c 100644
Binary files a/docs/reference/figures/unnamed-chunk-8-1.png and b/docs/reference/figures/unnamed-chunk-8-1.png differ
diff --git a/inst/extdata/results_vignette_kfunc.rda b/inst/extdata/results_vignette_kfunc.rda
index 7d325a65..27f2dc1e 100644
Binary files a/inst/extdata/results_vignette_kfunc.rda and b/inst/extdata/results_vignette_kfunc.rda differ
diff --git a/inst/extdata/results_vignette_network_build.rda b/inst/extdata/results_vignette_network_build.rda
index bedf37b5..27356482 100644
Binary files a/inst/extdata/results_vignette_network_build.rda and b/inst/extdata/results_vignette_network_build.rda differ
diff --git a/inst/extdata/results_vignette_nkde.rda b/inst/extdata/results_vignette_nkde.rda
index d4796d9e..a5f55d6c 100644
Binary files a/inst/extdata/results_vignette_nkde.rda and b/inst/extdata/results_vignette_nkde.rda differ
diff --git a/inst/extdata/results_vignette_tnkde.rda b/inst/extdata/results_vignette_tnkde.rda
index f18647b5..a1dbc870 100644
Binary files a/inst/extdata/results_vignette_tnkde.rda and b/inst/extdata/results_vignette_tnkde.rda differ
diff --git a/inst/extdata/results_vignette_wmat.rda b/inst/extdata/results_vignette_wmat.rda
index 87b73aa9..adc514da 100644
Binary files a/inst/extdata/results_vignette_wmat.rda and b/inst/extdata/results_vignette_wmat.rda differ
diff --git a/man/figures/unnamed-chunk-8-1.png b/man/figures/unnamed-chunk-8-1.png
index 4e9ac0bf..219ffe2c 100644
Binary files a/man/figures/unnamed-chunk-8-1.png and b/man/figures/unnamed-chunk-8-1.png differ
diff --git a/test.log b/test.log
new file mode 100644
index 00000000..e77eef18
--- /dev/null
+++ b/test.log
@@ -0,0 +1,297 @@
+✔ | F W S OK | Context
+
⠏ | 0 | adaptive_bw_sf
⠏ | 0 | testing functions for adptative bandwidth in NKDE [1] "checking inputs ..."
+[1] "prior data preparation ..."
+[1] "start calculating the kernel values for the adaptive bandwidth..."
+[1] " quadra 1/3"
+[1] " build graph ..."
+[1] " calculating NKDE values ..."
+[1] " quadra 2/3"
+[1] " build graph ..."
+[1] " calculating NKDE values ..."
+[1] " quadra 3/3"
+[1] " build graph ..."
+[1] " calculating NKDE values ..."
+[1] "Splitting the data with the spatial grid ..."
+[1] "start calculating the kernel values ..."
+[1] " quadra 1/3"
+[1] " build graph ..."
+[1] " calculating NKDE values ..."
+[1] " quadra 2/3"
+[1] " build graph ..."
+[1] " calculating NKDE values ..."
+[1] " quadra 3/3"
+[1] " build graph ..."
+[1] " calculating NKDE values ..."
+[1] "combining the results ..."
+
⠋ | 1 | testing functions for adptative bandwidth in NKDE [1] "precalculated bws : 3.73661539510889;2.93822642599985;2.45923541821083"
+[1] "checking inputs ..."
+[1] "prior data preparation ..."
+[1] "calculating the local bandwidth ..."
+[1] "start calculating the kernel values for the adaptive bandwidth..."
+[1] "starting the kernel calculations ..."
+[1] "starting the kernel calculations ..."
+[1] "combining the results ..."
+
⠙ | 2 | testing functions for adptative bandwidth in NKDE [1] "checking inputs ..."
+[1] "prior data preparation ..."
+[1] "start calculating the kernel values for the adaptive bandwidth..."
+[1] " quadra 1/3"
+[1] " build graph ..."
+[1] " calculating NKDE values ..."
+[1] " quadra 2/3"
+[1] " build graph ..."
+[1] " calculating NKDE values ..."
+[1] " quadra 3/3"
+[1] " build graph ..."
+[1] " calculating NKDE values ..."
+[1] "Splitting the data with the spatial grid ..."
+[1] "start calculating the kernel values ..."
+[1] " quadra 1/3"
+[1] " build graph ..."
+[1] " calculating NKDE values ..."
+[1] " quadra 2/3"
+[1] " build graph ..."
+[1] " calculating NKDE values ..."
+[1] " quadra 3/3"
+[1] " build graph ..."
+[1] " calculating NKDE values ..."
+[1] "combining the results ..."
+
⠹ | 3 | testing functions for adptative bandwidth in NKDE
✔ | 3 | testing functions for adptative bandwidth in NKDE [1.7s]
+
⠏ | 0 | adaptive_bw_tnkde_interaction_sf
⠏ | 0 | testing functions for adptative bandwidth with interaction in TNKDE [1] "checking inputs ..."
+[1] "prior data preparation ..."
+[1] "start calculating the kernel values for the adaptive bandwidth..."
+[1] "start calculating the kernel values ..."
+[1] " quadra 1/1"
+[1] " build graph ..."
+[1] " calculating NKDE values ..."
+[1] "combining the results ..."
+
⠋ | 1 | testing functions for adptative bandwidth with interaction in TNKDE [1] "checking inputs ..."
+[1] "prior data preparation ..."
+[1] "start calculating the kernel values for the adaptive bandwidth..."
+[1] "starting the kernel calculations ..."
+[1] " build graph ..."
+[1] " calculating NKDE values ..."
+[1] "combining the results ..."
+
⠙ | 2 | testing functions for adptative bandwidth with interaction in TNKDE [1] "start calculating the kernel values for the adaptive bandwidth..."
+
⠹ | 3 | testing functions for adptative bandwidth with interaction in TNKDE [1] "start calculating the kernel values for the adaptive bandwidth..."
+
⠦ | 7 | testing functions for adptative bandwidth with interaction in TNKDE
✔ | 8 | testing functions for adptative bandwidth with interaction in TNKDE [1.3s]
+
⠏ | 0 | base_kernels_sf
⠏ | 0 | testing the base kernel implemented
✔ | 2 | testing the base kernel implemented
+
⠏ | 0 | basics_listw_sf
⠏ | 0 | basic tests for the neighbour matrices creation [1] "generating the starting points"
+[1] "snapping the points to the lines (only once)"
+[1] "starting the network part"
+[1] "working on quadra : 1/1"
+[1] "adding the points as vertices to nearest lines"
+[1] "splitting the lines for the network"
+[1] "generating the network"
+[1] "calculating the distances on the network"
+[1] "building the final listw object"
+[1] "finally generating the listw object ..."
+
⠙ | 2 | basic tests for the neighbour matrices creation
✔ | 2 | basic tests for the neighbour matrices creation [0.3s]
+
⠏ | 0 | border_correction_sf
⠏ | 0 | testing function used to apply border correction in NKDE
⠙ | 2 | testing function used to apply border correction in NKDE
⠹ | 3 | testing function used to apply border correction in NKDE
⠸ | 4 | testing function used to apply border correction in NKDE
✔ | 4 | testing function used to apply border correction in NKDE [1.1s]
+
⠏ | 0 | bw_selection_sf
⠏ | 0 | testing the bandwidth selection functions [1] 1
+[1] 1
+
⠙ | 2 | testing the bandwidth selection functions [1] 1
+[1] 1
+
⠸ | 4 | testing the bandwidth selection functions [1] "checking inputs ..."
+[1] "prior data preparation ..."
+[1] "Calculating the correction factor if required"
+[1] "Splittig the dataset within the grid ..."
+[1] "start calculating the CV values ..."
+
|
| | 0%[1] 1
+
|
|=====================================================================================================================| 100%
⠴ | 6 | testing the bandwidth selection functions [1] "checking inputs ..."
+[1] "prior data preparation ..."
+[1] "Calculating the correction factor if required"
+[1] "start calculating the CV values ..."
+
|
| | 0%
⠧ | 8 | testing the bandwidth selection functions
⠇ | 9 | testing the bandwidth selection functions [1] "checking inputs ..."
+[1] "prior data preparation ..."
+[1] "Calculating the correction factor if required"
+[1] "start calculating the CV values ..."
+[1] "checking inputs ..."
+[1] "prior data preparation ..."
+[1] "Calculating the correction factor if required"
+[1] "Splittig the dataset within the grid ..."
+[1] "start calculating the CV values ..."
+
|
| | 0%[1] 1
+
|
|============================= | 25%[1] 2
+
|
|========================================================== | 50%[1] 3
+
|
|======================================================================================== | 75%[1] 4
+
|
|=====================================================================================================================| 100%
⠏ | 10 | testing the bandwidth selection functions [1] "checking inputs ..."
+[1] "prior data preparation ..."
+[1] "Calculating the correction factor if required"
+[1] "start calculating the CV values ..."
+ bw cvl_scores
+1 200 3.068423e+12
+2 300 9.065686e+12
+3 400 1.812569e+13
+ bw cvl_scores
+1 200 3.068423e+12
+2 300 9.065686e+12
+3 400 1.812569e+13
+ bw cvl_scores
+1 200 3.068423e+12
+2 300 9.065686e+12
+3 400 1.812569e+13
+
⠋ | 11 | testing the bandwidth selection functions [1] "checking inputs ..."
+[1] "prior data preparation ..."
+[1] "Calculating the correction factor if required"
+[1] "start calculating the kernel values for the adaptive bandwidth..."
+[1] " quadra 1/3"
+[1] " build graph ..."
+[1] " calculating NKDE values ..."
+[1] " quadra 2/3"
+[1] " build graph ..."
+[1] " calculating NKDE values ..."
+[1] " quadra 3/3"
+[1] " build graph ..."
+[1] " calculating NKDE values ..."
+[1] "Splittig the dataset within the grid ..."
+[1] "start calculating the CV values ..."
+
|
| | 0%[1] 1
+
|
|======================================= | 33%[1] 2
+
|
|============================================================================== | 67%[1] 3
+
|
|=====================================================================================================================| 100%
⠙ | 12 | testing the bandwidth selection functions [1] 1
+
⠹ | 13 | testing the bandwidth selection functions
✔ | 13 | testing the bandwidth selection functions [7.6s]
+
⠏ | 0 | bw_selection_tnkde_sf
⠏ | 0 | testing the bandwidth selection functions for tnkde
⠋ | 1 | testing the bandwidth selection functions for tnkde
⠙ | 2 | testing the bandwidth selection functions for tnkde [1] "prior data preparation ..."
+[1] "Calculating the correction factor if required"
+[1] "start calculating the CV values ..."
+
|
| | 0%
|
|=====================================================================================================================| 100%[1] "prior data preparation ..."
+[1] "Calculating the correction factor if required"
+[1] "start calculating the CV values ..."
+
|
| | 0%
|
|=====================================================================================================================| 100%
⠸ | 4 | testing the bandwidth selection functions for tnkde [1] "prior data preparation ..."
+[1] "Calculating the correction factor if required"
+[1] "start calculating the CV values ..."
+
|
| | 0%
|
|=====================================================================================================================| 100%[1] "prior data preparation ..."
+[1] "Calculating the correction factor if required"
+[1] "splitting the data by the grid..."
+[1] "start calculating the CV values ..."
+
⠼ | 5 | testing the bandwidth selection functions for tnkde
⠴ | 6 | testing the bandwidth selection functions for tnkde
⠦ | 7 | testing the bandwidth selection functions for tnkde
⠧ | 8 | testing the bandwidth selection functions for tnkde
✔ | 8 | testing the bandwidth selection functions for tnkde [1.5s]
+
⠏ | 0 | geometrical_functions_sf
⠏ | 0 | Testing the geometrical functions of the package
|
| | 0%
|
|======================= | 20%
|
|=============================================== | 40%
|
|====================================================================== | 60%
|
|============================================================================================== | 80%
|
|=====================================================================================================================| 100%
⠴ | 6 | Testing the geometrical functions of the package
⠋ | 11 | Testing the geometrical functions of the package
|
| | 0%
|
|============================= | 25%
|
|========================================================== | 50%
|
|======================================================================================== | 75%
|
|=====================================================================================================================| 100%
✔ | 12 | Testing the geometrical functions of the package [0.3s]
+
⠏ | 0 | graph_functions_sf
⠏ | 0 | testing the graph functions
✔ | 2 | testing the graph functions
+
⠏ | 0 | isochrone_sf
⠏ | 0 | testing the isochrone creation functions
⠙ | 2 | testing the isochrone creation functions
✔ | 2 | testing the isochrone creation functions [0.2s]
+
⠏ | 0 | testing the isochrone creation functions
⠋ | 1 | testing the isochrone creation functions
✔ | 1 | testing the isochrone creation functions [0.1s]
+
⠏ | 0 | k_functions_sf
⠏ | 0 | testing functions for k and g function analysis [1] "Preparing data ..."
+[1] "Snapping points on lines ..."
+[1] "Building graph ..."
+[1] "Calculating k and g functions ..."
+[1] "Calculating the simulations ..."
+
|
| | 0%
|
|======================= | 20%
|
|=============================================== | 40%
|
|====================================================================== | 60%
|
|============================================================================================== | 80%
|
|=====================================================================================================================| 100%
⠋ | 1 0 | testing functions for k and g function analysis [1] "Preparing data ..."
+[1] "Snapping points on lines ..."
+[1] "Building graph ..."
+[1] "Calculating k and g functions ..."
+[1] "Calculating the simulations ..."
+
|
| | 0%
|
|======================= | 20%
|
|=============================================== | 40%
|
|====================================================================== | 60%
|
|============================================================================================== | 80%
|
|=====================================================================================================================| 100%
⠹ | 1 2 | testing functions for k and g function analysis
⠼ | 1 4 | testing functions for k and g function analysis [1] "Preparing data ..."
+[1] "Snapping points on lines ..."
+[1] "Building graph ..."
+[1] "Calculating k and g functions ..."
+[1] "Calculating the simulations ..."
+
⠴ | 2 4 | testing functions for k and g function analysis [1] "Preparing data ..."
+[1] "Snapping points on lines ..."
+[1] "Building graph ..."
+[1] "Calculating k and g functions ..."
+[1] "Calculating the simulations ..."
+
⠧ | 3 5 | testing functions for k and g function analysis [1] "Preparing data ..."
+[1] "Snapping points on lines ..."
+[1] "Building graph ..."
+[1] "Calculating k and g functions ..."
+[1] "Calculating the simulations ..."
+
|
| | 0%
⠏ | 4 6 | testing functions for k and g function analysis [1] "Preparing data ..."
+[1] "Snapping points on lines ..."
+[1] "Building graph ..."
+[1] "Calculating k and g functions ..."
+[1] "Calculating the simulations ..."
+
|
| | 0%
|
|======================= | 20%
|
|=============================================== | 40%
|
|====================================================================== | 60%
|
|============================================================================================== | 80%
|
|=====================================================================================================================| 100%
⠙ | 4 8 | testing functions for k and g function analysis
✔ | 4 8 | testing functions for k and g function analysis [1.4s]
+───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
+Warning ('test_k_functions_sf.R:28:3'): Testing the simple k function
+`aes_string()` was deprecated in ggplot2 3.0.0.
+ℹ Please use tidy evaluation idioms with `aes()`.
+ℹ See also `vignette("ggplot2-in-packages")` for more information.
+Backtrace:
+ 1. spNetwork::kfunctions(...)
+ at test_k_functions_sf.R:28:2
+ 4. ggplot2::aes_string(x = "distances", ymin = "lower_k", ymax = "upper_k")
+ 5. ggplot2:::deprecate_soft0(...)
+
+Warning ('test_k_functions_sf.R:332:3'): Testing the multicore simple k function
+UNRELIABLE VALUE: One of the ‘future.apply’ iterations (‘future_lapply-1’) unexpectedly generated random numbers without declaring so. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'future.seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'future.seed = NULL', or set option 'future.rng.onMisuse' to "ignore".
+Backtrace:
+ 1. spNetwork::kfunctions.mc(...)
+ at test_k_functions_sf.R:332:2
+ 2. progressr::with_progress(...)
+ at spNetwork/R/k_functions_sf.R:599:6
+ 3. progressr:::flush_conditions(conditions)
+ at spNetwork/R/k_functions_sf.R:599:6
+
+Warning ('test_k_functions_sf.R:368:3'): Testing the multicore cross k function
+UNRELIABLE VALUE: One of the ‘future.apply’ iterations (‘future_lapply-1’) unexpectedly generated random numbers without declaring so. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'future.seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'future.seed = NULL', or set option 'future.rng.onMisuse' to "ignore".
+Backtrace:
+ 1. spNetwork::cross_kfunctions.mc(...)
+ at test_k_functions_sf.R:368:2
+ 2. progressr::with_progress(...)
+ at spNetwork/R/k_functions_sf.R:1077:4
+ 3. progressr:::flush_conditions(conditions)
+ at spNetwork/R/k_functions_sf.R:1077:4
+
+Warning ('test_k_functions_sf.R:407:3'): Testing the simple k function in space-time
+UNRELIABLE VALUE: One of the ‘future.apply’ iterations (‘future_lapply-1’) unexpectedly generated random numbers without declaring so. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'future.seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'future.seed = NULL', or set option 'future.rng.onMisuse' to "ignore".
+Backtrace:
+ 1. spNetwork::k_nt_functions.mc(...)
+ at test_k_functions_sf.R:407:2
+ 2. progressr::with_progress(...)
+ at spNetwork/R/k_functions_nettime_sf.R:452:6
+ 3. progressr:::flush_conditions(conditions)
+ at spNetwork/R/k_functions_nettime_sf.R:452:6
+───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
+
⠏ | 0 | kernels
⠏ | 0 | testing the kernel functions [1] "checking inputs ..."
+[1] "prior data preparation ..."
+[1] "Splitting the data with the spatial grid ..."
+[1] "start calculating the kernel values ..."
+[1] " quadra 1/1"
+[1] " build graph ..."
+[1] " calculating NKDE values ..."
+
|
| | 0%
|
|=====================================================================================================================| 100%[1] "combining the results ..."
+
⠙ | 2 | testing the kernel functions
⠸ | 4 | testing the kernel functions
⠼ | 5 | testing the kernel functions
⠴ | 6 | testing the kernel functions
✔ | 6 | testing the kernel functions [0.6s]
+
⠏ | 0 | knn_sf
⠏ | 0 | testing the knn functions
⠙ | 2 | testing the knn functions
⠸ | 4 | testing the knn functions
✔ | 5 | testing the knn functions [0.4s]
+
⠏ | 0 | listw_symetry_sf
⠏ | 0 | symetry and comparison between simple and multicore
⠋ | 1 | symetry and comparison between simple and multicore
✔ | 1 | symetry and comparison between simple and multicore [7.3s]
+
⠏ | 0 | nkde_execution_functions_sf
⠏ | 0 | testing function used to perform NKDE
✔ | 1 | testing function used to perform NKDE
+
⠏ | 0 | nkde_manual_bws
⠏ | 0 | testing the kernel functions with manually changed bandwidths
⠙ | 2 | testing the kernel functions with manually changed bandwidths
✔ | 2 | testing the kernel functions with manually changed bandwidths [0.2s]
+
⠏ | 0 | spatial_indexing
⠏ | 0 | testing the spatial indexing functions
✔ | 1 | testing the spatial indexing functions
+
⠏ | 0 | splitting_functions
⠏ | 0 | testing the base kernel implemented
⠋ | 1 | testing the base kernel implemented
⠙ | 2 | testing the base kernel implemented
✔ | 2 | testing the base kernel implemented [0.8s]
+
⠏ | 0 | tnkde_sf
⠏ | 0 | testing the kernel functions [1] "checking inputs ..."
+[1] "prior data preparation ..."
+[1] "start calculating the kernel values ..."
+[1] " quadra 1/1"
+[1] " build graph ..."
+[1] " calculating NKDE values ..."
+
|
| | 0%
|
|=====================================================================================================================| 100%[1] "combining the results ..."
+[1] "checking inputs ..."
+[1] "prior data preparation ..."
+[1] "start calculating the kernel values ..."
+[1] " quadra 1/1"
+[1] " build graph ..."
+[1] " calculating NKDE values ..."
+[1] "combining the results ..."
+
⠙ | 2 | testing the kernel functions [1] "checking inputs ..."
+[1] "prior data preparation ..."
+[1] "start calculating the kernel values ..."
+[1] " quadra 1/1"
+[1] " build graph ..."
+[1] " calculating NKDE values ..."
+[1] "combining the results ..."
+
⠹ | 3 | testing the kernel functions [1] "checking inputs ..."
+[1] "prior data preparation ..."
+[1] "start calculating the kernel values ..."
+[1] " quadra 1/1"
+[1] " build graph ..."
+[1] " calculating NKDE values ..."
+[1] "combining the results ..."
+[1] "checking inputs ..."
+[1] "prior data preparation ..."
+[1] "starting the kernel calculations ..."
+[1] " build graph ..."
+[1] " calculating NKDE values ..."
+[1] "combining the results ..."
+
⠸ | 4 | testing the kernel functions
✔ | 4 | testing the kernel functions [0.7s]
+
+══ Results ════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
+Duration: 25.9 s
+
+[ FAIL 0 | WARN 4 | SKIP 0 | PASS 87 ]
diff --git a/vignettes/NKDE.Rmd b/vignettes/NKDE.Rmd
index b167f642..df46d813 100644
--- a/vignettes/NKDE.Rmd
+++ b/vignettes/NKDE.Rmd
@@ -576,24 +576,24 @@ For both, one can use the multicore version of the functions to speed up the cal
```{r eval = FALSE}
bws_selection_cv <- bw_cv_likelihood_calc(
- bws = seq(200,700,50),
+ bws = seq(50,700,50),
lines = mtl_network, events = bike_accidents,
w = rep(1,nrow(bike_accidents)),
kernel_name = "quartic", method = "discontinuous",
diggle_correction = FALSE, study_area = NULL,
max_depth = 8,
- digits=2, tol=0.1, agg=5,
+ digits=2, tol=0.1, agg=5,
sparse=TRUE, grid_shape=c(1,1),
verbose=FALSE, check=TRUE)
bws_selection_cvl <- bw_cvl_calc(
- bws = seq(50,700, 50),
+ bws = seq(50,700,50),
lines = mtl_network, events = bike_accidents,
w = rep(1,nrow(bike_accidents)),
kernel_name = "quartic", method = "discontinuous",
diggle_correction = FALSE, study_area = NULL,
max_depth = 8,
- digits=2, tol=0.1, agg=5,
+ digits=2, tol=0.1, agg=5,
sparse=TRUE, grid_shape=c(1,1),
verbose=FALSE, check=TRUE)
@@ -602,22 +602,52 @@ bws_selection_cvl <- bw_cvl_calc(
It is also possible to do bandwidth selection with adaptive bandwidth. In that context, we search for the optimal global bandwidth. It requires more computation because for each bandwidth, we need to estimate the density twice, one with the global bandwidth, and one with the local bandwidths obtained from the density estimation.
```{r eval = FALSE}
-bws_selection_cv_adpt <- bw_cv_likelihood_calc(
- bws = seq(200,700,50),
- lines = mtl_network, events = bike_accidents,
+bws_selection_cv_adpt_dis <- bw_cv_likelihood_calc(
+ bws = seq(50,700,50),
+ trim_bws = seq(50,700,50)*2,
+ lines = mtl_network,
+ events = bike_accidents,
w = rep(1,nrow(bike_accidents)),
adaptive = TRUE,
- kernel_name = "quartic", method = "discontinuous",
- diggle_correction = FALSE, study_area = NULL,
+ kernel_name = "quartic",
+ method = "discontinuous",
+ diggle_correction = FALSE,
+ study_area = NULL,
max_depth = 8,
- digits=2, tol=0.1, agg=5,
- sparse=TRUE, grid_shape=c(1,1),
- verbose=FALSE, check=TRUE)
+ digits=2,
+ tol=0.1,
+ agg=5,
+ sparse=TRUE,
+ grid_shape=c(1,1),
+ verbose=TRUE,
+ check=TRUE)
+
+bws_selection_cv_adpt_cont <- bw_cv_likelihood_calc(
+ bws = seq(50,700,50),
+ trim_bws = seq(50,700,50)*2,
+ lines = mtl_network,
+ events = bike_accidents,
+ w = rep(1,nrow(bike_accidents)),
+ adaptive = TRUE,
+ kernel_name = "quartic",
+ method = "continuous",
+ diggle_correction = FALSE,
+ study_area = NULL,
+ max_depth = 8,
+ digits=2,
+ tol=0.1,
+ agg=5,
+ sparse=TRUE,
+ grid_shape=c(1,1),
+ verbose=TRUE,
+ check=TRUE)
cv_values <- data.frame(
"bw" = bws_selection_cv$bw,
"cv_likelihood" = bws_selection_cv$cv_scores,
- "cvl_crit" = bws_selection_cvl$cvl_scores
+ "cvl_crit" = bws_selection_cvl$cvl_scores,
+ "cv_likelihood_adpt_dis" = bws_selection_cv_adpt_dis$cv_scores,
+ "cv_likelihood_adpt_cont" = bws_selection_cv_adpt_cont$cv_scores
)
```
@@ -625,7 +655,7 @@ cv_values <- data.frame(
knitr::kable(cv_values, digits = 2,row.names = FALSE)
```
-As one can see here, the cross-validation approach suggests a value between 550 and 600 metres, while the Cronie and Van Lieshout's Criterion would suggest a bandwidth inferior to 50 metres and is probably not adapted for this dataset. With an adaptive bandwidth, the best bandwidth would be around 500 and 550 metres.
+As one can see here, the cross-validation approach suggests a value between 550 and 600 metres, while the Cronie and Van Lieshout's Criterion would suggest a bandwidth inferior to 50 metres and is probably not adapted for this dataset. With an adaptive bandwidth, the best bandwidth would be around 450 and 500 metres for the discontinuous kernel, and between 550 and 600 for the continuous kernel.
## Complementary functions
diff --git a/vignettes/TNKDE.Rmd b/vignettes/TNKDE.Rmd
index a7332249..835c2a52 100644
--- a/vignettes/TNKDE.Rmd
+++ b/vignettes/TNKDE.Rmd
@@ -291,17 +291,15 @@ One can decide to use adaptive bandwidth for the TNKDE. They are calculated usin
We can also select the global bandwidth by cross validation with the function `bw_tnkde_cv_likelihood_calc`.
```{r message=FALSE, warning=FALSE, eval = FALSE}
-cv_scores_adpt <- bw_tnkde_cv_likelihood_calc(
- bw_net_range = c(200,1100),
- bw_net_step = 100,
- bw_time_range = c(10,70),
- bw_time_step = 10,
+cv_scores_adpt_dis <- bw_tnkde_cv_likelihood_calc(
+ bws_net = seq(200,1100,100),
+ bws_time = seq(10,70,10),
lines = mtl_network,
events = bike_accidents,
time_field = "Time",
adaptive = TRUE,
- trim_net_bws = seq(200,1100,100),
- trim_time_bws = seq(10,70,10),
+ trim_net_bws = seq(200,1100,100)*2,
+ trim_time_bws = seq(10,70,10)*2,
w = rep(1, nrow(bike_accidents)),
kernel_name = "quartic",
method = "discontinuous",
@@ -316,12 +314,36 @@ cv_scores_adpt <- bw_tnkde_cv_likelihood_calc(
sub_sample=1,
verbose = FALSE,
check = TRUE)
+
+cv_scores_adpt_cont <- bw_tnkde_cv_likelihood_calc.mc(
+ bws_net = seq(200,1100,100),
+ bws_time = seq(10,70,10),
+ lines = mtl_network,
+ events = bike_accidents,
+ time_field = "Time",
+ adaptive = TRUE,
+ trim_net_bws = seq(200,1100,100)*2,
+ trim_time_bws = seq(10,70,10)*2,
+ w = rep(1, nrow(bike_accidents)),
+ kernel_name = "quartic",
+ method = "continuous",
+ diggle_correction = FALSE,
+ study_area = NULL,
+ max_depth = 10,
+ digits = 2,
+ tol = 0.1,
+ agg = 15,
+ sparse=TRUE,
+ grid_shape=c(2,2),
+ sub_sample=1,
+ verbose = FALSE,
+ check = TRUE)
```
```{r message=FALSE, warning=FALSE}
-knitr::kable(cv_scores_adpt)
+knitr::kable(cv_scores_adpt_cont)
```
-The best score is reached with a network and temporal bandwidths of 800m and 60 days.
+For a discontinuous NKDE The best score is reached with a network and temporal bandwidths of 800m and 60 days.
```{r message=FALSE, warning=FALSE, eval = FALSE}
tnkde_densities <- tnkde(lines = mtl_network,
diff --git a/vignettes/images/animated_map.gif b/vignettes/images/animated_map.gif
index a85183c1..81825931 100644
Binary files a/vignettes/images/animated_map.gif and b/vignettes/images/animated_map.gif differ
diff --git a/vignettes/web_vignettes/AdaptiveBW.Rmd b/vignettes/web_vignettes/AdaptiveBW.Rmd
index 520a7867..b2dda56d 100644
--- a/vignettes/web_vignettes/AdaptiveBW.Rmd
+++ b/vignettes/web_vignettes/AdaptiveBW.Rmd
@@ -98,6 +98,7 @@ densities <- nkde(lines = mtl_network,
```
We can now map the result
+
```{r message=FALSE, warning=FALSE, fig.align= "center", fig.width = 8, fig.height = 8}
# rescaling to help the mapping
@@ -181,6 +182,7 @@ tmap_animation(all_maps, filename = "images/animated_densities.gif",
```{r message=FALSE, warning=FALSE, fig.align= "center", out.width = "100%"}
knitr::include_graphics("images/animated_densities.gif")
```
+
With no suprise, the larger the bandwidth, the smoother the results
## Finding the optimal bandwidth
@@ -189,12 +191,13 @@ To complete the visual inspection we did above, we could select an optimal set o
To do so, we can use the function `bw_cv_likelihood_calc` and we must create a matrix of bandwidths that will be evaluated.
We will compare below the scores obtained for the local bandwidths based on the 5th to 25th nearest neighbours.
+
```{r message=FALSE, warning=FALSE}
nearest_nb_mat <- knn_dists$distances[,5:25]
colnames(nearest_nb_mat) <- 5:25
-bw_scores <- bw_cv_likelihood_calc(lines = mtl_network,
+bw_scores_dis <- bw_cv_likelihood_calc(lines = mtl_network,
events = bike_accidents_agg,
w = bike_accidents_agg$weight,
kernel_name = 'quartic',
@@ -202,21 +205,41 @@ bw_scores <- bw_cv_likelihood_calc(lines = mtl_network,
adaptive = TRUE,
mat_bws = nearest_nb_mat,
digits = 1,
- tol = 0.01,
- max_depth = 10, agg = NULL, sparse = TRUE)
+ tol = 0.01,
+ grid_shape = c(2,2),
+ max_depth = 8, agg = NULL, sparse = TRUE)
+
+bw_scores_cont <- bw_cv_likelihood_calc(lines = mtl_network,
+ events = bike_accidents_agg,
+ w = bike_accidents_agg$weight,
+ kernel_name = 'quartic',
+ method = 'continuous',
+ adaptive = TRUE,
+ mat_bws = nearest_nb_mat,
+ digits = 1,
+ tol = 0.01,
+ grid_shape = c(2,2),
+ max_depth = 8, agg = NULL, sparse = TRUE)
df <- data.frame(
k = 5:25,
- score = bw_scores[,2]
+ score_dis = bw_scores_dis[,2],
+ score_cont = bw_scores_cont[,2]
)
+
ggplot(df) +
- geom_line(aes(x = k, y = score)) +
- geom_point(aes(x = k, y = score), color = 'red') +
+ geom_line(aes(x = k, y = score_dis)) +
+ geom_point(aes(x = k, y = score_dis, color = 'discontinuous')) +
+ geom_line(aes(x = k, y = score_cont)) +
+ geom_point(aes(x = k, y = score_cont, color = 'continuous')) +
+ scale_color_manual(values = c("discontinuous" = "red",
+ "continuous" = "blue")) +
+ labs(color = '') +
theme_bw()
```
-Based on these results, we decide to use the 8th nearest neighbour as an optimal bandwidth. It clearly minimizes the likelihood cross validation criterion.
+Based on these results, we decide to use the 8th nearest neighbour as an optimal bandwidth. It clearly maximizes the likelihood cross validation criterion for both the continuous and the discontinuous NKDE.
# K nearest neighbours adaptive bandwidth for TNKDE
@@ -364,7 +387,7 @@ for(j in 5:25){
}
-values <- bw_tnkde_cv_likelihood_calc(lines = mtl_network,
+scores_dis <- bw_tnkde_cv_likelihood_calc(lines = mtl_network,
events = bike_accidents,
time_field = "int_time",
w = rep(1,nrow(bike_accidents)),
@@ -388,16 +411,48 @@ values <- bw_tnkde_cv_likelihood_calc(lines = mtl_network,
verbose=FALSE,
check=TRUE)
+scores_cont <- bw_tnkde_cv_likelihood_calc(lines = mtl_network,
+ events = bike_accidents,
+ time_field = "int_time",
+ w = rep(1,nrow(bike_accidents)),
+ kernel_name = 'quartic',
+ method = 'continuous',
+ arr_bws_net = network_bws,
+ arr_bws_time = time_bws,
+ diggle_correction = FALSE,
+ study_area = NULL,
+ adaptive = TRUE,
+ trim_net_bws = NULL,
+ trim_time_bws = NULL,
+ max_depth = 10,
+ digits=5,
+ tol=0.1,
+ agg=NULL,
+ sparse=TRUE,
+ zero_strat = "min_double",
+ grid_shape=c(1,1),
+ sub_sample=1,
+ verbose=FALSE,
+ check=TRUE)
+
df <- data.frame(
k = 5:25,
- score = values[,1]
+ score_dis = scores_dis[,1],
+ score_cont = scores_cont[,1]
)
+
ggplot(df) +
- geom_line(aes(x = k, y = score)) +
- geom_point(aes(x = k, y = score), color = 'red') +
+ geom_line(aes(x = k, y = score_dis)) +
+ geom_point(aes(x = k, y = score_dis, color = 'discontinuous')) +
+ geom_line(aes(x = k, y = score_cont)) +
+ geom_point(aes(x = k, y = score_cont, color = 'continuous')) +
+ scale_color_manual(values = c("discontinuous" = "red",
+ "continuous" = "blue")) +
+ labs(color = '') +
theme_bw()
+
```
-By checking the table above, we decide to select the 10th nearest neighbour because it clearly corresponds to the major elbow in the above figure. Also, the 21th neighbour gives the highest score.
+By checking the table above, we could decide to select the 10th nearest neighbour because it clearly corresponds to the major elbow in the above figure. Also, the 21th neighbour gives the highest score.