JeremyGelb / spNetwork

An R package to perform spatial analysis on networks.
GNU General Public License v2.0
34 stars 2 forks source link

Does the spNetwork support the output of spatial & temporal bandwidth in tnkde? #16

Closed bright1993ff66 closed 1 year ago

bright1993ff66 commented 1 year ago

Hi @JeremyGelb , I am recently using the tnkde function based on adaptive bandwidth to analyze the spatio-temporal distribution of accident records across the city.

I am wondering if the tnkde function can output the optimal spatial and temporal bandwidth values when computing the density values, based on the given arguments such as road network and point distribution? From a nkde example, you mentioned that the bandwidth is computed for each event. Is it possible to obtain a overall bandwidth value in density computation (e.g., mean bandwidth values based on all the events)?

The function I refer to is given below. Thank you for your time and help!

tnkde_densities <- tnkde(lines = mtl_network,
                   events = bike_accidents,
                   time_field = "Time",
                   w = rep(1, nrow(bike_accidents)), 
                   samples_loc = sample_points,
                   samples_time = sample_time, 
                   kernel_name = "quartic",
                   bw_net = 700, bw_time = 60,
                   adaptive = TRUE,
                   adaptive_separate = FALSE,
                   trim_bw_net = 900,
                   trim_bw_time = 80,
                   method = "discontinuous",
                   div = "bw", max_depth = 10,
                   digits = 2, tol = 0.01,
                   agg = 15, grid_shape = c(1,1), 
                   verbose  = FALSE)
JeremyGelb commented 1 year ago

Dear Bright,

Currently, it is possible to do bandwidth selection by likelihood cross validation for a TNKDE (see here). The function to use is : _bw_tnkde_cv_likelihoodcalc. However, it will only use global bandwidths and not local bandwidths. I am currently reworking the function to make it possible to use local bandwidths.

So, for the moment, you can select an optimal network and time global bandwidths with the function _bw_tnkde_cv_likelihoodcalc. Be sure to also check visually the results because likelihood cross validation tends to select large bandwidths for bivariate kernel density estimate.

bright1993ff66 commented 1 year ago

Thanks @JeremyGelb for your prompt reply!

I will check the bandwidth selection method bw_tnkde_cv_likelihood_calc you mentioned.