lar_simulation_D/E/F | R Documentation |
Simulate three types of animal social structure patterns.
lar_simulation_D(N, n, W, tp)
lar_simulation_E(N, n, W, lambda, tp)
lar_simulation_F(N, n, W, U, lambda, tp)
N |
Population size within the study area. |
n |
A vector or a positive integer, representing the number of groups identified in each sampling period. It indicates the same number of groups identified in all sampling periods if a positive integer. |
W |
Number of groups formed by individuals. |
tp |
A set of observed time. |
lambda |
The probability that an individual changes the group per time unit. |
U |
Number of permanent social units allocated by individuals. |
Type D (Random): individuals form W groups, with random allocation of individuals to groups at each observation.
Type E (Casual acquaintances): individuals form W groups, and change groups with probability lambda per time unit.
Type F (Permanent companions plus casual acquaintances): individuals are randomly allocated to U permanent social units, and these are randomly allocated to W groups, with units changing groups with probability lambda per time unit-permanent companions plus casual acquaintances.
Simulation data for Type D-F.
# Example
# set population size and number of subsampling
N <- 100; n <- 4; W <- 10; U <- 20
# set the observation time
tp <- c(1:5, 51:55, 101:105, 501:505, 601:605)
# set parameters
lambda_E <- 0.008; lambda_F <- 0.008
# simulation of Type D
library(rCLIFII)
simulation_D <- lar_simulation_D(N, n, W, tp)
lar_data <- lar_nonparametric_estimation(simulation_D, tp)
Aij <- lar_data$Aij
Ai <- lar_data$Ai
tauij <- lar_data$tauij
theta <- round(Model4(Aij, Ai, tauij)$par, 8)
# a plot object
graph_data <- data.frame(tau=lar_data$tau, g_tau=lar_data$g_tau)
require(ggplot2)
ggplot(data = graph_data, aes(tau, g_tau)) +
geom_point() +
theme(axis.text = element_text(size = rel(1.2))) +
labs(x="Time Lag", y="Lagged Association Rates", title='Simulation_D') +
geom_hline(yintercept = theta, linetype = 2, color='blue')
# simulation of Type E
simulation_E <- lar_simulation_E(N, n, W, lambda_E, tp)
lar_data <- lar_nonparametric_estimation(simulation_E, tp)
Aij <- lar_data$Aij
Ai <- lar_data$Ai
tauij <- lar_data$tauij
theta <- round(Model5(Aij, Ai, tauij)$par, 8)
alpha <- theta[1]
beta <- theta[2]
graph_data <- data.frame(tau=lar_data$tau, g_tau=lar_data$g_tau)
tT <- max(tp-min(tp))
line_data <- data.frame(tau=seq_len(tT), g_tau=(1-alpha)*exp(-beta*seq_len(tT))+alpha)
require(ggplot2)
ggplot(data = graph_data, aes(tau, g_tau)) +
geom_point() +
theme(axis.text = element_text(size = rel(1.2))) +
labs(x="Time Lag", y="Lagged Association Rates", title='Simulation_E') +
geom_line(aes(tau, g_tau), line_data, linetype = 2, color='blue')
# simulation of Type F
simulation_F <- lar_simulation_F(N=100, n=4, W=10, U=20, lambda_F, tp)
lar_data <- lar_nonparametric_estimation(simulation_F, tp)
Aij <- lar_data$Aij
Ai <- lar_data$Ai
tauij <- lar_data$tauij
theta <- round(Model5(Aij, Ai, tauij)$par, 8)
alpha <- theta[1]
beta <- theta[2]
graph_data <- data.frame(tau=lar_data$tau, g_tau=lar_data$g_tau)
tT <- max(tp-min(tp))
require(ggplot2)
line_data <- data.frame(tau=seq_len(tT), g_tau=(1-alpha)*exp(-beta*seq_len(tT))+alpha)
ggplot(data = graph_data, aes(tau, g_tau)) +
geom_point() +
theme(axis.text = element_text(size = rel(1.2))) +
labs(x="Time Lag", y="Lagged Association Rates", title='Simulation_F') +
geom_line(aes(tau, g_tau), line_data, linetype = 2, color='blue')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.