This function simulates one stochastic realization of the proportion of individuals that leave origin \(i\). The function takes posterior estimates of the mean (mu) and standard deviation (sigma) for each origin \(i\), and then derives the shape and rate parameters for the Beta distribution. Simulated values are random draws from this Beta distribution.

sim_prob_travel(mu = 0.5, sigma = 0.1, n = 1, id = NULL)

Arguments

mu

scalar or vector giving mean probability of leaving origin (defualt = 0.5)

sigma

scalar or vector giving standard deviation of the probability of leaving origin (default = 0.1)

n

number of simulations (default = 1)

id

optional scalar or vector giving name(s) of origin (default = NULL)

Value

a numeric scalar or vector with values between 0 and 1

See also

Other simulation: sim_gravity(), sim_mobility(), sim_param()

Other travel probability: fit_prob_travel(), get_stay_data()

Examples

sim_prob_travel(0.5, 0.04)
#> [1] 0.4825024
sim_prob_travel(mu=c(0.8, 0.6), sigma=c(0.08, 0.06), id=c('A', 'B'))
#> A B #> 0.8477181 0.6592818
# Simulate with estimated parameters n_orig <- 6 n_missing <- 3 orig_id <- LETTERS[1:n_orig] N <- rpois(n_orig, 100) # population size of each origin p <- rbeta(n_orig, 2, 2) # probability of leaving origin travel <- setNames(rbinom(n_orig, N, p), orig_id) total <- setNames(N, orig_id) miss <- sample(1:n_orig, n_missing) # missing observations travel[miss] <- total[miss] <- NA # Estimate probability of travel for each locations (missing locations regress to mean) prob_trav <- summarize_mobility( fit_prob_travel(travel=travel, total=total) )
#> These missing locations will inherit population mean:
#> B D E
#> Compiling model graph #> Resolving undeclared variables #> Allocating nodes #> Graph information: #> Observed stochastic nodes: 3 #> Unobserved stochastic nodes: 6 #> Total graph size: 17 #> #> Initializing model #> #> NOTE: Stopping adaptation #> #>
sim_prob_travel(mu=prob_trav$Mean, sigma=prob_trav$SD, id=names(travel), n=5)
#> [,1] [,2] [,3] [,4] [,5] #> A 0.1147013 0.15605529 0.09066297 0.1277807 0.09972248 #> B 0.7537584 0.92276432 0.29146866 0.4941843 0.94393856 #> C 0.9152566 0.87845621 0.88440829 0.8996513 0.90334714 #> D 0.7738666 0.12055434 0.17825939 0.6742990 0.95013579 #> E 0.3156557 0.09925886 0.48856626 0.3042094 0.30075374 #> F 0.4579946 0.57340870 0.52674698 0.5189877 0.36918711