CausalTables.jl Full API

CausalTables.AllOrderStatisticsType
AllOrderStatistics <: NetworkSummary

A NetworkSummary which computes all ordered values of the target variable among each unit's connected neighbors in the adjacency matrix.

Fields

  • target::Symbol: A key denoting the target variable to be summarized in the DataGeneratingProcess of the StructuralCausalModel; or, alternatively, the target variable to be summarized in the data attribute of a CausalTable.
  • matrix::Symbol: A key denoting the adjacency matrix over which summary is computed in the DataGeneratingProcess of the StructuralCausalModel; or, alternatively, the key of the adjacency matrix in the arrays attribute of a CausalTable.
  • weights::Union{Symbol, Nothing}: An optional variable by which each unit may be weighted in the summary.
source
CausalTables.DataGeneratingProcessType
mutable struct DataGeneratingProcess

A struct representing a data generating process.

Fields

  • names: An array of symbols representing the names of the variables.
  • types: An array of symbols representing the types of the variables.
  • funcs: An array of functions representing the generating functions for each variable.
source
CausalTables.FriendsType
mutable struct Friends <: NetworkSummary

A NetworkSummary counting the number of connected individuals in an adjacency matrix, also known as the number of "friends".

Fields

  • matrix::Symbol: A key denoting the adjacency matrix over which summary is computed in the DataGeneratingProcess of the StructuralCausalModel; or, alternatively, the key of the adjacency matrix in the arrays attribute of a CausalTable.
source
CausalTables.KOrderStatisticsType
KOrderStatistics <: NetworkSummary

A NetworkSummary which computes the top K ordered values of the target variable among each unit's connected neighbors in the adjacency matrix.

Fields

  • target::Symbol: A key denoting the target variable to be summarized in the DataGeneratingProcess of the StructuralCausalModel; or, alternatively, the target variable to be summarized in the data attribute of a CausalTable.
  • matrix::Symbol: A key denoting the adjacency matrix over which summary is computed in the DataGeneratingProcess of the StructuralCausalModel; or, alternatively, the key of the adjacency matrix in the arrays attribute of a CausalTable.
  • weights::Union{Symbol, Nothing}: An optional variable by which each unit may be weighted in the summary.
source
CausalTables.MeanType
Mean <: NetworkSummary

A NetworkSummary which computes the mean of the target variable among each unit connected in the adjacency matrix.

Fields

  • target::Symbol: A key denoting the target variable to be summarized in the DataGeneratingProcess of the StructuralCausalModel; or, alternatively, the target variable to be summarized in the data attribute of a CausalTable.
  • matrix::Symbol: A key denoting the adjacency matrix over which summary is computed in the DataGeneratingProcess of the StructuralCausalModel; or, alternatively, the key of the adjacency matrix in the arrays attribute of a CausalTable.
  • weights::Union{Symbol, Nothing}: An optional variable by which each unit may be weighted in the summary.
source
CausalTables.StructuralCausalModelType
struct StructuralCausalModel

A struct representing a structural causal model (SCM). This includes a DataGeneratingProcess

Arguments

  • dgp::DataGeneratingProcess: The data generating process from which random data will be drawn.
  • treatment::Vector{Symbol}: The variables representing the treatment.
  • response::Vector{Symbol}: The variables representing the response.
  • causes::Union{NamedTuple, Nothing}: A NamedTuple of Vectors labeling the causes of relevant variables in the data-generating process. If nothing, will assume that all variables not contained in treatment or response are common causes of both.
  • arraynames: Names of auxiliary variables used in the DataGeneratingProcess that are not included as "tabular" variables. Most commonly used to denote names of adjacency matrices used to compute summary functions of previous steps.
source
CausalTables.SumType
Sum <: NetworkSummary

A NetworkSummary which sums the values of the target variable for each unit connected in the adjacency matrix of a StructuralCausalModel or CausalTable

Fields

  • target::Symbol: A key denoting the target variable to be summarized in the DataGeneratingProcess of the StructuralCausalModel; or, alternatively, the target variable to be summarized in the data attribute of a CausalTable.
  • matrix::Symbol: A key denoting the adjacency matrix over which summary is computed in the DataGeneratingProcess of the StructuralCausalModel; or, alternatively, the key of the adjacency matrix in the arrays attribute of a CausalTable.
  • weights::Union{Symbol, Nothing}: An optional variable by which each unit may be weighted in the summary.
source
Base.randMethod
rand(scm::StructuralCausalModel, n::Int)

Generate random data from a Structural Causal Model (SCM) using the specified number of samples.

Arguments

  • scm::StructuralCausalModel: The Structural Causal Model from which to generate data.
  • n::Int: The number of samples to generate.

Returns

A CausalTable object containing the generated data.

source
Base.replaceMethod
replace(o::CausalTable; kwargs...)

Replace the fields of a CausalTable object with the provided keyword arguments.

Arguments

  • o::CausalTable: The CausalTable object to be replaced.
  • kwargs...: Keyword arguments specifying the new values for the fields.

Returns

A new CausalTable object with the specified fields replaced.

source
CausalTables.additive_mtpMethod
additive_mtp(δ)

Constructs a function that adds a constant (or constant vector) δ to the treatment variable(s) in a CausalTable object. This function is intended to be used as an argument to ape.

Arguments

  • δ: The "additive shift" to be applied to the treatment variable of a CausalTable.

Returns

  • A function that takes a CausalTable object as input and returns a column table of treatments that have been shifted by δ units.

Example

using Distributions
dgp = @dgp(
    L ~ Beta(2, 4),
    A ~ @.(Normal(L)),
    Y ~ @.(Normal(A + 2 * L + 1))
)
scm = StructuralCausalModel(dgp, :A, :Y)
ape(scm, additive_mtp(0.5))
source
CausalTables.adjacency_matrixMethod
adjacency_matrix(o::CausalTable)

Generate the adjacency matrix induced by the summaries and arrays attributes of a CausalTable object. This matrix denotes which units are causally dependent upon one another: an entry of 1 in cell (i,j) indicates that some variable in unit i exhibits a causal relationship to some variable in unit j.

Arguments

  • o::CausalTable: The CausalTable object for which the adjacency matrix is to be generated.

Returns

A boolean matrix representing the adjacency relationships in the CausalTable.

source
CausalTables.apeMethod
ape(scm::StructuralCausalModel, intervention::Function; samples = 10^6)

Approximate the average policy effect for a given structural causal model (SCM), along with its efficiency bound. This is also known as the causal effect of a modified treatment policy, and is approximated using Monte Carlo sampling. Note that unless intervention is piecewise smooth invertible, the estimated statistical quantity may not have a causal interpretation; see Haneuse and Rotnizky (2013). Mathematically, this is

\[E(Y(d(a) - Y(a))\]

where $d(a)$ represents the intervention on the treatment variable(s) $A$, $Y(d(a))$ represents the counterfactual $Y$ under treatment $d(a)$, and $Y(a)$ represents the counterfactual outcome under the naturally observed value of treatment. This statistical quantity is approximated using Monte Carlo sampling.

Convenience functions for generating intervention functions include additive_mtp and multiplicative_mtp, which construct functions that respectively add or multiply a constant (or constant vector) to the treatment variable(s). One can also implement their own intervention function; this function must take as input a CausalTable object and return a NamedTuple object with each key indexing a treatment variable that has been modified according to the intervention. Also see cast_matrix_to_table_function for a convenience function for constructing interventions.

Arguments

  • scm::StructuralCausalModel: The SCM from which data is to be simulated.
  • intervention::Function: The intervention function to apply to the SCM.
  • samples: The number of samples to draw from scm for Monte Carlo approximation (default is 10^6). This controls the precision of the approximation.

Returns

A named tuple containing:

  • μ: The APE approximation.

Example

using Distributions
dgp = CausalTables.@dgp(
    L ~ Beta(2, 4),
    A ~ @.(Normal(L)),
    Y ~ @.(Normal(A + 2 * L + 1))
)
scm = CausalTables.StructuralCausalModel(dgp, :A, :Y)
ape(scm, additive_mtp(0.5))
ape(scm, multiplicative_mtp(2.0))

# example of a custom intervention function
custom_intervention = cast_matrix_to_table_function(x -> exp.(x))
ape(scm, custom_intervention)
source
CausalTables.ateMethod
ate(scm::StructuralCausalModel; samples = 10^6)

Approximate the average treatment effect (ATE) for a given structural causal model (SCM), along with its efficiency bound, for a univariate binary treatment. Mathematically, this is

\[E(Y(1) - Y(0))\]

where $Y(a)$ represents the counterfactual $Y$ had the treatment $A$ been set to $a$. This statistical quantity is approximated using Monte Carlo sampling.

Arguments

  • scm::StructuralCausalModel: The SCM from which data is to be simulated.
  • samples: The number of samples to draw from scm for Monte Carlo approximation (default is 10^6). This controls the precision of the approximation.

Returns

A named tuple containing:

  • μ: The ATE approximation.
  • eff_bound: The variance of the counterfactual response, which is equal to the efficiency bound for IID data. If observations are correlated, this may not have a meaningful interpretation.

Example

using Distributions
dgp = @dgp(
    L ~ Beta(2, 4),
    A ~ @.(Bernoulli(L)),
    Y ~ @.(Normal(A + L))
)
scm = StructuralCausalModel(dgp, :A, :Y)
ate(scm)
source
CausalTables.attMethod
att(scm::StructuralCausalModel; samples = 10^6)

Approximate the average treatment effect among the treated (ATT) for a given structural causal model (SCM), along with its efficiency bound, for a univariate binary treatment. Mathematically, this is

\[E(Y(1) - Y(0) \mid A = 1)\]

where $Y(a)$ represents the counterfactual $Y$ had the treatment $A$ been set to $a$. This statistical quantity is approximated using Monte Carlo sampling.

Arguments

  • scm::StructuralCausalModel: The SCM from which data is to be simulated.
  • samples: The number of samples to draw from scm for Monte Carlo approximation (default is 10^6). This controls the precision of the approximation.

Returns

A named tuple containing:

  • μ: The ATT approximation.
  • eff_bound: The variance of the counterfactual response, which is equal to the efficiency bound for IID data. If observations are correlated, this may not have a meaningful interpretation.

Example

using Distributions
dgp = @dgp(
    L ~ Beta(2, 4),
    A ~ @.(Bernoulli(L)),
    Y ~ @.(Normal(A + L))
)
scm = StructuralCausalModel(dgp, :A, :Y)
att(scm)
source
CausalTables.atuMethod
atu(scm::StructuralCausalModel; samples = 10^6)

Approximate the average treatment effect among the untreated (ATU) for a given structural causal model (SCM), along with its efficiency bound, for a univariate binary treatment. Mathematically, this is

\[E(Y(1) - Y(0) \mid A = 0)\]

where $Y(a)$ represents the counterfactual $Y$ had the treatment $A$ been set to $a$. This statistical quantity is approximated using Monte Carlo sampling.

Arguments

  • scm::StructuralCausalModel: The SCM from which data is to be simulated.
  • samples: The number of samples to draw from scm for Monte Carlo approximation (default is 10^6). This controls the precision of the approximation.

Returns

A named tuple containing:

  • μ: The ATU approximation.
  • eff_bound: The variance of the counterfactual response, which is equal to the efficiency bound for IID data. If observations are correlated, this may not have a meaningful interpretation.

Example

using Distributions
dgp = @dgp(
    L ~ Beta(2, 4),
    A ~ @.(Bernoulli(L)),
    Y ~ @.(Normal(A + L))
)
scm = StructuralCausalModel(dgp, :A, :Y)
atu(scm)
source
CausalTables.cast_matrix_to_table_functionMethod
cast_matrix_to_table_function(func::Function)

Wraps a given function func that operates on a matrix and returns a new function that operates on a CausalTable object. The returned function converts the CausalTable's treatment matrix to a table, applies func to this matrix, and then converts the result back to a column table with the same header as the original treatment matrix.

Arguments

  • func::Function: A function that takes a matrix as input and returns a matrix.

Returns

  • A function that takes a CausalTable object as input and returns a column table.

Example

custom_intervention = cast_matrix_to_table_function(x -> exp.(x))
source
CausalTables.cfdiffMethod
cfdiff(scm::StructuralCausalModel, intervention1::Function, intervention2::Function; samples = 10^6)

Approximate the difference between two counterfactual response means – that under intervention1 having been applied to the treatment, and that under intervention2 – for a given structural causal model (SCM), along with its efficiency bound. Mathematically, this is

\[E(Y(d_1(a)) - Y(d_2(a)))\]

where $d_1$ and $d_2$ represent intervention1 and intervention2 being applied on the treatment variable(s) $A$. This statistical quantity is approximated using Monte Carlo sampling.

Arguments

  • scm::StructuralCausalModel: The SCM from which data is to be simulated.
  • intervention1::Function: The first intervention function to be contrasted.
  • intervention2::Function: The second intervention function to be contrasted.
  • samples: The number of samples to draw from scm for Monte Carlo approximation (default is 10^6). This controls the precision of the approximation.

Returns

A named tuple containing:

  • μ: The mean difference in counterfactual outcomes.

Example

using Distributions
dgp = @dgp(
    L ~ Beta(2, 4),
    A ~ @.(Bernoulli(L)),
    Y ~ @.(Normal(A + L))
)
scm = StructuralCausalModel(dgp, :A, :Y)
cfdiff(scm, treat_all, treat_none)
source
CausalTables.cfmeanMethod
cfmean(scm::StructuralCausalModel, intervention::Function; samples = 10^6)

Approximate the counterfactual mean of the response had intervention been applied to the treatment, along with its efficiency bound, for a given structural causal model (SCM). Mathematically, this estimand is

\[E(Y(d(a)))\]

where $d(a)$ represents an intervention on the treatment variable(s) $A$. This statistical quantity is approximated using Monte Carlo sampling.

Arguments

  • scm::StructuralCausalModel: The SCM from which data is to be simulated.
  • intervention::Function: The intervention function to apply to the SCM.
  • samples: The number of samples to draw from scm for Monte Carlo approximation (default is 10^6). This controls the precision of the approximation.

Returns

A named tuple containing:

  • μ: The mean of the counterfactual outcomes.

Example

using Distributions
dgp = @dgp(
    L ~ Beta(2, 4),
    A ~ @.(Bernoulli(L)),
    Y ~ @.(Normal(A + L))
)
scm = StructuralCausalModel(dgp, :A, :Y)
cfmean(scm, treat_all)
cfmean(scm, treat_none)
source
CausalTables.condensityMethod
condensity(scm::StructuralCausalModel, ct::CausalTable, name::Symbol)

Compute the conditional density of variable name in CausalTable ct that has been drawn from StructuralCausalModel scm.

Arguments

  • scm::StructuralCausalModel: The StructuralCausalModel representing the data generating process.
  • ct::CausalTable: The CausalTable containing the observed data.
  • name::Symbol: The variable for which to compute the conditional density.

Returns

The conditional density of the variable var given the observed data.

source
CausalTables.confoundernamesMethod
confoundernames(o::CausalTable, x::Symbol, y::Symbol)

Outputs the names of the confounders of the causal relationship between x and y from the given CausalTable object.

Arguments

  • o::CausalTable: The CausalTable object from which to extract the confounder names.
  • x::Symbol, y::Symbol: The two variables whose confounders should be selected.

Returns

A Vector of Symbols containing the names of the confounders between x and y.

source
CausalTables.confoundernamesMethod
confoundernames(o::CausalTable)

Outputs the confounder names of each response-treatment pair from the given CausalTable object.

Arguments

  • o::CausalTable: The CausalTable object from which to extract the confounder names of each treatment-response pair.

Returns

A matrix of Vectors containing the confounder names of each treatment-response pair.

source
CausalTables.confoundersMethod
confounders(o::CausalTable, x::Symbol, y::Symbol)

Selects the common causes for a specific pair of variables (x,y) from the given CausalTable object.

Arguments

  • o::CausalTable: The CausalTable object from which to extract the confounders.
  • x::Symbol, y::Symbol: The two variables whose confounders should be selected.

Returns

A new CausalTable containing only the confounders of both x and y.

source
CausalTables.confoundersMethod
confounders(o::CausalTable; collapse_parents = true)

Selects the confounders of each response-treatment pair from the given CausalTable object.

Arguments

  • o::CausalTable: The CausalTable object from which to extract the confounder variables of each treatment-response pair.
  • collape_parents::Bool: Optional parameter, whether to collapse the output to a single CausalTable object if there is either only one treatment-response pair or all pair share the same set of confounders. Defaults to true.

Returns

A new CausalTable containing only the confounders (if a single response, or all responses share the same set of causes); otherwise, a Matrix of CausalTable objects containing the confounders of each treatment-response pair, where rows represent responses and columns represent treatments.

source
CausalTables.confoundersmatrixMethod
confoundersmatrix(o::CausalTable; collapse_parents = true)

Outputs the treatment-variable confounders from the given CausalTable object as a matrix (or matrix of matrices, if multiple treatment-response pairs are present).

Arguments

  • o::CausalTable: The CausalTable object from which to extract the confounders of each treatment-response pair.
  • collape_parents::Bool: Optional parameter, whether to collapse the output to a single Matrix object if there is either only one treatment-response pair or all pair share the same set of confounders. Defaults to true.

Returns

A matrix containing only the confounders.

source
CausalTables.conmeanMethod
conmean(scm::StructuralCausalModel, ct::CausalTable, name::Symbol)

Compute the conditional mean of variable name in CausalTable ct that has been drawn from StructuralCausalModel scm.

Arguments

  • scm::StructuralCausalModel: The StructuralCausalModel object representing the data generating process.
  • ct::CausalTable: The CausalTable object representing the data.
  • name::Symbol: The variable for which to compute the conditional mean.

Returns

An array of conditional means for the specified variable.

source
CausalTables.convarMethod
convar(scm::StructuralCausalModel, ct::CausalTable, name::Symbol)

Compute the conditional variance of variable name in CausalTable ct that has been drawn from StructuralCausalModel scm.

Arguments

  • scm::StructuralCausalModel: The StructuralCausalModel object representing the data generating process.
  • ct::CausalTable: The CausalTable object representing the data.
  • name::Symbol: The variable for which to compute the conditional mean.

Returns

An array of conditional variances for the specified variable.

source
CausalTables.convolveMethod
convolve(ds::Vector{T}) where {T <: UnivariateDistribution}

A convolve function that works on a vector of UnivariateDistribution.

Arguments

  • ds::Vector{T}: A vector of UnivariateDistribution objects.

Returns

  • output: The result of convolving all the distributions in ds. If ds is empty, will return Binomial(0, 0.5) denoting a point mass at 0.
source
CausalTables.dataMethod
data(o::CausalTable)

Retrieve the data stored in a CausalTable object.

Arguments

  • o::CausalTable: The CausalTable from which to retrieve the data.

Returns

The data stored in the CausalTable object.

source
CausalTables.dependency_matrixMethod
dependency_matrix(o::CausalTable)

Generate the dependency matrix induced by the summaries and arrays attributes of a CausalTable object. This matrix stores which units are statistically dependent upon one another: an entry of 1 in cell (i,j) indicates that the data of unit i is correlated with the data in unit j. Two units are correlated if they either are causally dependent (neighbors in the adjacency matrix) or share a common cause (share a neighbor in the adjacency matrix).

Arguments

  • o::CausalTable: The CausalTable object for which the dependency matrix is to be generated.

Returns

A boolean matrix representing the relationships in the CausalTable.

source
CausalTables.draw_counterfactualMethod
draw_counterfactual(scm::StructuralCausalModel, parents::CausalTable, intervention::Function) -> Vector

Generate counterfactual responses based on a given structural causal model (SCM), a table of response parents, and an intervention function. That is, sample the responses that would have occurred had some intervention been applied to the treatment specified by the structural causal model.

Arguments

  • scm::StructuralCausalModel: The structural causal model used to generate counterfactual outcomes.
  • parents::CausalTable: A table containing the variables causally preceding the response variable.
  • intervention::Function: A function that defines the intervention to be applied to the parent variables. Use cast_matrix_to_table_function to convert a function acting on a treatment vector or matrix to a function that acts on a CausalTable.

Returns

A vector of counterfactual responses.

source
CausalTables.instrumentnamesMethod
instrumentnames(o::CausalTable, x::Symbol, y::Symbol)

Outputs the names of the instruments of the causal relationship between x and y from the given CausalTable object; that is, variables that are associated with x but do not cause y.

Arguments

  • o::CausalTable: The CausalTable object from which to extract the mediator names.
  • x::Symbol, y::Symbol: The two variables whose mediators should be selected.

Returns

A Vector of Symbols containing the names of the mediators between x and y.

source
CausalTables.instrumentnamesMethod
instrumentnames(o::CausalTable)

Outputs the instrument names of each treatment-response pair from the given CausalTable object.

Arguments

  • o::CausalTable: The CausalTable object from which to extract the instrument names of each treatment-response pair.

Returns

A matrix of Vectors containing the instrument names of each treatment-response pair.

source
CausalTables.instrumentsMethod
instruments(o::CausalTable, x::Symbol, y::Symbol)

Selects the instruments for a specific pair of variables (x,y) from the given CausalTable object; that is, variables that are associated with x but do not cause y.

Arguments

  • o::CausalTable: The CausalTable object from which to extract the instruments.
  • x::Symbol, y::Symbol: The two variables whose instruments should be selected.

Returns

A new CausalTable containing only the instruments of both x and y.

source
CausalTables.instrumentsMethod
instruments(o::CausalTable; collapse_parents = true)

Selects the instruments of each treatment-response pair from the given CausalTable object; that is, variables that are associated with the treatment but do not cause the response.

Arguments

  • o::CausalTable: The CausalTable object from which to extract the instrumental variables of each treatment-response pair.
  • collape_parents::Bool: Optional parameter, whether to collapse the output to a single CausalTable object if there is either only one treatment-response pair or all pair share the same set of instruments. Defaults to true.

Returns

A new CausalTable containing only the instruments (if a single response, or all responses share the same set of instruments); otherwise, a Matrix of CausalTable objects containing the instruments of each treatment-response pair, where rows represent responses and columns represent treatments.

source
CausalTables.instrumentsmatrixMethod
instrumentsmatrix(o::CausalTable; collapse_parents = true)

Outputs the treatment-variable instruments from the given CausalTable object as a matrix (or matrix of matrices, if multiple treatment-response pairs are present).

Arguments

  • o::CausalTable: The CausalTable object from which to extract the instruments of each treatment-response pair.
  • collape_parents::Bool: Optional parameter, whether to collapse the output to a single Matrix object if there is either only one treatment-response pair or all pair share the same set of instruments. Defaults to true.

Returns

A matrix containing only the confounders.

source
CausalTables.interveneMethod
intervene(ct::CausalTable, intervention::Function)

Applies intervention to the treatment vector(s) within a CausalTable, and outputs a new CausalTable with the intervened treatment.

Arguments

  • ct::CausalTable: The data on which treatment should be intervened
  • intervention::Function: A function that defines the intervention to be applied to the parent variables. Use cast_matrix_to_table_function to convert a function acting on a treatment vector or matrix to a function that acts on a CausalTable.

Returns

A CausalTable containing the same data as ct, but with the treatment variable(s) modified accoding to intervention

Example

using Distributions
dgp = @dgp(
    L ~ Beta(2, 4),
    A ~ @.(Bernoulli(L)),
    Y ~ @.(Normal(A + L))
)
scm = StructuralCausalModel(dgp, :A, :Y)
ct = rand(scm, 100)
intervene(ct, treat_all)
source
CausalTables.mediatornamesMethod
mediatornames(o::CausalTable, x::Symbol, y::Symbol)

Outputs the names of the mediators of the causal relationship between x and y from the given CausalTable object.

Arguments

  • o::CausalTable: The CausalTable object from which to extract the mediator names.
  • x::Symbol, y::Symbol: The two variables whose mediators should be selected.

Returns

A Vector of Symbols containing the names of the mediators between x and y.

source
CausalTables.mediatornamesMethod
mediatornames(o::CausalTable)

Outputs the mediator names of each response-treatment pair from the given CausalTable object.

Arguments

  • o::CausalTable: The CausalTable object from which to extract the mediator names of each treatment-response pair.

Returns

A matrix of Vectors containing the mediator names of each treatment-response pair.

source
CausalTables.mediatorsMethod
mediators(o::CausalTable, x::Symbol, y::Symbol)

Selects the mediators for a specific pair of variables (x,y) from the given CausalTable object; that is, the variables that are caused by x and cause y.

Arguments

  • o::CausalTable: The CausalTable object from which to extract the mediators.
  • x::Symbol, y::Symbol: The two variables whose mediators should be selected.

Returns

A new CausalTable containing only the mediators of both x and y.

source
CausalTables.mediatorsMethod
mediators(o::CausalTable; collapse_parents = true)

Selects the mediators of each treatment-response pair from the given CausalTable object.

Arguments

  • o::CausalTable: The CausalTable object from which to extract the mediator variables of each treatment-response pair.
  • collape_parents::Bool: Optional parameter, whether to collapse the output to a single CausalTable object if there is either only one treatment-response pair or all pair share the same set of mediators. Defaults to true.

Returns

A new CausalTable containing only the mediators (if a single response, or all responses share the same set of mediators); otherwise, a Matrix of CausalTable objects containing the mediators of each treatment-response pair, where rows represent responses and columns represent treatments.

source
CausalTables.mediatorsmatrixMethod
mediatorsmatrix(o::CausalTable; collapse_parents = true)

Outputs the treatment-variable confounders from the given CausalTable object as a matrix (or matrix of matrices, if multiple treatment-response pairs are present).

Arguments

  • o::CausalTable: The CausalTable object from which to extract the mediators of each treatment-response pair.
  • collape_parents::Bool: Optional parameter, whether to collapse the output to a single Matrix object if there is either only one treatment-response pair or all pair share the same set of mediators. Defaults to true.

Returns

A matrix containing only the confounders.

source
CausalTables.multiplicative_mtpMethod
multiplicative_mtp(δ)

Constructs a function that scales the treatment variable(s) in a CausalTable object by a constant δ. This function is intended to be used as an argument to ape.

Arguments

  • δ: The "multiplicative shift" to be applied to the treatment variable of a CausalTable.

Returns

  • A function that takes a CausalTable object as input and returns a column table of treatments that have been scaled by δ units.

Example

using Distributions
dgp = CausalTables.@dgp(
    L ~ Beta(2, 4),
    A ~ @.(Normal(L)),
    Y ~ @.(Normal(A + 2 * L + 1))
)
scm = CausalTables.StructuralCausalModel(dgp, :A, :Y)
ape(scm, multiplicative_mtp(2.0))
source
CausalTables.parentsMethod
parents(o::CausalTable, symbol)

Selects the variables that precede symbol causally from the CausalTable o, based on the causes attribute. Note that if symbol is not contained within o.causes, this function will output an empty CausalTable.

Arguments

  • o::CausalTable: The CausalTable object from which to extract the parent variables of symbol.
  • symbol: The variable for which to extract the parent variables.

Returns

A new CausalTable containing only the parents of symbol

source
CausalTables.propensityMethod
propensity(scm::StructuralCausalModel, ct::CausalTable, name::Symbol)

Compute the (generalized) propensity score of variable name in CausalTable ct that has been drawn from StructuralCausalModel scm.

Arguments

  • scm::StructuralCausalModel: The StructuralCausalModel object representing the data generating process.
  • ct::CausalTable: The CausalTable object representing the data.
  • name::Symbol: The variable for which to compute the conditional mean.

Returns

An array of conditional probabilities for the specified variable (or densities, if the specified variable is continuous).

source
CausalTables.rejectMethod
reject(o::CausalTable, symbols)

Removes the columns specified by symbols from the CausalTable object o.

Arguments

  • o::CausalTable: The CausalTable object from which symbols will be rejected.
  • symbols: A collection of symbols to be rejected from the CausalTable.

Returns

A new CausalTable object with the specified symbols removed from its data.

source
CausalTables.responseMethod
response(o::CausalTable)

Selects the response column(s) from the given CausalTable object.

Arguments

  • o::CausalTable: The CausalTable object from which to select the response column(s).

Returns

A new CausalTable containing only the response column(s).

source
CausalTables.responsematrixMethod
responsematrix(o::CausalTable)

Outputs the response column(s) from the given CausalTable object as a matrix.

Arguments

  • o::CausalTable: The CausalTable object from which to select the response column(s).

Returns

A matrix containing only the response column(s)

source
CausalTables.responseparentsMethod
responseparents(o::CausalTable)

Selects the parents of each response variable from the given CausalTable object.

Arguments

  • o::CausalTable: The CausalTable object from which to extract the parent variables of each response.
  • collape_parents::Bool: Optional parameter, whether to collapse the output to a single CausalTable object if there is either only one response or all response have the same parents. Defaults to true.

Returns

A new CausalTable containing only the causes of the responses (if a single response, or all responses share the same set of causes); otherwise, a Vector of CausalTable objects containing the causes of each response.

source
CausalTables.selectMethod
select(o::CausalTable, symbols)

Selects specified columns from a CausalTable object.

Arguments

  • o::CausalTable: The CausalTable object from which columns are to be selected.
  • symbols: A list of symbols representing the columns to be selected.

Returns

  • A new CausalTable object with only the selected columns.
source
CausalTables.set_treatment_valueMethod
set_treatment_value(ct::CausalTable, value::Float64)

Sets all treatments present in the data of a CausalTable to a specified value. This function is primarily used for interventions where the treatment value is set to a constant, such as in the case of binary treatments.

Arguments

  • ct::CausalTable: The causal table object containing treatment information and data.
  • value::Float64: (Currently unused) A float value intended to represent the treatment value to set.

Returns

  • NamedTuple: A named tuple mapping each treatment variable to a vector of ones.
source
CausalTables.summarizeMethod
summarize(o::CausalTable)

Summarizes the data in a CausalTable object according to the NetworkSummary objects stored in its summaries attribute.

Arguments

  • o::CausalTable: The CausalTable object to be summarized.

Returns

  • A new CausalTable object with the original data merged with the summarized data.
source
CausalTables.treat_allMethod
treat_all(ct::CausalTable)

Intervenes on a CausalTable object by setting all treatment variables to 1.

Arguments

  • ct::CausalTable: A CausalTable object with a univariate binary treatment.

Returns

A NamedTuple object with the same header as the treatment matrix in ct, where each treatment variable is set to 1.

Example

using Distributions
dgp = @dgp(
    L ~ Beta(2, 4),
    A ~ @.(Bernoulli(L)),
    Y ~ @.(Normal(A + L))
)
scm = StructuralCausalModel(dgp, :A, :Y)
data = rand(scm, 100)
treat_all(data)
source
CausalTables.treat_noneMethod
treat_none(ct::CausalTable)

Intervenes on a CausalTable object by setting all treatment variables to 0.

Arguments

  • ct::CausalTable: A CausalTable object with a univariate binary treatment.

Returns

A NamedTuple object with the same header as the treatment matrix in ct, where each treatment variable is set to 0.

Example

using Distributions
dgp = @dgp(
    L ~ Beta(2, 4),
    A ~ @.(Bernoulli(L)),
    Y ~ @.(Normal(A + L))
)
scm = StructuralCausalModel(dgp, :A, :Y)
data = rand(scm, 100)
treat_none(data)
source
CausalTables.treatmentMethod
treatment(o::CausalTable)

Selects the treatment column(s) from the given CausalTable object. treatment

Arguments

  • o::CausalTable: The CausalTable object from which to select the treatment column(s).

Returns

A new CausalTable containing only the treatment column(s)

source
CausalTables.treatmentmatrixMethod
treatmentmatrix(o::CausalTable)

Outputs the treatment column(s) from the given CausalTable object as a matrix.

Arguments

  • o::CausalTable: The CausalTable object from which to select the treatment column(s).

Returns

A matrix containing only the treatment column(s)

source
CausalTables.treatmentparentsMethod
treatmentparents(o::CausalTable)

Selects the parents of each treatment variable from the given CausalTable object.

Arguments

  • o::CausalTable: The CausalTable object from which to extract the parent variables of each treatment.
  • collape_parents::Bool: Optional parameter, whether to collapse the output to a single CausalTable object if there is either only one treatment or all treatments have the same parents. Defaults to true.

Returns

A new CausalTable containing only the causes of the treatment (if a single treatment, or all treatments share the same set of causes); otherwise, a Vector of CausalTable objects containing the causes of each treatment.

source