Skip to content

Interpolate-and-bin resampling

# CausalityToolsBase.causalityMethod.

causality(source::AbstractUncertainIndexValueDataset, 
    target::AbstractUncertainIndexValueDataset, 
    test::InterpolatedBinTest{CT, IB}) where {CT, IB}

Apply a causality test of type CT to test.n independent realisations of source and target. Each realisation is generated by first drawing realisations of the datasets, then using the provided InterpolateAndBin resampling scheme to interpolate and bin the draw.

See also UncertainData.InterpolateAndBin.

Examples

# Some test data
N = 100
sys = ar1_unidir(c_xy = 0.2)
X, Y = example_uncertain_indexvalue_datasets(sys, N, (1, 2),
    d_xval = Uniform(0.001, 0.2), d_yval = Uniform(0.001, 0.2));

# Define a causality test 
k, l, m = 1, 1, 1 # embedding parameters
n_subdivisions = floor(Int, N^(1/(k + l + m + 1)))
state_space_binning = RectangularBinning(n_subdivisions)

te_test = VisitationFrequencyTest(k = k, l = l, m = m,
            binning = state_space_binning, 
            ηs = ηs, b = 2) # use base-2 logarithms
pa_test = PredictiveAsymmetryTest(predictive_test = te_test)


# Define interpolation grid over the range of available index values
tmin = max(minimum(mean.(X.indices)), minimum(mean.(Y.indices)))
tmax = max(maximum(mean.(X.indices)), maximum(mean.(Y.indices)))
intp_grid = tmin:0.01:tmax

# Define binning grid
left_bin_edges = tmin:1.5:tmax

# Define the InterpolateAndBin instance
intp_bin = InterpolateAndBin(mean, left_bin_edges, Linear(), intp_grid, Flat(OnGrid()))

# Define interpolate-and-bin test
ib_test = InterpolateBinTest(pa_test, intp_bin, 2)

source

InterpolateBinTest

# CausalityTools.CausalityTests.InterpolateBinTestType.

InterpolateBinTest(test::CausalityTest, interpolate_bin_resampling::InterpolateAndBin)
InterpolateBinTest(test::CausalityTest, interpolate_bin_resampling::InterpolateAndBin, n::Int)

A causality test where the data is interpolated and then binned before the test is applied.

n controls the number of independent resamplings over which the test is performed (if not provided, n is set to 1 by default).

Examples

Record N points from the built-in ar1_unidir system, collect the 1st and 2nd variables as X and Y and add some uncertainties to both the indices and the values.

N = 300
sys = ar1_unidir(c_xy = 0.8)
X, Y = example_uncertain_indexvalue_datasets(sys, N, (1, 2),
    d_xval = Uniform(0.001, 0.05), d_yval = Uniform(0.001, 0.05));

Say we want to interpolate both X and Y to some very fine grid using linear interpolation, then bin to a coarser grid and summarise each bin using the mean of the values in each bin.

# Define interpolation grid over the range of available index values
tmin = max(minimum(mean.(X.indices)), minimum(mean.(Y.indices)))
tmax = max(maximum(mean.(X.indices)), maximum(mean.(Y.indices)))
intp_grid = tmin:0.01:tmax

# Define binning grid
left_bin_edges = tmin:5:tmax

# Define the InterpolateAndBin instance
intp_bin = InterpolateAndBin(mean, left_bin_edges, Linear(), intp_grid, Flat(OnGrid()))

source