# Artificial data on high levels of education
#--------------------------------------------
# Load dataset.
data(d.educate)
# Exhaustive CNA without constraints on the search space; print complete solution without
# the truth table.
cna(d.educate)
# The two resulting complex solution formulas represent a common cause structure
# and a causal chain, respectively. The common cause structure is graphically depicted
# in (Note, figure (a)), the causal chain in (Note, figure (b)).
# Print only complex solution formulas.
cna(d.educate, what = "c")
# Print only atomic solution formulas.
cna(d.educate, what = "a")
# Print only minimally sufficient conditions.
cna(d.educate, what = "m")
# Print only the truth table.
cna(d.educate, what = "t")
# CNA with negations of the factors E and L.
cna(d.educate, notcols = c("E","L"))
# CNA with negations of all factors.
cna(d.educate, notcols = "all")
# Lam and Ostrom (2010) on the impact of development interventions on water adequacy in Nepal
#--------------------------------------------------------------------------------------------
# Load dataset.
data(d.irrigate)
# 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(d.irrigate, ordering = list(c("A","R","F","L","C"),"W"), cov = 0.9)
# The previous function call yields a total of 12 complex solution formulas, only
# 5 of which are printed in the default output.
# Here is how to extract all 12 complex solution formulas.
cna.irrigate <- cna(d.irrigate, ordering = list(c("A","R","F","L","C"),"W"), cov = 0.9)
csf(cna.irrigate)
# Extract all atomic solution formulas.
asf(cna.irrigate)
# Extract all minimally sufficient conditions.
msc(cna.irrigate)
# Alterantively, all minimally sufficient conditions, atomic and complex solution formulas
# can be recovered by means of the nsolutions argument of the print function.
print(cna.irrigate, nsolutions = "all")
# Print the truth table with the "cases" column.
print(cna.irrigate, what = "t", show.cases = TRUE)
# Only build solution formulas with maximally 3 disjuncts.
cna(d.irrigate, ordering = list(c("A","R","F","L","C"),"W"), cov = 0.9, maxstep = 3)
# Only print 2 digits of consistency and coverage scores.
print(cna.irrigate, digits = 2)
# Build all but print only two minimally sufficient conditions for each factor and two
# solution formulas.
print(cna(d.irrigate, ordering = list(c("A","R","F","L","C"),"W"), cov = 0.9), nsolutions = 2)
# CNA with a different ordering such that the factors on one level of the ordering are causally
# unrelated; consistency cut-off at 0.9 (coverage cut-off at 1); print only complex solution
# formulas.
cna(d.irrigate, ordering = list(c("A","R","L"),c("F","C"),"W"), strict = TRUE, con = 0.9,
what = "c")
# Same ordering with negation of factor C, consistency cut-off at 0.8, coverage cut-off at 0.9;
# print only complex solution formulas.
cna(d.irrigate, ordering = list(c("A","R","L"),c("F","c"),"W"), notcols = c("C"), con = 0.8,
cov = 0.9, what = "c")
# Same ordering with negations of all factors, consistency cut-off at 0.75, coverage cut-off
# at 0.75.
cna(d.irrigate, ordering = list(c("a","r","l"),c("f","c"),"w"), notcols = "all", con = 0.75,
cov = 0.75)
# Wollebaek (2010) on very high volatility of grassroots associations in Norway
#------------------------------------------------------------------------------
# Load dataset.
data(d.volatile)
# CNA with ordering from Wollebaek (2010) [Beware: due to massive ambiguities, this analysis
# will not terminate in reasonable time on most computers! In that case, R has to be
# interrupted manually, e.g. by ESC, Ctr+C, or Alt+M+Enter.]
cna(d.volatile, ordering = list(c("PG","RB","EL","SE","CS","OD","PC","UP"),"VO2"))
# Using suff.only, CNA can be forced to abandon the analysis after minimization of sufficient
# conditions. [This analysis terminates reasonably quickly.]
cna(d.volatile, ordering = list(c("PG","RB","EL","SE","CS","OD","PC","UP"),"VO2"),
suff.only = TRUE)
# Similarly, using maxstep, CNA can be forced to only search for atomic and complex solutions
# with a maximal number of disjuncts. [This analysis also terminates reasonably quickly,
# yielding a total of 4264 complex solution formulas.]
cna(d.volatile, ordering = list(c("PG","RB","EL","SE","CS","OD","PC","UP"),"VO2"), maxstep = 3)
# Krook (2010) on representation of women in western-democratic parliaments
#--------------------------------------------------------------------------
# Load dataset.
data(d.women)
# This example shows that CNA can infer which factors are causes and which ones
# are effects from the data. Without being told which factor is the outcome,
# CNA reproduces the original QCA of Krook (2010).
cna(d.women)
# Baumgartner and Epple (2014) on the Swiss Minaret Initiative
#-------------------------------------------------------------
# load dataset
data(d.minaret)
# Set up the data frame for calibrated factors
smi <- data.frame(
matrix(numeric(nrow(d.minaret) * (ncol(d.minaret))), ncol = ncol(d.minaret),
dimnames = list(row.names(d.minaret), c(toupper(names(d.minaret))))
)
)
# Calibration
smi$A <- ifelse(d.minaret$a >= 28.0, 1, 0)
smi$L <- ifelse(d.minaret$l >= 31.9, 1, 0)
smi$S <- ifelse(d.minaret$s >= 14.5, 1, 0)
smi$T <- ifelse(d.minaret$t >= 8.0, 1, 0)
smi$X <- ifelse(d.minaret$x >= 38.2, 1, 0)
smi$M <- ifelse(d.minaret$m >= 50.0, 1, 0)
# Replicate the results of Baumgartner and Epple (2014:290-96).
cna(smi, ordering = list(c("A","T"), c("L","S"),"X","M"), cov = 0.94)
# User defined data input
#------------------------
# Data input via data.frame()
dat1 <- data.frame(
A = c(1,1,1,1,1,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,0,0,0,0,0),
B = c(1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0),
C = c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0),
D = c(1,1,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,0),
E = c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0),
G = c(1,1,1,0,0,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,0,0,0,0),
H = c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0)
)
# CNA of dat1
cna(dat1)
# Same input via the frequency argument of the truthTab function.
dat1 <- data.frame(
A = c(1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0),
B = c(1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0),
C = c(1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0),
D = c(1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0),
E = c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0),
G = c(1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0),
H = c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0)
)
dat1_tt <- truthTab(dat1, frequency = c(3,3,3,1,3,1,3,1,3,1,3,1,3,1,1,4))
cna(dat1_tt)
# Data input via matrix() is also possible
dat2 <-
matrix(scan(what = integer(0)), ncol = 5, byrow = TRUE)
1 1 1 1 1
1 1 1 0 1
1 0 1 1 1
1 0 1 0 1
0 1 1 1 1
0 1 1 0 1
0 0 0 1 1
0 0 0 0 0
0 0 0 1 1
0 0 0 1 1
1 1 1 0 1
1 1 1 0 1
1 0 1 0 1
1 1 1 1 1
cna(dat2)
Run the code above in your browser using DataLab