if (FALSE) {
# make sure the package QCA is loaded
# -----
# for compute()
library(QCA)
compute(DEV*~IND + URB*STB, data = LF)
# calculating individual paths
compute(DEV*~IND + URB*STB, data = LF, separate = TRUE)
}
# -----
# for simplify() also make sure the package QCA is installed
simplify(asSOP("(A + B)(A + ~B)")) # result is "A"
# works even without the quotes
simplify(asSOP((A + B)(A + ~B))) # result is "A"
# but to avoid confusion POS expressions are more clear when quoted
# to force a certain order of the set names
simplify("(URB + LIT*~DEV)(~LIT + ~DEV)", snames = c(DEV, URB, LIT))
# multilevel conditions can also be specified (and negated)
simplify("(A[1] + ~B[0])(B[1] + C[0])", snames = c(A, B, C), noflevels = c(2, 3, 2))
# Ragin's (1987) book presents the equation E = SG + LW as the result
# of the Boolean minimization for the ethnic political mobilization.
# intersecting the reactive ethnicity perspective (R = ~L~W)
# with the equation E (page 144)
simplify("~L~W(SG + LW)", snames = c(S, L, W, G))
# [1] "S~L~WG"
# resources for size and wealth (C = SW) with E (page 145)
simplify("SW(SG + LW)", snames = c(S, L, W, G))
# [1] "SWG + SLW"
# and factorized
factorize(simplify("SW(SG + LW)", snames = c(S, L, W, G)))
# F1: SW(G + L)
# developmental perspective (D = Lg) and E (page 146)
simplify("L~G(SG + LW)", snames = c(S, L, W, G))
# [1] "LW~G"
# subnations that exhibit ethnic political mobilization (E) but were
# not hypothesized by any of the three theories (page 147)
# ~H = ~(~L~W + SW + L~G) = GL~S + GL~W + G~SW + ~L~SW
simplify("(GL~S + GL~W + G~SW + ~L~SW)(SG + LW)", snames = c(S, L, W, G))
# -----
# for translate()
translate(A + B*C)
# same thing in multivalue notation
translate(A[1] + B[1]*C[1])
# tilde as a standard negation (note the condition "b"!)
translate(~A + b*C)
# and even for multivalue variables
# in multivalue notation, the product sign * is redundant
translate(C[1] + T[2] + T[1]*V[0] + C[0])
# negation of multivalue sets requires the number of levels
translate(~A[1] + ~B[0]*C[1], snames = c(A, B, C), noflevels = c(2, 2, 2))
# multiple values can be specified
translate(C[1] + T[1,2] + T[1]*V[0] + C[0])
# or even negated
translate(C[1] + ~T[1,2] + T[1]*V[0] + C[0], snames = c(C, T, V), noflevels = c(2,3,2))
# if the expression does not contain the product sign *
# snames are required to complete the translation
translate(AaBb + ~CcDd, snames = c(Aa, Bb, Cc, Dd))
# to print _all_ codes from the standard output matrix
(obj <- translate(A + ~B*C))
print(obj, original = TRUE) # also prints the -1 code
# -----
# for expand()
expand(~AB + B~C)
# S1: ~AB~C + ~ABC + AB~C
expand(~AB + B~C, snames = c(A, B, C, D))
# S1: ~AB~C~D + ~AB~CD + ~ABC~D + ~ABCD + AB~C~D + AB~CD
# In implicants form:
expand(~AB + B~C, snames = c(A, B, C, D), implicants = TRUE)
# A B C D
# [1,] 1 2 1 1 ~AB~C~D
# [2,] 1 2 1 2 ~AB~CD
# [3,] 1 2 2 1 ~ABC~D
# [4,] 1 2 2 2 ~ABCD
# [5,] 2 2 1 1 AB~C~D
# [6,] 2 2 1 2 AB~CD
Run the code above in your browser using DataLab