## Example on the porpoise
data(porpoise)
## Keep the first porpoise
gus <- porpoise[1]
plot(gus)
## First test the independence of the step length
indmove(gus)
## There is a lack of independence between successive distances
## plots the distance according to the date
plotltr(gus, "dist")
## One supposes that the distance has been generated
## by normal distribution, with different means for the
## different behaviours
## The means of the normal distribution range from 0 to
## 130000. We suppose a standard deviation equal to 5000:
tested.means <- round(seq(0, 130000, length = 10), 0)
(limod <- as.list(paste("dnorm(dist, mean =",
tested.means,
", sd = 5000)")))
## Build the probability matrix
mod <- modpartltraj(gus, limod)
## computes the corrected log-likelihood for each
## number of segments
bestpartmod(mod)
## The best number of segments is 4. Compute the partition:
(pm <- partmod.ltraj(gus, 4, mod))
plot(pm)
## Shows the partition on the distances:
plotltr(gus, "dist")
lapply(1:length(pm$ltraj), function(i) {
lines(pm$ltraj[[i]]$date, rep(tested.means[pm$stats$mod[i]],
nrow(pm$ltraj[[i]])),
col=c("red","green","blue")[as.numeric(factor(pm$stats$mod))[i]],
lwd=2)
})
## Computes the residuals of the partition
res <- unlist(lapply(1:length(pm$ltraj), function(i) {
pm$ltraj[[i]]$dist - rep(tested.means[pm$stats$mod[i]],
nrow(pm$ltraj[[i]]))
}))
plot(res, ty = "l")
## Test of independence of the residuals of the partition:
wawotest(res)
Run the code above in your browser using DataLab