| Title: | An Implementation of Interaction Graphs of Aleks Jakulin |
|---|---|
| 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/>. |
| Authors: | Petar Markovic [aut, cre] |
| Maintainer: | Petar Markovic <[email protected]> |
| License: | GPL-3 |
| Version: | 1.0.0 |
| Built: | 2026-05-13 07:29:09 UTC |
| Source: | https://github.com/peleplay/integr |
Formula: , where is the
probability of the corresponding -th class
entropy(df, classAtt)entropy(df, classAtt)
df |
A discrete |
classAtt |
A class column of the df ( |
The Shannon's entropy of the df, based on the classAtt
attribute
entropy(golf, "Play")entropy(golf, "Play")
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.
golfgolf
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:
Input attribute, values: Overcast, Rainy, Sunny
Input attribute, values: Cool, Hot, Mild
Input attribute, values: High, Normal
Input attribute, values: True, False
Artifically added input attribute indicating whether the players on the other courts were playing the golf at the given time, values: Yes, No
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)
ig(n, e)ig(n, e)
n |
ig.nodes ( |
e |
ig.edges ( |
An instance of the ig class
Constructs Interaction Graph Edges (S3 class)
igEdge(n1, n2, w)igEdge(n1, n2, w)
n1 |
igEdge.node1 |
n2 |
igEdge.node2 |
w |
igEdge.weight (i.e. 3-way Interaction Gain) |
An instance of the igEdge class
Constructs Interaction Graph Nodes (S3 class)
igNode(n, v)igNode(n, v)
n |
igNode.name |
v |
igNode.value |
An instance of the igNode class
Exports Interaction graph to a GraphViz file
igToGrViz(ig, path = "", fName = "InteractionGraph")igToGrViz(ig, path = "", fName = "InteractionGraph")
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 |
Writes the ig interaction graph to a GraphViz .gv file
to the folder specified in the path
#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")#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
igToPDF(ig, path = "", fName = "InteractionGraph", h = 2000)igToPDF(ig, path = "", fName = "InteractionGraph", h = 2000)
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 |
Writes the ig interaction graph to a PDF (.pdf) file
to the folder specified in the path
#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)#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
igToPNG(ig, path = "", fName = "InteractionGraph", h = 2000)igToPNG(ig, path = "", fName = "InteractionGraph", h = 2000)
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 |
Writes the ig interaction graph to a PNG (.png) file
to the folder specified in the path
#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)#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
igToPS(ig, path = "", fName = "InteractionGraph", h = 2000)igToPS(ig, path = "", fName = "InteractionGraph", h = 2000)
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 |
Writes the ig interaction graph to a PostScript (.ps)
file to the folder specified in the path
#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)#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
igToSVG(ig, path = "", fName = "InteractionGraph", h = 2000)igToSVG(ig, path = "", fName = "InteractionGraph", h = 2000)
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 |
Writes the ig interaction graph to a SVG (.svg) file
to the folder specified in the path
#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)#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)
, where is the difference in the
Shannon's entropy of the system before a new attribute is
introduced, and is the entropy of the system after the attribute
has been introduced.
infoGain(df, inAtt, classAtt)infoGain(df, inAtt, classAtt)
df |
A discrete |
inAtt |
An input column of the data.frame |
classAtt |
A class column of the data.frame |
The Information Gain of df on the class attribute
classAtt
infoGain(golf, "Windy", "Play") infoGain(golf, "Outlook", "Play")infoGain(golf, "Windy", "Play") infoGain(golf, "Outlook", "Play")
Creates Interaction graph
interactionGraph(df, classAtt, intNo = 16, speedUp = FALSE)interactionGraph(df, classAtt, intNo = 16, speedUp = FALSE)
df |
A |
classAtt |
A class column of the df ( |
intNo |
A desired number of interactions to show, i.e. an
( |
speedUp |
A ( |
An interaction graph object (string)
interactionGraph(golf, "Play", intNo = 10) interactionGraph(golf, "Play", intNo = 10, speedUp = FALSE) interactionGraph(golf, "Play", intNo = 10, speedUp = TRUE)interactionGraph(golf, "Play", intNo = 10) interactionGraph(golf, "Play", intNo = 10, speedUp = FALSE) interactionGraph(golf, "Play", intNo = 10, speedUp = TRUE)
Formula: , where
is 3-way Interaction gain of the attributes and , given the
context (i.e. class) attribute . Hence, is a joint
2-way interaction gain (i.e. Information Gain) of the attributes and
, and and are 2-way Interaction gains
(i.e. Information Gains) of the attributes and , respectively.
interactions3Way(df, classAtt, speedUp = FALSE)interactions3Way(df, classAtt, speedUp = FALSE)
df |
A discrete |
classAtt |
A class column of the df ( |
speedUp |
A ( |
A list with a: 1) data frame with 3-way interactions, 2)list of 2-way interactions of the input attributes
interactions3Way(golf, "Play") interactions3Way(golf, "Play", speedUp = TRUE) interactions3Way(golf, "Play", speedUp = FALSE)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)
isDiscreteDataFrame(df)isDiscreteDataFrame(df)
df |
A |
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.
isDiscreteDataFrame(golf)isDiscreteDataFrame(golf)
Plots Interaction graph
plotIntGraph(ig)plotIntGraph(ig)
ig |
Interaction graph |
Plots the ig
plotIntGraph(interactionGraph(golf, "Play", intNo = 10))plotIntGraph(interactionGraph(golf, "Play", intNo = 10))
Print generic method for Interaction Graph (S3 class)
## S3 method for class 'ig' print(intGraph)## S3 method for class 'ig' print(intGraph)
intGraph |
An |
Print (ig) object
Print generic method for Interaction Graph Edges (S3 class)
## S3 method for class 'igEdge' print(edge)## S3 method for class 'igEdge' print(edge)
edge |
An |
Print (igEdge) object
Print generic method for Interaction Graph Nodes (S3 class)
## S3 method for class 'igNode' print(node)## S3 method for class 'igNode' print(node)
node |
An |
Print (igNode) object
toString() generic method for Interaction Graph (S3 class)
## S3 method for class 'ig' toString(intGraph)## S3 method for class 'ig' toString(intGraph)
intGraph |
An |
A character object made of the provided ig object
toString() generic method for Interaction Graph Edges (S3 class)
## S3 method for class 'igEdge' toString(edge)## S3 method for class 'igEdge' toString(edge)
edge |
An |
(character) object made of the provided (igEdge) object
toString() generic method for Interaction Graph Nodes (S3 class)
## S3 method for class 'igNode' toString(node)## S3 method for class 'igNode' toString(node)
node |
An |
(character) object made of the provided (igNode) object