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)
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 = |
a numeric scalar or vector with values between 0 and 1
Other simulation:
sim_gravity()
,
sim_mobility()
,
sim_param()
Other travel probability:
fit_prob_travel()
,
get_stay_data()
sim_prob_travel(0.5, 0.04)#> [1] 0.4825024#> 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) )#>#>#> 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 #> #>#> [,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