simulateUCVM: Correlated velocity movement: OU Simulation

View source: R/simulateUCVM.R

simulateUCVMR Documentation

Correlated velocity movement: OU Simulation

Description

Simulates 2D correlated velocity movement model

Usage

simulateUCVM(nu = 1, tau = 1, v0 = nu * exp((0+1i) * runif(1, 0, 2 * pi)), 
T.max = NULL, dt = NULL, T = NULL, method = c("direct","exact")[1])

Arguments

nu

mean speed of movement

tau

characteristic time scale of movement

v0

initial velocity vector. Default is randomly oriented vector with magnitude nu

T.max

maximum time of simulations.

dt

time interval of simulations.

T

time vector

method

one of direct, referring to a direct numerical integration of the process which requires a fixed (and small) interval, or exact which samples from the likelihood of the complete process and can take any random vector or times T. The "exact" sampling can be much slower for a large vector of observations. See the package vignette("smoove",package="smoove") for more details.

Details

This function simulates an unbiased CVM in one of two ways: either by explicitly sampling from the velocity equation at some small interval dt << tau and integrating to obtain positions, or sampling locations and velocities directly from the true process at arbitrary times.

Value

a list with the following elements

T

the time vector

V

the (complex) vector of velocities

Z

the (complex) vector of locations

XY

a 2 x n matrix containing columns for the X and Y coordinates of the location

dt, tau, nu,vo

the parameters of the model.

See Also

simulateUCVM, simulateRACVM

Examples

# Direct simulation of UCVM
nu <- 2; tau <- 5; dt <- .1; ucvm <- simulateUCVM(nu, tau, T.max = 1000, dt = dt)
plot(ucvm$XY, asp=1, type="l", main = paste0("UCVM(",nu, tau,")"))

## Also plotting the velocity and using the plot_track function.
par(mfrow=c(1,2))
plot(ucvm$V[1:1000], asp=1, type="l", main = "Velocity")
plot_track(ucvm$Z[1:1000], pch=19, cex=0.5, col=rgb(0,0,0,.1), main = "Location")

# Exact simulation of UCVM, with illustration of velocity and position samples
T <- cumsum(rexp(100))
ucvm2 <-  simulateUCVM(nu, tau, T = T, method="exact")
layout(rbind(c(1,3,3,2), c(1,4,4,2))); par(bty="l", oma=c(0,0,4,0))
with(ucvm2, {
    plot(V, type="o", asp=1, main="Velocity",  col=rgb(0,0,0,.5), cex=0.5)
    plot(Z, type="o", main="Position", asp=1, col=rgb(0,0,0,.5), cex=0.5)
    plot(T, Re(V), col=2, type="o", main="Velocity (decomposed)", 
    ylim=range(c(Re(V), Im(V))),  pch=19, cex=0.5)
    lines(T, Im(V), col=3, type="o", pch=19, cex=0.5)
    plot(T, Re(Z), col=2, type="o", main="Position (decomposed)", 
    ylim=range(XY), pch=19, cex=0.5)
    lines(T, Im(Z), col=3, type="o", pch=19, cex=0.5)
})

EliGurarie/smoove documentation built on Aug. 2, 2022, 10:26 p.m.