knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
# Install development version from GitHub install_github("spatialnetworkslab/homelocator")
#load homelocator package library(homelocator)
# load other packages needed for the analysis library(tidyverse) library(here)
The test data includes 100 random users, and it can be used as an example to get started with homelocator
package.
data("test_sample", package = "homelocator")
The validate_dataset()
function makes sure your input dataset contains all three necessary variables: user, location and timestamp. There are 4 arguments in this function:
user
: name of column that holds a unique identifier for each user.timestamp
: name of column that holds specific timestamp for each data point. This timestamp should be in POSIXct
format.location
: name of column that holds a unique identifier for each location.keep_other_vars
: option to keep or remove any other variables of the input dataset. The default is FALSE
.When validating the dataset, please specify the names of column for user, timestamp and location.
validate_dataset(test_sample, user = "u_id", timestamp = "created_at", location = "grid_id", keep_other_vars = FALSE)
Weighs data points across multiple time frames to ‘score’ potentially meaningful locations for each user
# recipe: homelocator -- HMLC identify_location(test_sample, user = "u_id", timestamp = "created_at", location = "grid_id", show_n_loc = 1, recipe = "HMLC")
Selects the most frequently 'visited' location assuming a user is active mainly around their home location.
# recipe: Frequency -- FREQ identify_location(test_sample, user = "u_id", timestamp = "created_at", location = "grid_id", show_n_loc = 1, recipe = "FREQ")
Finds the most 'popular' location during 'rest', 'active' and 'leisure time. Here we focus on 'rest' and 'leisure' time to find the most possible home location for each user.
# 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")
Calculates the average and standard deviation of start time data points by a single user, in a single location.
# recipe: Online Social Network Activity -- APDM ## APDM recipe strictly returns the most likely home location ## It is important to load the 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", recipe = "APDM", keep_score = F)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.