Skip to contents

Introduction

The imaginarycss package provides tools for analyzing Cognitive Social Structures (CSS), focusing on the discrepancies between actual social networks and individuals’ perceptions of those networks. This package is particularly useful for understanding how people perceive social relationships and the systematic errors they make in their social cognition.

What are Cognitive Social Structures?

Cognitive Social Structures (CSS) represent how individuals perceive the entire social network around them, not just their own relationships. Think of it this way: while traditional network analysis asks “Who is connected to whom?”, CSS analysis asks “Who thinks who is connected to whom?”

The Core Concept

Imagine you work in an office with 10 people. You have your own understanding of who talks to whom, who collaborates with whom, and who are friends. But your perception might be different from reality, and certainly different from what your colleagues perceive. CSS captures these multiple, potentially conflicting views of the same social reality.

Why This Matters

Understanding perceptual differences in social networks is crucial because:

  1. Decision Making: People base their social strategies on their perceptions, not reality
  2. Information Flow: Misperceptions can block or redirect information paths
  3. Organizational Dynamics: Leadership effectiveness often depends on accurate social perception
  4. Social Psychology: Systematic biases reveal fundamental cognitive processes

Types of Perceptual Errors

When we compare perceived networks to actual networks, several types of errors emerge:

  • False Positives: Seeing connections that don’t exist (“imaginary ties”)
  • False Negatives: Missing connections that do exist (“invisible ties”)
  • Reciprocity Errors: Misperceiving whether relationships are mutual
  • Asymmetric Biases: Systematically over- or under-estimating certain types of relationships

When we compare these perceptions to the actual network structure, we can identify various types of perceptual errors that reveal important insights about social cognition.

Key Features

  • Network Construction: Create binary array graphs from matrices or lists of adjacency matrices
  • Error Analysis: Compute various types of perceptual errors including reciprocity errors and imaginary census
  • Null Models: Generate null distributions for testing the prevalence of imaginary structures
  • Tie-Level Accuracy: Analyze individual-level accuracy rates for perceiving ties and non-ties
  • Network Sampling: Sample perceived networks based on individual accuracy rates

Let’s start by loading the package:


Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
Loading required package: viridisLite
# Set a beautiful theme for all plots
theme_set(theme_minimal(base_size = 12) +
  theme(
    plot.title = element_text(size = 16, face = "bold", color = "#2c3e50"),
    plot.subtitle = element_text(size = 12, color = "#7f8c8d"),
    axis.title = element_text(size = 11, color = "#34495e"),
    panel.grid.minor = element_blank(),
    panel.grid.major = element_line(color = "#ecf0f1", size = 0.5),
    legend.title = element_text(size = 10, face = "bold"),
    plot.background = element_rect(fill = "#ffffff", color = NA),
    panel.background = element_rect(fill = "#ffffff", color = NA)
  ))
Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
ℹ Please use the `linewidth` argument instead.
# Define a beautiful color palette
css_colors <- c(
  primary = "#3498db",
  secondary = "#e74c3c", 
  accent = "#9b59b6",
  success = "#27ae60",
  warning = "#f39c12",
  info = "#17a2b8",
  light = "#95a5a6",
  dark = "#2c3e50"
)

Basic Usage

Creating a Barry Graph

The fundamental data structure in imaginarycss is the barry_graph object, which represents a collection of networks where the first network is the “true” network and subsequent networks represent different individuals’ perceptions.

Understanding the Data Structure

A barry_graph object is essentially a “stack” of adjacency matrices: - Layer 0: The actual/true network (ground truth) - Layer 1: Person 1’s perception of the entire network - Layer 2: Person 2’s perception of the entire network - Layer N: Person N’s perception of the entire network

This structure allows us to compare what each person thinks the network looks like against reality and against each other’s perceptions.

Why “Barry Graph”?

The name comes from the underlying C++ library that efficiently handles binary array operations on multiple network layers simultaneously. This allows for fast computation of complex network comparisons that would be slow with traditional matrix operations.

Example 1: Simple Network from Matrix

Let’s create a simple example with a 4-node network:

# Define edges for the true network and one perceived network
source_ <- c(1, 2, 3, 1) 
target_ <- c(2, 1, 4, 4)

# Add perceived network (shifted by network size)
source_ <- c(source_, source_[-1] + 4)
target_ <- c(target_, target_[-1] + 4)

# Create adjacency matrix
adjmat <- matrix(0L, nrow = 8, ncol = 8)
adjmat[cbind(source_, target_)] <- 1L

# Create barry_graph object
graph <- new_barry_graph(adjmat, n = 4)
print(graph)
A barry_graph with 2 networks of size 4
.    .  1.00     .  1.00     .     .     .     .
 1.00     .     .     .     .     .     .     .
    .     .     .  1.00     .     .     .     .
    .     .     .     .     .     .     .     .
    .     .     .     .     .     .     .  1.00
    .     .     .     .  1.00     .     .     .
    .     .     .     .     .     .     .  1.00
    .     .     .     .     .     .     .     . 

What’s happening here?

  1. True Network: We define a 4-person network with edges (1→2, 2→1, 3→4, 1→4)
  2. Perceived Network: We create one person’s perception by taking some of the true edges and shifting their indices by the network size (4)
  3. Combined Matrix: The 8×8 matrix contains both networks stacked together
  4. Barry Graph: The new_barry_graph() function recognizes this structure and creates the specialized object

The key insight is that the person’s perception (edges 2→1, 3→4, 1→4 shifted to positions 6→5, 7→8, 5→8) represents what one individual thinks the network looks like - which may differ from reality.

Example 2: Network from List of Matrices

Alternatively, you can create a barry_graph from a list of adjacency matrices:

# True network (4x4)
true_net <- matrix(c(
  0, 1, 0, 1,
  1, 0, 1, 0,
  0, 1, 0, 1,
  1, 0, 1, 0
), nrow = 4, byrow = TRUE)

# Perceived network by individual 1
perceived_net1 <- matrix(c(
  0, 1, 1, 1,  # Person 1 thinks there are more connections
  1, 0, 1, 0,
  1, 1, 0, 1,
  1, 0, 1, 0
), nrow = 4, byrow = TRUE)

# Perceived network by individual 2
perceived_net2 <- matrix(c(
  0, 1, 0, 0,  # Person 2 thinks there are fewer connections
  1, 0, 0, 0,
  0, 0, 0, 1,
  0, 0, 1, 0
), nrow = 4, byrow = TRUE)

# Create barry_graph from list
net_list <- list(true_net, perceived_net1, perceived_net2)
graph_from_list <- new_barry_graph(net_list)
print(graph_from_list)
A barry_graph with 3 networks of size 4
.    .  1.00     .  1.00     .     .     .     .     .     .
 1.00     .  1.00     .     .     .     .     .     .     .
    .  1.00     .  1.00     .     .     .     .     .     .
 1.00     .  1.00     .     .     .     .     .     .     .
    .     .     .     .     .  1.00  1.00  1.00     .     .
    .     .     .     .  1.00     .  1.00     .     .     .
    .     .     .     .  1.00  1.00     .  1.00     .     .
    .     .     .     .  1.00     .  1.00     .     .     .
    .     .     .     .     .     .     .     .     .  1.00
    .     .     .     .     .     .     .     .  1.00     .
Skipping 2 rows. Skipping 2 columns. 

Understanding the Perceptual Differences:

  • True Network: A regular pattern with 6 edges
  • Person 1’s Perception: Sees 8 edges (33% more than reality) - this person has a “densification bias”
  • Person 2’s Perception: Sees only 4 edges (33% fewer than reality) - this person has a “sparsification bias”

These different perceptions could arise from various factors: - Position in network: Central people might see more connections - Personality traits: Extroverts might perceive more social activity - Attention patterns: Some people notice strong ties, others notice weak signals - Social desirability: People might report what they think should exist

Key Attributes

Every barry_graph object has important attributes:

# Network size (number of nodes)
cat("Network size:", attr(graph, "netsize"), "\n")
Network size: 4 
# Endpoints (boundaries between networks in the combined structure)
cat("Endpoints:", attr(graph, "endpoints"), "\n")
Endpoints: 8 
# Convert to edgelist for inspection
edgelist <- barray_to_edgelist(graph)
head(edgelist)
     source target
[1,]      1      2
[2,]      1      4
[3,]      2      1
[4,]      3      4
[5,]      5      8
[6,]      6      5

References

  • Krackhardt, D. (1987). Cognitive social structures. Social Networks, 9(2), 109-134.
  • Vega Yon, G. G., & Demarais, A. (2022). Exponential random graph models for little networks. Social Networks, 70, 181-195.

This vignette was created with imaginarycss version 0.1.0.