Strictly increasing, interpolated resampling
#
CausalityToolsBase.causality
— Method.
causality(source::AbstractUncertainIndexValueDataset,
target::AbstractUncertainIndexValueDataset,
test::CausalityTest, constraint::SequentialSamplingConstraint, grid::RegularGrid)
Test for a causal influence from source
to target
using the provided causality test
on single draws of source
and target
that have been generated according to the provided sequential
sampling constraint. After interpolating both source
and target
to the provided regular grid
, the causality test is performed on the interpolated data.
Example
First, generate some example data.
N = 300
a₁, a₂, b₁, b₂, ξ₁, ξ₂, C₁₂ = 0.7, 0.1, 0.75, 0.2, 0.3, 0.3, 0.5
D = rand(N, 2)
for t in 5:N
D[t,1] = a₁*D[t-1,1] - a₂*D[t-3,1] + ξ₁*rand(Normal(0, 1))
D[t,2] = b₁*D[t-1,2] - b₂*D[t-2,2] + C₁₂*D[t-1,1] + ξ₂*rand(Normal(0, 1))
end
Gather time series and add some uncertainties to them:
ts = collect(1:N)
x, y = D[:, 1], D[:, 2]
t = UncertainValue.(Normal.(ts .+ 0.2 .* rand(N), rand(N)))
uvalx = UncertainValue.(Normal.(x, rand()))
uvaly = UncertainValue.(Normal.(y, rand()))
X = UncertainIndexValueDataset(t, uvalx)
Y = UncertainIndexValueDataset(t, uvaly)
Now, resample both the indices and values of X
and Y
in a strictly increasing manner according to the indices, interpolate both to the same regular grid, and perform a causality test.
n_bins = ceil(Int, N^(1/4))
te_test = VisitationFrequencyTest(binning = RectangularBinning(n_bins), ηs = -5:5)
pa_test = PredictiveAsymmetryTest(predictive_test = te_test)
# Sample a strictly increasing realisation of the indices, interpolate,
# then perform the causality test on the interpolated data.
causality(X, Y, pa_test, StrictlyIncreasing(), RegularGrid(1:1:N))