Little useless-useful R functions – Absurd bias DAG with useless mental shortcuts

Exploring graphs is always a fun. Attaching the edges and nodes with real examples of psychological effects and accompany them with useless mental shortcuts is beyond fun. This is why we will call it a “cognitive bias” explorer using DAG.

Here are the graphs edges and nodes and we are calling them biases and weird links. Because, yes 🙂 Let’s mix the math with psychology.

  biases <- c(
    "Confirmation Bias", "Anchoring Bias", "Availability Heuristic", 
    "Dunning-Kruger Effect", "Survivorship Bias", "Recency Bias",
    "Sunk Cost Fallacy", "Bandwagon Effect", "Framing Effect", 
    "Self-Serving Bias", "Negativity Bias", "Halo Effect"
  )
  
  # useless links 🙂
  weird_links <- c(
    "You saw it on Reddit", "Too lazy to verify", "Sounds familiar",
    "Because Elon tweeted it", "Grandma said so", "Wikipedia said maybe",
    "Your gut feeling", "Cited by no one", "Used in a TED talk",
    "Found in fortune cookie", "Might be science", "Feels statistically valid"
  )

With this real life useless connections we can build a data.frame:

  edges <- data.frame(
    from = sample(biases, n_links, replace = TRUE),
    to = sample(biases, n_links, replace = TRUE),
    reason = sample(weird_links, n_links, replace = TRUE),
    stringsAsFactors = FALSE
  )

And finally, let’s glue all the pieces together:

library(igraph)
library(ggraph)
library(ggplot2)

bias_explorer <- function(seed = 2908, n_links = 25) {
  set.seed(seed)
  
  # Some psych effects from RL
  biases <- c(
    "Confirmation Bias", "Anchoring Bias", "Availability Heuristic", 
    "Dunning-Kruger Effect", "Survivorship Bias", "Recency Bias",
    "Sunk Cost Fallacy", "Bandwagon Effect", "Framing Effect", 
    "Self-Serving Bias", "Negativity Bias", "Halo Effect"
  )
  
  # useless links 🙂
  weird_links <- c(
    "You saw it on Reddit", "Too lazy to verify", "Sounds familiar",
    "Because Elon tweeted it", "Grandma said so", "Wikipedia said maybe",
    "Your gut feeling", "Cited by no one", "Used in a TED talk",
    "Found in fortune cookie", "Might be science", "Feels statistically valid"
  )

  edges <- data.frame(
    from = sample(biases, n_links, replace = TRUE),
    to = sample(biases, n_links, replace = TRUE),
    reason = sample(weird_links, n_links, replace = TRUE),
    stringsAsFactors = FALSE
  )
  
  edges <- edges[edges$from != edges$to, ]
  g <- graph_from_data_frame(edges, vertices = data.frame(name = biases), directed = TRUE)

  ggraph(g, layout = "drl") +
    geom_edge_link(
      aes(label = reason),
      arrow = arrow(length = unit(3, 'mm')),
      end_cap = circle(2, 'mm'),
      start_cap = circle(2, 'mm'),
      label_colour = "darkgray",
      edge_width = 1.2,
      colour = "skyblue"
    ) +
    geom_node_point(color = "darkred", size = 6) +
    geom_node_text(aes(label = name), repel = TRUE, fontface = "bold", size = 3.5) +
    labs(
      title = "Bias_explorer(): The Absurd Web of Biases",
      subtitle = "Visualizing ridiculous mental shortcuts.",
      caption = "Edges represent irrational and useless connections."
    ) +
    theme_void()
  
}

Just to get a graph of random connections that can spark useless or useful imagination when examining your or one’s head. 🙂

As always, the complete code is available on GitHub in  Useless_R_function repository. The sample file in this repository is here (filename: Cognitive bias.R). Check the repository for future updates.

Carry on with R-coding and stay healthy!

Tagged with: , , , , , , , , , , ,
Posted in R, Uncategorized, Useless R functions
One comment on “Little useless-useful R functions – Absurd bias DAG with useless mental shortcuts
  1. […] article was first published on R – TomazTsql, and kindly contributed to R-bloggers]. (You can report issue about the content on this page […]

    Like

Leave a comment

Follow TomazTsql on WordPress.com
Programs I Use: SQL Search
Programs I Use: R Studio
Programs I Use: Plan Explorer
Rdeči Noski – Charity

Rdeči noski

100% of donations made here go to charity, no deductions, no fees. For CLOWNDOCTORS - encouraging more joy and happiness to children staying in hospitals (http://www.rednoses.eu/red-noses-organisations/slovenia/)

€2.00

Top SQL Server Bloggers 2018
TomazTsql

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

Discover WordPress

A daily selection of the best content published on WordPress, collected for you by humans who love to read.

Revolutions

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

Reeves Smith's SQL & BI Blog

A blog about SQL Server and the Microsoft Business Intelligence stack with some random Non-Microsoft tools thrown in for good measure.

SQL Server

for Application Developers

Business Analytics 3.0

Data Driven Business Models

SQL Database Engine Blog

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

Search Msdn

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

R-bloggers

Tomaz doing BI and DEV with SQL Server and R, Python, Power BI, Azure and beyond

Data Until I Die!

Data for Life :)

Paul Turley's SQL Server BI Blog

sharing my experiences with the Microsoft data platform, SQL Server BI, Data Modeling, SSAS Design, Power Pivot, Power BI, SSRS Advanced Design, Power BI, Dashboards & Visualization since 2009

Grant Fritchey

Intimidating Databases and Code

Madhivanan's SQL blog

A modern business theme

Alessandro Alpi's Blog

DevOps could be the disease you die with, but don’t die of.

Paul te Braak

Business Intelligence Blog

Sql Insane Asylum (A Blog by Pat Wright)

Information about SQL (PostgreSQL & SQL Server) from the Asylum.

Gareth's Blog

A blog about Life, SQL & Everything ...

SQLPam's Blog

Life changes fast and this is where I occasionally take time to ponder what I have learned and experienced. A lot of focus will be on SQL and the SQL community – but life varies.

William Durkin

William Durkin a blog on SQL Server, Replication, Performance Tuning and whatever else.

$hell Your Experience !!!

As aventuras de um DBA usando o Poder do $hell

Design a site like this with WordPress.com
Get started