6.2 Cyclical Temporal Effects
The squidR function in the {squid} R package uses the sinusoidal equation to implement cyclical temporal effects:
\[ y = A sin(B(x - C)) + D \]
where A is the amplitude, \(B/2\pi\) is the period \(C/B\) is the horizontal shift and D is the vertical shift. We can visualise this
time <- 1:20
amplitude <- 10 # |A| = the amplitude
period <- 10
h_shift <- 3
v_shift <- 5
B <- (2*pi) / abs(period) # 2pi/|B| = the period
cyclic_effect <- amplitude*sin(B*time - B^2*h_shift ) + v_shift
plot(cyclic_effect~time)
We can simulate this using the model part of the simulate_population(), adding the extra parameters for the cyclical effects into the year_cont part of the list.
squid_data <- simulate_population(
data_structure= make_structure(structure = "year(20) + sex(2)/individual(50)",repeat_obs=1),
parameters=list(
year_cont = list(
group="year",
names= "linear_effect",
covariate=TRUE,
beta=0.3,
amplitude = 2, # |A| = the amplitude
period = 10,
h_shift = 3,
v_shift = 5
),
year = list(
vcov = 1.2
),
residual=list(
vcov = 1
)
),
model=" B =(2*pi) / abs(period);
cyclic_effect = amplitude*sin(B*I(linear_effect) - B^2*h_shift ) + v_shift;
y = linear_effect + cyclic_effect + year_effect + residual"
)
data <- get_population_data(squid_data)
plot(y~year,data)