You are on page 1of 27

ALGORITHMIC BIAS SAMPLE.

A Tutorial
by Ethan Lynagh
Introduction
Here is a guided overview of how this code works with set data.

Setup
First is to load the required packages {dplyr, ggplot2, cowplot}, make sure to install these if your environment
does not contain them (run install.packages(“dplyr”, “ggplot2”, “cowplot”)). We will also be sourcing some
custom built packages in this step, which you can look through yourself in the functions folder.

# Import Functions
source(paste0("functions/plotTopGroupNames.R"))
source(paste0("functions/plotTopNames.R"))
source(paste0("functions/createTopProfilePlot.R"))

# Import Packages
library(dplyr)
library(ggplot2)
library(cowplot)
We also need to ingest the pre-made data, you can investigate the data in the environment window and you
can adjust it as you’d like. Any data in the same format with participant numbers matching will work.

# Import Data
data <- readRDS("dataList.Rda")

# Set data to their respective objects


g1_nameWeights <- data[[1]]
g1_charPlot <- data[[2]]
g1_topProfile <- data[[3]]
g2a_charPlot <- data[[4]]
g2a_topProfile <- data[[5]]
g2a_nameWeights <- data[[6]]
g2b_charPlot <- data[[7]]
g2b_topProfile <- data[[8]]
g2b_nameWeights <- data[[9]]
g2_nameWeights <- data[[10]]
g2_charPlot <- data[[11]]
g2_topProfile <- data[[12]]
g1a_charPlot <- data[[13]]
g1a_topProfile <- data[[14]]
g1a_nameWeights <- data[[15]]
g1b_charPlot <- data[[16]]
g1b_topProfile <- data[[17]]
g1b_nameWeights <- data[[18]]
Group 1
Next let’s build the group 1 example graphs. These graphs are for output analysis of algorithms that were built
based on participants voting on what other participants they think would best handle a prompted task. Top
names are the top ten and bottom ten voted participants for the task. Char plot is the participant demographic
characteristic and subcharacteristic weightings pulled from a fitted random forests model. The top profile
describes what characteristics would score the highest from the model.

# For group 1 top names


g1_topNamesPlotList <- plotTopNames(g1_nameWeights)
g1_topNamesPlots <- plot_grid(g1_topNamesPlotList[[1]], g1_topNamesPlotList[[2]],
rel_widths = 1, ncol = 2, rel_h eights = .5,
labels = c("Top 10", "Bottom 10"), vjust = 1)
ggplot_build(plot = g1_topNamesPlots)
# group 1 char plots
ggplot_build(plot = g1_charPlot)
# group 1 char plots
ggplot_build(plot = g1_charPlot)
# group 1 top profile plot
g1_topProfilePlot <-
createTopProfilePlot(g1_topProfile)
ggplot_build(plot = g1_topProfilePlot)
Group 2a
Next let’s build the group 2a example graphs. These graphs are for output analysis of participant
build algorithms. Char plot is the participant demographic characteristic and subcharacteristic
weightings derived from the participant build model. The top profile describes what characteristics
would score the highest from the model.Top names are the top ten and bottom ten model rated
participants for the task.

# group 2a char plots


ggplot_build(plot = g2a_charPlot)
# group 2a top profile plot
g2a_topProfilePlot <- createTopProfilePlot(g2a_topProfile)
ggplot_build(plot = g2a_topProfilePlot)
# group 2a top names
g2a_topNamesPlotList <-
plotTopGroupNames(names_and_weights_in =
g2a_nameWeights)
g2a_topNamesPlots <-
plot_grid(g2a_topNamesPlotList[[1]],
g2a_topNamesPlotList[[2]], rel_widths
= 1, ncol = 2, labels = c("Top 10",
"Bottom 10"), vjust = 1)
ggplot_build(plot = g2a_topNamesPlots)
Group 2b
Next let’s build the group 2b example graphs. These graphs are for output analysis of participant
built algorithms. Char plot is the participant demographic characteristic and subcharacteristic
weightings derived from the participant built model. The top profile describes what
characteristics would score the highest from the model.Top names are the top ten and bottom
ten model rated participants for the task.

# group 2b char plots


ggplot_build(plot = g2b_charPlot)
# group 2b top profile plot
g2b_topProfilePlot <- createTopProfilePlot(g2b_topProfile)
ggplot_build(plot = g2b_topProfilePlot)
# group 2b top names
g2b_topNamesPlotList <-
plotTopGroupNames(names_and_weights_in =
g2b_nameWeights)
g2b_topNamesPlots <-
plot_grid(g2b_topNamesPlotList[[1]],
g2b_topNamesPlotList[[2]], rel_widths = 1,
ncol = 2, labels = c("Top 10", "Bottom
10"), vjust = 1)
ggplot_build(plot = g2b_topNamesPlots)
Group 2
Next let’s build the group 2 example graphs. These graphs are for output analysis of algorithms that
were built based on participants voting on what other participants they think would best handle a
prompted task. Top names are the top ten and bottom ten voted participants for the task. Char plot is the
participant demographic characteristic and subcharacteristic weightings pulled from a fitted random
forests model. The top profile describes what characteristics would score the highest from the model.

# For group 2 top names


g2_topNamesPlotList <- plotTopNames(g2_nameWeights)
g2_topNamesPlots <- plot_grid(g2_topNamesPlotList[[1]], g2_topNamesPlotList[[2]],
rel_widths = 1, ncol = 2, rel_h eights = .5,
labels = c("Top 10", "Bottom 10"), vjust = 1)
ggplot_build(plot = g2_topNamesPlots)
# group 2 char plots
ggplot_build(plot = g2_charPlot)
# group 2 top profile plot
g2_topProfilePlot <- createTopProfilePlot(g2_topProfile)
ggplot_build(plot = g2_topProfilePlot)
Group 1a
Next let’s build the group 1a example graphs. These graphs are for output analysis of
participant build algorithms. Char plot is the participant demographic characteristic and
subcharacteristic weightings derived from the participant build model. The top profile
describes what characteristics would score the highest from the model.Top names are the
top ten and bottom ten model rated participants for the task.

# group 1a char plots


ggplot_build(plot = g1a_charPlot)
# group 1a top profile plot
g1a_topProfilePlot <- createTopProfilePlot(g1a_topProfile)
ggplot_build(plot = g1a_topProfilePlot)
# group 1a top names
g1a_topNamesPlotList <-
plotTopGroupNames(names_and_weights_in =
g1a_nameWeights)
g1a_topNamesPlots <-
plot_grid(g1a_topNamesPlotList[[1]],
g1a_topNamesPlotList[[2]], rel_widths = 1,
ncol = 2, labels = c("Top 10", "Bottom
10"), vjust = 1)
ggplot_build(plot = g1a_topNamesPlots)
Group 1B
Next let’s build the group 1B example graphs. These graphs are for output analysis of participant
build algorithms. Char plot is the participant demographic characteristic and subcharacteristic
weightings derived from the participant build model. The top profile describes what characteristics
would score the highest from the model.Top names are the top ten and bottom ten model rated
participants for the task.

# group 1b char plots


ggplot_build(plot = g1b_charPlot)
# group 1b top profile plot
g1b_topProfilePlot <-
createTopProfilePlot(g1b_topProfile)
ggplot_build(plot =
g1b_topProfilePlot)
# group 1b top names
g1b_topNamesPlotList <-
plotTopGroupNames(names_and_weights_
in = g1b_nameWeights)
g1b_topNamesPlots <-
plot_grid(g1b_topNamesPlotList[[
1]], g1b_topNamesPlotList[[2]],
rel_widths = 1, ncol = 2,
labels = c("Top 10", "Bottom
10"), vjust = 1)
ggplot_build(plot =
g1b_topNamesPlots)

You might also like