# NOT RUN {
require("bcpa")
# Exemple with simulated data:
# A study case with with change simulated (i.e. mu1 and mu2 are different)
# --------------------------------------------------
mu1 <- 25 # behavioural value at stage 1
mu2 <- 50
rho1 <- 0.5 # interval frequency at stage 1
rho2 <- rho1
# Low number of individuals (N, n.obs) and low variance (V, sigma)
# create time series from 0 to 50 with a behavioural change at 25
t.full <- 0:50
t.break <- 25
n.obs <- 35 # no. observations randomly selected in the time series: 5 to 45
sigma1 <- 0.1 # variance: 0.1 to 3
sigma2 <- sigma1
SimTS <- function(n, mu, rho, sigma){
X.standard <- arima.sim(n, model = list(ar = rho))
X.standard/sd(X.standard)*sigma + mu
}
x.full <- c(SimTS(t.break, mu1, rho1, sigma1),
SimTS(max(t.full)-t.break+1, mu2, rho2, sigma2))
# subsample of observations (n defined above) and estimate
keep <- sort(sample(1:length(x.full), n.obs))
TimeBudget <- data.frame(
name = "A",
Age = t.full[keep],
x = x.full[keep])
# Running the algorithm
AOF <- aof(
name = TimeBudget$name,
Age = TimeBudget$Age,
x = TimeBudget$x)
print(AOF)
# Exemple with real data extracted from Requier et al.
# (2020, J. Animal Ecology):
# --------------------------------------------------
TimeBudget <- dataExample
# working on Number of trips
varX <- "Number"
AOF_number <- aof(
name = TimeBudget[,1],
Age = TimeBudget[,2],
x = TimeBudget[varX])
print(AOF_number)
# working on Duration of trips
varX <- "Duration"
AOF_duration <- aof(
name = TimeBudget[,1],
Age = TimeBudget[,2],
x = TimeBudget[varX])
print(AOF_duration)
# working on Time of trips
varX <- "Time"
AOF_time <- aof(
name = TimeBudget[,1],
Age = TimeBudget[,2],
x = TimeBudget[varX])
print(AOF_time)
# see vignette for more examples
# }
Run the code above in your browser using DataLab