knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
# Install development version from GitHub install_github("spatialnetworkslab/homelocator")
These are some basic examples that show you how to use common functions in the package.
You need to make sure the input dataset includes three essential attributes:
You can use validate_dataset()
to validate your input dataset before starting identifying meaningful locations. In this function, you need to specify the names of three essential attribute that used in your dataset.
# Load homelocator library library(homelocator)
# Load other needed libraries library(tidyverse) library(here)
# load test sample dataset data("test_sample", package = "homelocator") df_validated <- validate_dataset(test_sample, user = "u_id", timestamp = "created_at", location = "grid_id") head(df_validated)
To speed up computing progress, you can nest the validated dataset by user so that the subsequent location inference can be applied to each user at the same time.
df_nested <- nest_verbose(df_validated, c("created_at", "grid_id")) head(df_nested) head(df_nested$data[[1]])
Add additional needed varialbes derived from the timestamp column. These are often used/needed as intermediate variables in home location algorithms, such as year, month, day, day of the week and hour of the day, etc.
df_enriched <- enrich_timestamp(df_nested, timestamp = "created_at") head(df_enriched$data[[1]])
Current available recipes, where HMLC
is the default recipe used in identify_location
:
HMLC
: FREQ
OSNA
: Efstathiades et al.2015APDM
: Ahas et al. 2010# default recipe: homelocator -- HMLC identify_location(test_sample, user = "u_id", timestamp = "created_at", location = "grid_id", show_n_loc = 1, recipe = "HMLC")
# recipe: Frequency -- FREQ identify_location(test_sample, user = "u_id", timestamp = "created_at", location = "grid_id", show_n_loc = 1, recipe = "FREQ")
# recipe: Online Social Network Activity -- OSNA identify_location(test_sample, user = "u_id", timestamp = "created_at", location = "grid_id", show_n_loc = 1, recipe = "OSNA")
# recipe: Online Social Network Activity -- APDM ## APDM recipe strictly returns the most likely home location ## It is important to create your location neighbors table before you use the recipe!! ## example: st_queen <- function(a, b = a) st_relate(a, b, pattern = "F***T****") ## neighbors <- st_queen(df_sf) ===> convert result to dataframe data("df_neighbors", package = "homelocator") identify_location(test_sample, user = "u_id", timestamp = "created_at", location = "grid_id", show_n_loc = 1, recipe = "APDM")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.