Conversion between an intervention matrix and a list of intervention targets
Conversion between an intervention matrix and a list of intervention targets
In a data set with n measurements of p variables, intervened variables can be specified in two ways:
with a logical intervention matrix of dimension n×p, where the entry [i, j] indicates whether variable j has been intervened in measurement i; or
with a list of (unique) intervention targets and a p-dimensional vector indicating the indices of the intervention targets of the p measurements.
The function mat2targets converts the first representation to the second one, the function targets2mat does the reverse conversion. The second representation can be used to create scoring objects (see Score) and to run causal inference methods based on interventional data such as gies or simy.
UTF-8
## Specify interventions using a matrixp <-5n <-10A <- matrix(FALSE, nrow = n, ncol = p)for(i in1:n) A[i,(i-1)%% p +1]<-TRUE## Generate list of intervention targets and corresponding indicestarget.list <- mat2targets(A)for(i in1:length(target.list$target.index)) sprintf("Intervention target of %d-th data point: %d", i, target.list$targets[[target.list$target.index[i]]])## Convert back to matrix representationall(A == targets2mat(p, target.list$targets, target.list$target.index))