# Crisp-set data from Lam and Ostrom (2010) on the impact of development interventions
# ------------------------------------------------------------------------------------
# CNA with causal ordering that corresponds to the ordering in Lam & Ostrom (2010); coverage
# cut-off at 0.9 (consistency cut-off at 1).
cna.irrigate <- cna(d.irrigate, ordering = "A, R, F, L, C < W", cov = .9,
maxstep = c(4, 4, 12), details = TRUE)
cna.irrigate
# The previous function call yields a total of 12 complex solution formulas, only
# 5 of which are returned in the default output.
# Here is how to extract all 12 complex solution formulas along with all
# solution attributes.
csf(cna.irrigate)
# With only the standard attributes plus exhaustiveness and faithfulness.
csf(cna.irrigate, details = c("e", "f"))
# Extract all atomic solution formulas.
asf(cna.irrigate)
# Extract all minimally sufficient conditions.
msc(cna.irrigate) # capped at 20 rows
print(msc(cna.irrigate), n = Inf) # prints all rows
# Add cases featuring the minimally sufficient conditions combined
# with the outcome.
(msc.table <- msc(cna.irrigate, cases = TRUE))
# Render as data frame.
as.data.frame(msc.table)
# Extract only the conditions (solutions).
csf(cna.irrigate)$condition
asf(cna.irrigate)$condition
msc(cna.irrigate)$condition
# A CNA of d.irrigate without outcome specification and ordering is even more
# ambiguous.
cna2.irrigate <- cna(d.irrigate, cov = .9, maxstep = c(4,4,12), details = TRUE)
# To speed up the construction of complex solution formulas, first extract asf
# and then pass these asf to csf.
cna2.irrigate.asf <- asf(cna2.irrigate)
csf(cna2.irrigate, asfx = cna2.irrigate.asf, details = FALSE)
# Reduce the initial asf combinations.
csf(cna2.irrigate, asfx = cna2.irrigate.asf, n.init = 50)
# Print the first 20 csf.
csf(cna2.irrigate, asfx = cna2.irrigate.asf, n.init = 50)[1:20, ]
# Also extract exhaustiveness scores.
csf(cna2.irrigate, asfx = cna2.irrigate.asf, n.init = 50,
details = "e")[1:20, ]
# Print details about the csf building process.
csf(cna.irrigate, verbose = TRUE)
# Return solution attributes with 5 digits.
print(cna2.irrigate.asf, digits = 5)
# Further examples
# ----------------
# An example generating structural redundancies.
target <- "(A*B + C <-> D)*(c + a <-> E)"
dat1 <- selectCases(target)
ana1 <- cna(dat1, maxstep = c(3, 4, 10))
# Run csf with elimination of structural redundancies.
csf(ana1, verbose = TRUE)
# Run csf without elimination of structural redundancies.
csf(ana1, verbose = TRUE, inus.only = FALSE)
# An example generating partial structural redundancies.
dat2 <- data.frame(A=c(0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,
1),B=c(0,0,1,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1),C=c(1,
1,0,0,0,1,0,0,1,1,0,1,1,0,1,1,0,1,1,1,0,1,0,1,0,1,0),D=c(0,1,1,1,
0,1,1,1,0,0,0,1,0,1,0,0,0,1,0,0,0,1,1,0,0,1,0),E=c(1,0,0,0,0,1,1,
1,1,1,1,0,0,1,0,0,0,1,1,1,1,0,0,0,0,1,1),F=c(1,1,1,1,1,0,0,0,0,0,
0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0),G=c(1,1,1,1,1,1,1,1,1,1,1,1,1,
0,0,0,0,0,0,0,0,0,0,0,0,1,1))
ana2 <- cna(dat2, con = .8, cov = .8, maxstep = c(3, 3, 10))
# Run csf without elimination of partial structural redundancies.
csf(ana2, inus.only = FALSE, verbose = TRUE)
# Run csf with elimination of partial structural redundancies.
csf(ana2, verbose = TRUE)
# Prior to version 3.6.0, the "equivalence" definition of partial structural
# redandancy was used by default (see ?is.inus() for details). Now, the
# "implication" definition is used. To replicate old behavior
# set inus.only to "equivalence".
csf(ana2, verbose = TRUE, inus.only = "equivalence")
# The two definitions only come apart in case of cyclic structures.
# Build only acyclic models.
csf(ana2, verbose = TRUE, acyclic.only = TRUE)
# Feed the outputs of msc, asf, and csf into the condition function to further inspect the
# properties of minimally sufficient conditions and atomic and complex solution formulas.
head(condition(msc(ana2)$condition, dat2), 3) # (showing output for first 3 only)
head(condition(asf(ana2)$condition, dat2), 3)
head(condition(csf(ana2)$condition, dat2), 3)
# Reshape the output of the condition function in such a way as to make it identical to the
# output returned by msc, asf, and csf.
head(condition(msc(ana2)$condition, dat2), 3)
head(condition(asf(ana2)$condition, dat2), 3)
head(condition(csf(ana2)$condition, dat2), 3)
head(condTbl(csf(ana2)$condition, dat2), 3) # Same as preceding line
Run the code above in your browser using DataLab