Type: | Package |
Title: | An Implementation of Interaction Graphs of Aleks Jakulin |
Version: | 1.0.0 |
Description: | Generates a 'Graphviz' graph of the most significant 3-way interaction gains (i.e. conditional information gains) based on a provided discrete data frame. Various output formats are supported ('Graphviz', SVG, PNG, PDF, PS). For references, see the webpage of Aleks Jakulin http://stat.columbia.edu/~jakulin/Int/. |
Depends: | R (≥ 3.5.0), dplyr (≥ 0.7.6), DiagrammeR (≥ 1.0.0), DiagrammeRsvg (≥ 0.1), rsvg (≥ 1.3), gtools (≥ 3.5.0), utils (≥ 3.5.0) |
License: | GPL-3 |
Encoding: | UTF-8 |
LazyData: | true |
URL: | https://github.com/peleplay/integr |
BugReports: | https://github.com/peleplay/integr/issues |
RoxygenNote: | 6.1.1 |
Suggests: | knitr, rmarkdown, testthat |
VignetteBuilder: | knitr |
NeedsCompilation: | no |
Packaged: | 2019-05-24 11:14:53 UTC; peleplay |
Author: | Petar Markovic [aut, cre] |
Maintainer: | Petar Markovic <peleplay@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2019-05-24 11:50:03 UTC |
Calculates Shannon's entropy
Description
Formula: H(S) = -P_i * \sum log_2 * P_i
, where P_i
is the
probability of the corresponding i
-th class
Usage
entropy(df, classAtt)
Arguments
df |
A discrete |
classAtt |
A class column of the df ( |
Value
The Shannon's entropy of the df
, based on the classAtt
attribute
Examples
entropy(golf, "Play")
Golf example dataset for Interaction graphs
Description
An example dataset containing the discrete data.frame (i.e. all columns are factors) with variables used as an input for making a decision whether a party of golf would be played, or not.
Usage
golf
Format
A data.frame with 6 discrete variables (i.e. factors) and 14 rows (i.e. observations). 5 input variables and 1 class (i.e. context) variable:
- Outlook
Input attribute, values: Overcast, Rainy, Sunny
- Temperature
Input attribute, values: Cool, Hot, Mild
- Humidity
Input attribute, values: High, Normal
- Windy
Input attribute, values: True, False
- Others
Artifically added input attribute indicating whether the players on the other courts were playing the golf at the given time, values: Yes, No
- Play
Class attribute, indicating whether the decision was to play or not to play a party of golf, values: Yes, No
@source https://gerardnico.com/data_mining/weather
Constructs Interaction Graph (S3 class)
Description
Constructs Interaction Graph (S3 class)
Usage
ig(n, e)
Arguments
n |
ig.nodes ( |
e |
ig.edges ( |
Value
An instance of the ig
class
Constructs Interaction Graph Edges (S3 class)
Description
Constructs Interaction Graph Edges (S3 class)
Usage
igEdge(n1, n2, w)
Arguments
n1 |
igEdge.node1 |
n2 |
igEdge.node2 |
w |
igEdge.weight (i.e. 3-way Interaction Gain) |
Value
An instance of the igEdge
class
Constructs Interaction Graph Nodes (S3 class)
Description
Constructs Interaction Graph Nodes (S3 class)
Usage
igNode(n, v)
Arguments
n |
igNode.name |
v |
igNode.value |
Value
An instance of the igNode
class
Exports Interaction graph to a GraphViz file
Description
Exports Interaction graph to a GraphViz file
Usage
igToGrViz(ig, path = "", fName = "InteractionGraph")
Arguments
ig |
Interaction graph |
path |
The folder in which to write the GraphViz file; |
fName |
The name of the file to be created; "InteractionGraph" by default |
Value
Writes the ig
interaction graph to a GraphViz .gv
file
to the folder specified in the path
Examples
#create temp dir path with slashes
myDir <- gsub("\\\\", "/", tempdir())
#create interaction graph
g <- interactionGraph(golf, "Play", intNo = 10)
#write to 'graphviz' file
igToGrViz(g, path = myDir, fName = "MyGraph")
Exports Interaction graph to a PDF file
Description
Exports Interaction graph to a PDF file
Usage
igToPDF(ig, path = "", fName = "InteractionGraph", h = 2000)
Arguments
ig |
Interaction graph |
path |
The folder in which to write the PDF file; |
fName |
The name of the file to be created; "InteractionGraph" by default |
h |
Desired height of the image in pixels; 2000px by default |
Value
Writes the ig
interaction graph to a PDF (.pdf
) file
to the folder specified in the path
Examples
#create temp dir path with slashes
myDir <- gsub("\\\\", "/", tempdir())
#create interaction graph
g <- interactionGraph(golf, "Play", intNo = 10)
#write to PDF
igToPDF(g, path = myDir, fName = "MyGraph", h = 2000)
Exports Interaction graph to a PNG file
Description
Exports Interaction graph to a PNG file
Usage
igToPNG(ig, path = "", fName = "InteractionGraph", h = 2000)
Arguments
ig |
Interaction graph |
path |
The folder in which to write the PNG file; |
fName |
The name of the file to be created; "InteractionGraph" by default |
h |
Desired height of the image in pixels; 2000px by default |
Value
Writes the ig
interaction graph to a PNG (.png
) file
to the folder specified in the path
Examples
#create temp dir path with slashes
myDir <- gsub("\\\\", "/", tempdir())
#create interaction graph
g <- interactionGraph(golf, "Play", intNo = 10)
#write to PNG
igToPNG(g, path = myDir, fName = "MyGraph", h = 2000)
Exports Interaction graph to a PS (PostScript) file
Description
Exports Interaction graph to a PS (PostScript) file
Usage
igToPS(ig, path = "", fName = "InteractionGraph", h = 2000)
Arguments
ig |
Interaction graph |
path |
The folder in which to write the PS file; |
fName |
The name of the file to be created; "InteractionGraph" by default |
h |
Desired height of the image in pixels; 2000px by default |
Value
Writes the ig
interaction graph to a PostScript (.ps
)
file to the folder specified in the path
Examples
#create temp dir path with slashes
myDir <- gsub("\\\\", "/", tempdir())
#create interaction graph
g <- interactionGraph(golf, "Play", intNo = 10)
#write to PS
igToPS(g, path = myDir, fName = "MyGraph", h = 2000)
Exports Interaction graph to a SVG file
Description
Exports Interaction graph to a SVG file
Usage
igToSVG(ig, path = "", fName = "InteractionGraph", h = 2000)
Arguments
ig |
Interaction graph |
path |
The folder in which to write the SVG file; |
fName |
The name of the file to be created; "InteractionGraph" by default |
h |
Desired height of the image in pixels; 2000px by default |
Value
Writes the ig
interaction graph to a SVG (.svg
) file
to the folder specified in the path
Examples
#create temp dir path with slashes
myDir <- gsub("\\\\", "/", tempdir())
#create interaction graph
g <- interactionGraph(golf, "Play", intNo = 10)
#write to SVG
igToSVG(g, path = myDir, fName = "MyGraph", h = 2000)
Calculates Information Gain (2-way Interaction Gain) of a discrete data.frame
Description
InfoGAIN = H(S) - H(S|X)
, where H(S)
is the difference in the
Shannon's entropy of the system S
before a new attribute X
is
introduced, and H(S|X)
is the entropy of the system after the attribute
X
has been introduced.
Usage
infoGain(df, inAtt, classAtt)
Arguments
df |
A discrete |
inAtt |
An input column of the data.frame |
classAtt |
A class column of the data.frame |
Value
The Information Gain of df
on the class attribute
classAtt
Examples
infoGain(golf, "Windy", "Play")
infoGain(golf, "Outlook", "Play")
Creates Interaction graph
Description
Creates Interaction graph
Usage
interactionGraph(df, classAtt, intNo = 16, speedUp = FALSE)
Arguments
df |
A |
classAtt |
A class column of the df ( |
intNo |
A desired number of interactions to show, i.e. an
( |
speedUp |
A ( |
Value
An interaction graph object (string
)
Examples
interactionGraph(golf, "Play", intNo = 10)
interactionGraph(golf, "Play", intNo = 10, speedUp = FALSE)
interactionGraph(golf, "Play", intNo = 10, speedUp = TRUE)
Calculates 3-Way Interactions
Description
Formula: I(X;Y;C) = I(X,Y;C) - IG(X;C) - IG(Y;C)
, where I(X;Y;C)
is 3-way Interaction gain of the attributes X
and Y
, given the
context (i.e. class) attribute C
. Hence, I(X,Y;C)
is a joint
2-way interaction gain (i.e. Information Gain) of the attributes X
and
Y
, and I(X;C)
and I(Y;C)
are 2-way Interaction gains
(i.e. Information Gains) of the attributes X
and Y
, respectively.
Usage
interactions3Way(df, classAtt, speedUp = FALSE)
Arguments
df |
A discrete |
classAtt |
A class column of the df ( |
speedUp |
A ( |
Value
A list with a: 1) data frame with 3-way interactions, 2)list of 2-way interactions of the input attributes
Examples
interactions3Way(golf, "Play")
interactions3Way(golf, "Play", speedUp = TRUE)
interactions3Way(golf, "Play", speedUp = FALSE)
Tests if data.frame is discrete (i.e. all of its columns are factors)
Description
Tests if data.frame is discrete (i.e. all of its columns are factors)
Usage
isDiscreteDataFrame(df)
Arguments
df |
A |
Value
Boolean
: TRUE
if all columns of the data.frame
df
are factors, FALSE
otherwise; If the provided df
object is of other type than data.frame
, the function throws an
error.
Examples
isDiscreteDataFrame(golf)
Plots Interaction graph
Description
Plots Interaction graph
Usage
plotIntGraph(ig)
Arguments
ig |
Interaction graph |
Value
Plots the ig
Examples
plotIntGraph(interactionGraph(golf, "Play", intNo = 10))
Print generic method for Interaction Graph (S3 class)
Description
Print generic method for Interaction Graph (S3 class)
Usage
## S3 method for class 'ig'
print(intGraph)
Arguments
intGraph |
An |
Value
Print (ig)
object
Print generic method for Interaction Graph Edges (S3 class)
Description
Print generic method for Interaction Graph Edges (S3 class)
Usage
## S3 method for class 'igEdge'
print(edge)
Arguments
edge |
An |
Value
Print (igEdge)
object
Print generic method for Interaction Graph Nodes (S3 class)
Description
Print generic method for Interaction Graph Nodes (S3 class)
Usage
## S3 method for class 'igNode'
print(node)
Arguments
node |
An |
Value
Print (igNode)
object
toString() generic method for Interaction Graph (S3 class)
Description
toString() generic method for Interaction Graph (S3 class)
Usage
## S3 method for class 'ig'
toString(intGraph)
Arguments
intGraph |
An |
Value
A character
object made of the provided ig
object
toString() generic method for Interaction Graph Edges (S3 class)
Description
toString() generic method for Interaction Graph Edges (S3 class)
Usage
## S3 method for class 'igEdge'
toString(edge)
Arguments
edge |
An |
Value
(character)
object made of the provided (igEdge)
object
toString() generic method for Interaction Graph Nodes (S3 class)
Description
toString() generic method for Interaction Graph Nodes (S3 class)
Usage
## S3 method for class 'igNode'
toString(node)
Arguments
node |
An |
Value
(character)
object made of the provided (igNode)
object