calculate_density_ratio_dnorm: Calculate the density ratio of M given its Markov pillow at...

View source: R/calculate_density_ratio_dnorm.R

calculate_density_ratio_dnormR Documentation

Calculate the density ratio of M given its Markov pillow at two treatment levels.

Description

Computes the ratio of two conditional densities of M evaluated at treatment levels a_0 and 1 - a_0. Let mp(M) \setminus A denote the Markov pillow of M excluding the treatment A. The density ratio is defined as

\frac{p(M \mid mp(M) \setminus A,\, A = a_0)}{p(M \mid mp(M) \setminus A,\, A = 1 - a_0)}.

The conditional density of M is modelled as follows: Gaussian for univariate or multivariate continuous M (via linear regression), Bernoulli for binary M (via logistic regression), and multivariate Gaussian for multivariate continuous M (via separate linear regressions with a shared residual covariance). Multivariate variables with binary elements are not supported.

Usage

calculate_density_ratio_dnorm(a0, M, graph, treatment, data, formula = NULL)

Arguments

a0

Numeric. The reference treatment level; must be 0 or 1. The density ratio is computed as p(M \mid A = a_0) / p(M \mid A = 1 - a_0).

M

A character string naming the variable for which the density ratio is computed. May refer to a univariate or multivariate vertex as defined in graph.

graph

A graph object created by make.graph.

treatment

A character string naming the binary treatment variable A in data.

data

A data frame containing all variables in the graph.

formula

An optional named list of regression formulas, where each name is a variable name and the corresponding value is the formula to use for that variable's regression on its Markov pillow. Variables not included in this list are regressed using all Markov pillow variables as predictors. See estADMG for details.

Value

A numeric vector of length nrow(data) containing the density ratio for each observation. Returns a vector of ones if the treatment A is not in the Markov pillow of M (i.e., the ratio is identically 1).

Note

Currently only supports binary treatment coded as 0/1. Multivariate variables with binary elements are not supported.


flexCausal documentation built on March 29, 2026, 5:08 p.m.