Title: | Helper Functions for QCA in R |
---|---|
Description: | Helper functions for Qualitative Comparative Analysis: evaluate and plot Boolean formulae on fuzzy set score data, apply Boolean operations, compute consistency and coverage measures. |
Authors: | Jirka Lewandowski <[email protected]> [aut, cre] |
Maintainer: | Jirka Lewandowski <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.2.3 |
Built: | 2024-12-17 06:51:26 UTC |
Source: | CRAN |
Logical 'and' of two conditions
Logical 'or' of two conditions
Logical 'not' of a condition
and(v1, v2) or(v1, v2) not(v)
and(v1, v2) or(v1, v2) not(v)
v1 |
A vector of fuzzy set scores of cases |
v2 |
A vector of fuzzy set scores of cases |
v |
A vector of fuzzy set scores of cases |
the fuzzy set scores of the logical conjunction of v1 and v2 for each case, i.e. the minimum in each component
the fuzzy set scores of the logical disjunction of v1 and v2 for each case, i.e. the maximum in each component
the fuzzy set scores of the negation of v for each case, i.e. 1-v
and(c(0,0.5,1), c(0.25, 0.75, 0.75)) or(c(0,0.5,1), c(0.25, 0.75, 0.75)) not(c(0,0.5,1))
and(c(0,0.5,1), c(0.25, 0.75, 0.75)) or(c(0,0.5,1), c(0.25, 0.75, 0.75)) not(c(0,0.5,1))
Computes the consistency score of "formula1 -> formula2" (sufficient condition)
or "formula1 <- formula2" (necessary condition), depending on whether type
is "->" or "<-".
If type
is "<->" it computes an equivalence score of formula1 and formula2
via the formula sum(min(X,Y))/(sum(max(X,Y))
consistency(formula1, type = "->", formula2, data)
consistency(formula1, type = "->", formula2, data)
formula1 |
A string, list of strings or function representing a Boolean formula in disjunctive normal form |
type |
either "->", "<-" or "<->", depending on the direction of the implication that is to be evaluated |
formula2 |
A string, list of strings or function representing a Boolean formula in disjunctive normal form |
data |
A data frame where the rows represent cases and the columns the sets. Column names must be as in the formula. |
Compute a consistency score for an implication/necessity/sufficiency statement.
If formula
is a function, it must take a data.frame
and return
a vector.
If formula
is a string or list of strings, the following conventions hold:
Set names must be capitalized in the formula and the data; if they are
lowercase, they are interpreted as the negation of the set.
If formula
is a string, logical 'or' is expressed as a '+',
and logical 'and' as a '*'.
If formula
is a list of strings, the strings are assumed to be
the dosjuncts and are concatenated with '+'.
The formula must be in disjunctive normal form, i.e. it must be a disjunction of
conjunctions of elementary or negated elementary sets. Example:
A*b*C + a*B
the consistency score of the implication described by formula1
, type
and formula2
require(QCA) data(d.urban) consistency("MLC + FRB", "->", "CP", d.urban)
require(QCA) data(d.urban) consistency("MLC + FRB", "->", "CP", d.urban)
When given a Boolean formula (see details) and a data.frame
of cases and fuzzy
set score for conditions, computes for each case the score of the membership
in the set described by the formula
evaluate_dnf(data, formula)
evaluate_dnf(data, formula)
data |
A data frame where the rows represent cases and the columns the sets. Column names must be as in the formula. |
formula |
A string, list of strings or function representing a Boolean formula in disjunctive normal form |
If formula
is a function, it must take a data.frame
and return
a vector.
If formula
is a string or list of strings, the following conventions hold:
Set names must be capitalized in the formula and the data; if they are
lowercase, they are interpreted as the negation of the set.
If formula
is a string, logical 'or' is expressed as a '+',
and logical 'and' as a '*'.
If formula
is a list of strings, the strings are assumed to be
the dosjuncts and are concatenated with '+'.
The formula must be in disjunctive normal form, i.e. it must be a disjunction of
conjunctions of elementary or negated elementary sets. Example:
A*b*C + a*B
the fuzzy set score of the set described by the formula for each case in the data
require(QCA) data(d.urban) evaluate_dnf(d.urban, "MLC*frb + CP")
require(QCA) data(d.urban) evaluate_dnf(d.urban, "MLC*frb + CP")
Rewrite a list of clauses to a string containing a Boolean formula in disjunctive normal form
format_dnf(dnf)
format_dnf(dnf)
dnf |
list of clauses |
string containing a Boolean formula in disjunctive normal form
When given a Boolean formula (in disjunctive normal form, see details), this function produces a function that takes a data.frame of a QCA data table and computes the fuzzy set score for each case of membership in the set described by the formula
formula_to_function(formula)
formula_to_function(formula)
formula |
A string or vector of strings containing a Boolean formula in disjunctive normal form |
Set names must be capitalized in the formula and the data; if they are
lowercase, they are interpreted as the negation of the set.
If formula
is a string, logical 'or' is expressed as a '+',
and logical 'and' as a '*'.
If formula
is a list of strings, the strings are assumed to be
the dosjuncts and are concatenated with '+'.
Disjunctive normal form means that the formula must be a disjunction of
conjunctions of elementary or negated elementary sets. Example:
A*b*C + a*B
a function that takes a data.frame and computes the fuzzy set score of the set described by the formula for each case into a vector
formula_to_function("A*b*C + a*B")
formula_to_function("A*b*C + a*B")
Plot the fuzzy set scores of the solution and the outcome against each other
## S3 method for class 'qca' plot(x, ...)
## S3 method for class 'qca' plot(x, ...)
x |
an object of class |
... |
further arguments passed on to |
the ggplot
plot object
## Not run: require(QCA) data(d.urban) solution <- eqmcc(d.urban, outcome="RT", conditions=c("MLC", "FRB", "CP", "WSR")) plot(solution) ## End(Not run)
## Not run: require(QCA) data(d.urban) solution <- eqmcc(d.urban, outcome="RT", conditions=c("MLC", "FRB", "CP", "WSR")) plot(solution) ## End(Not run)
Plot fuzzy set score of two sets against each other
xyplot(x, y, data, labels = FALSE, main.diagonal = TRUE, anti.diagonal = FALSE)
xyplot(x, y, data, labels = FALSE, main.diagonal = TRUE, anti.diagonal = FALSE)
x |
Formula that describes the fuzzy set to plot along the x axis |
y |
Formula that describes the fuzzy set to plot along the y axis |
data |
Data set of basic fuzzy set scores |
labels |
flag whether to label individual points with the case names |
main.diagonal |
flag whether to plot the main diagonal |
anti.diagonal |
flag whether to plot the anti diagonal |
the ggplot
plot object
require(QCA) data(d.urban) xyplot("MLC", "WSR", d.urban)
require(QCA) data(d.urban) xyplot("MLC", "WSR", d.urban)