Construct a bipartite respondent-modality graph
Source:R/bipartite_modality_graph.R
bipartite_modality_graph.RdBuilds a two-mode (bipartite) graph where one partition of vertices represents respondents (rows of the data) and the other represents modalities (factor levels). An edge connects respondent \(i\) to modality \(V{=}l\) if row \(i\) has value \(l\) on variable \(V\).
Value
An object of class "catbipartite", a list with:
graphAn
igraphundirected graph with vertex attributetype(FALSE = respondent, TRUE = modality).modalitiesData frame describing modality-side vertices, with columns
node,variable,modality.n_rowsNumber of respondent-side vertices.
n_modalitiesNumber of modality-side vertices.
dataThe processed categorical data used to build the graph (after NA removal).
Details
Bipartite (two-mode) graphs preserve the full respondent-to-modality
incidence structure. They are the unprojected counterpart of the
modality co-association graph returned by
build_modality_graph: projecting a catbipartite
onto its modality partition yields a respondents-in-common modality
network, which is a count-based co-occurrence network
distinct from the chi-square / phi-filtered network produced by
build_modality_graph.
The bipartite graph is the correct tool when the scientific object of interest is the raw incidence relationship between units and categories — for example, affiliation networks (persons to events), ecological surveys (sites to species), or survey data seen as respondents endorsing response levels.
The resulting graph satisfies the igraph convention for bipartite
graphs: igraph::bipartite_projection(g) can be called directly
to obtain either the respondent-side or the modality-side projection.
Scope. A catbipartite is a raw incidence graph; it
applies no statistical filter. Edges reflect endorsement, not
association. For statistically-filtered category co-association,
see build_modality_graph.
See also
build_modality_graph for the chi-square /
phi-filtered modality co-association graph.
Examples
df <- expand_table(Titanic)
bg <- bipartite_modality_graph(df)
bg
#> catbipartite object (respondent-modality incidence graph)
#> Respondent nodes : 2201
#> Modality nodes : 10
#> Edges : 8804
#> Variables : Class, Sex, Age, Survived
summary(bg)
#> $n_rows
#> [1] 2201
#>
#> $n_modalities
#> [1] 10
#>
#> $n_edges
#> [1] 8804
#>
#> $variables
#> [1] "Class" "Sex" "Age" "Survived"
#>
#> $modalities_per_variable
#>
#> Age Class Sex Survived
#> 2 4 2 2
#>
# Project onto modalities: edges weighted by shared respondents
proj <- igraph::bipartite_projection(bg$graph, which = "true")