selectCases {cna} | R Documentation

## Select the cases/configurations compatible with a data generating causal structure

### Description

`selectCases` selects the cases/configurations that are compatible with a Boolean function, in particular (but not exclusively), a data generating causal structure, from a data frame or `truthTab`.

`selectCases1` allows for setting consistency (`con`) and coverage (`cov`) thresholds. It then selects cases/configurations that are compatible with the data generating structure to degrees `con` and `cov`.

### Usage

    selectCases(cond, x = full.tt(cond), type, cutoff = 0.5,
                rm.dup.factors = FALSE, rm.const.factors = FALSE)
    selectCases1(cond, x = full.tt(cond), type, con = 1, cov = 1,
                 rm.dup.factors = FALSE, rm.const.factors = FALSE)

### Arguments

`cond` | Character string specifying the Boolean function for which compatible cases are to be selected.
`x` | Data frame or `truthTab`; if not specified, `full.tt(cond)` is used.
`type` | Character vector specifying the type of `x`: `"cs"` (crisp-set), `"mv"` (multi-value), or `"fs"` (fuzzy-set). Defaults to the type of `x`, if `x` is a `truthTab` or to `"cs"` otherwise.
`cutoff` | Cutoff value in case of `"fs"` data.
`rm.dup.factors` | Logical; if `TRUE`, all but the first of a set of factors with identical value distributions are eliminated.
`rm.const.factors` | Logical; if `TRUE`, constant factors are eliminated.
`con, cov` | Numeric scalars between 0 and 1 to set the minimum consistency and coverage thresholds.

### Details

In combination with `allCombs`, `full.tt`, `randomConds` and `makeFuzzy`, `selectCases` is useful for simulating data, which are needed for inverse search trials benchmarking the output of `cna`.

`selectCases` draws those cases/configurations from a data frame or `truthTab` `x` that are compatible with a data generating causal structure (or any other Boolean or set-theoretic function), which is given to `selectCases` as a character string `cond`. If the argument `x` is not specified, configurations are drawn from `full.tt(cond)`. `cond` can be a condition of any of the three types of conditions, boolean, atomic or complex (see `condition`). To illustrate, if the data generating structure is "A + B <-> C", then a case featuring A=1, B=0, and C=1 is selected by `selectCases`, whereas a case featuring A=1, B=0, and C=0 is not (because according to the data generating structure, A=1 must be associated with C=1, which is violated in the latter case). The type of the data frame is specified by the argument `type` taking `"cs"` (crisp-set), `"mv"` (multi-value), and `"fs"` (fuzzy-set) as values.

`selectCases1` allows for providing consistency (`con`) and coverage (`cov`) thresholds, such that some cases that are incompatible with `cond` are also drawn, as long as `con` and `cov` remain satisfied. The solution is identified by an algorithm aiming at finding a subset of maximal size meeting the `con` and `cov` requirements. In contrast to `selectCases`, `selectCases1` only accepts a condition of type atomic as its `cond` argument, i.e. an atomic solution formula. Data drawn by `selectCases1` can only be modeled with consistency = `con` and coverage = `cov`.

### Value

A `truthTab`.

### See Also

`allCombs`, `full.tt`, `randomConds`, `makeFuzzy`, `truthTab`, `condition`, `cna`, `d.jobsecurity`

### Examples

    # Generate all configurations of 5 dichotomous factors that are compatible with the causal
    # chain (A*b + a*B <-> C) * (C*d + c*D <-> E).
    groundTruth.1 <- "(A*b + a*B <-> C) * (C*d + c*D <-> E)"
    (dat1 <- selectCases(groundTruth.1))
    condition(groundTruth.1, dat1)

    # Randomly draw a multi-value ground truth and generate all configurations compatible with it.
    dat1 <- allCombs(c(3, 3, 4, 4, 3))
    groundTruth.2 <- randomCsf(mvtt(dat1), n.asf=2)
    (dat2 <- selectCases(groundTruth.2, dat1, type = "mv"))
    condition(groundTruth.2, dat2)

    # Generate all configurations of 5 fuzzy-set factors compatible with the causal structure
    # A*b + C*D <-> E, such that con = .8 and cov = .8.
    dat1 <- allCombs(c(2, 2, 2, 2, 2)) - 1
    dat2 <- makeFuzzy(dat1, fuzzvalues = seq(0, 0.45, 0.01))
    (dat3 <- selectCases1("A*b + C*D <-> E", con = .8, cov = .8, dat2))
    condition("A*b + C*D <-> E", dat3)

    # Inverse search for the data generating causal structure A*b + a*B + C*D <-> E from
    # fuzzy-set data with non-perfect consistency and coverage scores.
    dat1 <- allCombs(c(2, 2, 2, 2, 2)) - 1
    set.seed(9)
    dat2 <- makeFuzzy(dat1, fuzzvalues = 0:4/10)
    dat3 <- selectCases1("A*b + a*B + C*D <-> E", con = .8, cov = .8, dat2)
    fscna(dat3, ordering = list("E"), strict = TRUE, con = .8, cov = .8)

    # Draw cases satisfying specific conditions from real-life fuzzy-set data.
    tt.js <- fstt(d.jobsecurity)
    selectCases("S -> C", tt.js)  # Cases with higher membership scores in C than in S.
    selectCases("S -> C", d.jobsecurity, type = "fs")  # Same.
    selectCases("S <-> C", tt.js) # Cases with identical membership scores in C and in S.
    selectCases1("S -> C", con = .8, cov = .8, tt.js)  # selectCases1 makes no distinction
                  #  between "->" and "<->".
    condition("S -> C", selectCases1("S -> C", con = .8, cov = .8, tt.js))

    # selectCases not only draws cases compatible with Boolean causal models. Any Boolean or
    # set-theoretic function can be given as cond.
    selectCases("C > B", allCombs(2:4), type = "mv")
    selectCases("C=2 | B!=3", allCombs(2:4), type = "mv")
    selectCases("A=1 * !(C=2 + B!=3)", allCombs(2:4), type = "mv")

[Package cna version 2.2.0 Index]