load data and libraries

library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.0      ✔ purrr   0.3.5 
## ✔ tibble  3.1.8      ✔ dplyr   1.0.10
## ✔ tidyr   1.2.1      ✔ stringr 1.4.1 
## ✔ readr   2.1.3      ✔ forcats 0.5.2 
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
ppm <- read.csv("publishingpaidme_data.csv", header = TRUE)

view data

names(ppm)
##  [1] "timestamp"        "primary_genre"    "subgenre_1"       "subgenre_2"      
##  [5] "subgenre_3"       "payment_usd"      "rights"           "sale_or_pub_year"
##  [9] "publisher"        "debut"            "agented"          "race"            
## [13] "race_2"           "race_3"           "race_4"           "gender"          
## [17] "sexuality"        "disability"       "author"           "title"           
## [21] "comp_titles_yn"   "comments"
#make categorical variables factors
ppm$debut <- as.factor(ppm$debut)
ppm$primary_genre <- as.factor(ppm$primary_genre)
ppm$rights <- as.factor(ppm$rights)
ppm$primary_genre <- as.factor(ppm$primary_genre)
ppm$subgenre_1 <- as.factor(ppm$subgenre_1)
ppm$subgenre_2 <- as.factor(ppm$subgenre_2)
ppm$subgenre_3 <- as.factor(ppm$subgenre_3)
ppm$publisher <- as.factor(ppm$publisher)
ppm$agented <- as.factor(ppm$agented)
ppm$race <- as.factor(ppm$race)
ppm$race_2 <- as.factor(ppm$race_2)
ppm$race_3 <- as.factor(ppm$race_3)
ppm$race_4 <- as.factor(ppm$race_4)
ppm$gender <- as.factor(ppm$gender)
ppm$sexuality <- as.factor(ppm$sexuality)
ppm$disability <- as.factor(ppm$disability)
ppm$comp_titles_yn <- as.factor(ppm$comp_titles_yn)
ppm$sale_or_pub_year <- as.numeric(ppm$sale_or_pub_year)
#hist(count(ppm$debut))

View the summary

summary(ppm)
##   timestamp                             primary_genre
##  Length:2856        YA                         :931  
##  Class :character   Science Fiction and Fantasy:311  
##  Mode  :character   Literary Fiction           :309  
##                     MG                         :301  
##                     Non-Fiction                :298  
##                     PB                         :219  
##                     (Other)                    :487  
##                         subgenre_1                          subgenre_2  
##                              :1865                               :2774  
##   Science Fiction and Fantasy: 385    Thriller/Mystery           :  10  
##   Memoir                     :  81    Science Fiction and Fantasy:   8  
##   Contemporary               :  72    Historical                 :   7  
##   Romance                    :  59    LGBT                       :   7  
##   Historical                 :  54    Short Story                :   7  
##  (Other)                     : 340   (Other)                     :  43  
##              subgenre_3    payment_usd                        rights   
##                   :2851   Min.   :   -100   Worldwide            :932  
##   BIPOC           :   1   1st Qu.:   6000                        :755  
##   LGBT            :   1   Median :  18000   English Language Only:598  
##   Literary Fiction:   1   Mean   :  49820   North America Only   :514  
##   Non-Fiction     :   1   3rd Qu.:  45000   Other Language Only  :  4  
##   Thriller/Mystery:   1   Max.   :3000000   UK and Commonwealth  :  3  
##                                             (Other)              : 50  
##  sale_or_pub_year                               publisher        debut     
##  Min.   :1990     Small/Indie                        :505   Yes     :1355  
##  1st Qu.:2014                                        :378   No      : 941  
##  Median :2017     Penguin Random House (and Imprints):303           : 506  
##  Mean   :2016     Large (Big 5)                      :269   YA Debut:  10  
##  3rd Qu.:2019     Mid-Size (Scholastic, Disney, etc) :246   PB Debut:   8  
##  Max.   :2024     HarperCollins (and Imprints)       :243   MG Debut:   7  
##  NA's   :462      (Other)                            :912   (Other) :  29  
##                            agented                 race     
##                                : 780   White         :1952  
##  For 12                        :   1   Black         : 152  
##  No                            : 397   East Asian    : 131  
##  Short Story collection contest:   1   Latin American:  89  
##  Yes                           :1677   Multiracial   :  76  
##                                        (Other)       : 175  
##                                        NA's          : 281  
##                             race_2              race_3              race_4    
##                                :2775               :2819               :2851  
##   White                        :  49    Multiracial:  32    Multiracial:   5  
##   Multiracial                  :  12    White      :   5                      
##   Nonwhite                     :   5                                          
##   Latin American               :   4                                          
##   Native American/First Nations:   3                                          
##  (Other)                       :   8                                          
##                gender            sexuality   
##  Cis Woman        :1810   Straight    :1313  
##  Cis Man          : 475               : 801  
##  None Reported    : 448   Bi/Pansexual: 317  
##  Nonbinary/Agender:  77   Queer       : 173  
##  Other            :  27   Gay         :  68  
##  Trans Man        :  11   Lesbian     :  58  
##  (Other)          :   8   (Other)     : 126  
##                                      disability      author         
##                                           : 967   Length:2856       
##  Chronic illness                          :   1   Class :character  
##  No                                       :1657   Mode  :character  
##  not disabled; I do have a neurodivergence:   1                     
##  PTSD                                     :   2                     
##  Yes                                      : 228                     
##                                                                     
##     title           comp_titles_yn   comments        
##  Length:2856           :2203       Length:2856       
##  Class :character   No : 323       Class :character  
##  Mode  :character   Yes: 330       Mode  :character  
##                                                      
##                                                      
##                                                      
## 
summary(ppm$payment_usd)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    -100    6000   18000   49820   45000 3000000
summary(ppm$race)
## Arab/West Asian/Middle Eastern                          Black 
##                             28                            152 
##                     East Asian             Indian/South Asian 
##                            131                             66 
##                 Latin American                    Multiracial 
##                             89                             76 
##  Native American/First Nations                       Nonwhite 
##                             14                             13 
##                          Other               Pacific Islander 
##                              3                              6 
##                Southeast Asian                          White 
##                             45                           1952 
##                           NA's 
##                            281
summary(ppm$race_2)
##                                  Arab/West Asian/Middle Eastern 
##                            2775                               2 
##                      East Asian                  Latin American 
##                               2                               4 
##                     Multiracial   Native American/First Nations 
##                              12                               3 
##                        Nonwhite                Pacific Islander 
##                               5                               2 
##                     South Asian                 Southeast Asian 
##                               1                               1 
##                           White 
##                              49
summary(ppm$gender)
##                  Cis Man                Cis Woman Genderfluid/Multi-Gender 
##                      475                     1810                        4 
##        Nonbinary/Agender            None Reported                    Other 
##                       77                      448                       27 
##                Trans Man              Trans Woman 
##                       11                        4

We need to clean up some variables: comp titles No/no/No. and Yes/yes need to be merged replace blanks with NA update agented to remove the two non-answer values change specific debut to yes/no *change disability answers to y/n

hist(ppm$payment_usd)

ggplot(ppm, aes(x = payment_usd)) +
  geom_histogram(bins = 45)

#mathematical summary
advances <- ppm %>% summarise(
  minimum = min(payment_usd),
  average = mean(payment_usd),
  median_payment = median(payment_usd),
  stdev = sd(payment_usd)
  
)
View(advances)

#summary
summary(ppm$payment_usd)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    -100    6000   18000   49820   45000 3000000
#   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
#  -100    6000   18000   49820   45000 3000000 

#who had below $0 advance?
min_ppm <- ppm[ppm$payment_usd < 0, ]
min_ppm
##          timestamp               primary_genre subgenre_1 subgenre_2 subgenre_3
## 281 6/16/2020 7:55 Science Fiction and Fantasy                                 
##     payment_usd    rights sale_or_pub_year   publisher debut agented  race
## 281        -100 Worldwide             2015 Small/Indie    No      No White
##     race_2 race_3 race_4  gender sexuality disability author title
## 281                      Cis Man  Straight         No             
##     comp_titles_yn
## 281               
##                                                                                                                                                                                             comments
## 281 The negative advance is due to contributing authors paying up front toward production and marketing costs, but the royalty rate was high. So far the authors have each earned $13k in royalties.
max_ppm <- ppm[ppm$payment_usd > 1000000, ]
max_ppm
##             timestamp    primary_genre subgenre_1 subgenre_2 subgenre_3
## 407    6/8/2020 11:38 Thriller/Mystery                                 
## 626   6/10/2020 12:10 Literary Fiction                                 
## 852  12/12/2022 15:33      Commercial                                  
## 2557   6/7/2020 22:46      Non-Fiction                                 
## 2568   6/7/2020 22:45      Non-Fiction                                 
## 2575    6/7/2020 9:31 Literary Fiction                                 
## 2579   6/7/2020 22:46      Non-Fiction                                 
##      payment_usd             rights sale_or_pub_year
## 407      1100000          Worldwide             2020
## 626      2500000 North America Only             2016
## 852      1150000 North America Only             2022
## 2557     3000000                                2018
## 2568     3000000                                2019
## 2575     1300000 North America Only             2020
## 2579     2000000                                2020
##                            publisher debut agented        race race_2 race_3
## 407                    Large (Big 5)    No     Yes       White              
## 626                                     No     Yes  East Asian              
## 852                    Large (Big 5)   Yes     Yes Multiracial              
## 2557                        Flatiron                      <NA>              
## 2568         Little/Brown (Hachette)                      <NA>              
## 2575        Macmillan (and Imprints)                      <NA>              
## 2579 Simon & Schuster (and Imprints)                      <NA>              
##      race_4        gender sexuality disability          author
## 407               Cis Man  Straight         No                
## 626             Cis Woman  Straight         No                
## 852             Cis Woman  Straight         No                
## 2557        None Reported                          James Comey
## 2568        None Reported                         Ronan Farrow
## 2575        None Reported                      Jeanine Cummins
## 2579        None Reported                          John Bolton
##                           title comp_titles_yn
## 407                                           
## 626                                           
## 852                                           
## 2557           A Higher Loyalty               
## 2568             Catch and Kill               
## 2575              American Dirt               
## 2579 The Room Where It Happened               
##                                                comments
## 407               I'm a well-known, best-selling author
## 626  award-winning author, already published bestseller
## 852                                             Auction
## 2557                                                   
## 2568                                                   
## 2575                                                   
## 2579

We’re going to remove the two outliers ($3M advance) from this analysis because they are James Comey and Ronan Farrow and that’s all that needs to be said about that.

ppm_corrected <- ppm[ppm$payment_usd < 3000000, ]
summary(ppm_corrected$payment_usd)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    -100    6000   18000   47753   45000 2500000

remove the additional outliers above $1M

ppm_corrected <- ppm[ppm$payment_usd < 1000000, ]
summary(ppm_corrected$payment_usd)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    -100    5500   18000   42659   45000  900000

#removing the outliers above $1M did not change the median payment, but does slightly lower the mean Min. 1st Qu. Median Mean 3rd Qu. Max. -100 5500 18000 42659 45000 900000

look at the relationships between gender, race, sexuality, debut y/n, and advance amount

racepay <- lm(payment_usd ~ race, data = ppm_corrected)
racepay
## 
## Call:
## lm(formula = payment_usd ~ race, data = ppm_corrected)
## 
## Coefficients:
##                       (Intercept)                          raceBlack  
##                          44866.51                           16406.02  
##                    raceEast Asian             raceIndian/South Asian  
##                          11130.26                           -7131.29  
##                raceLatin American                    raceMultiracial  
##                          -4107.97                           18564.66  
## raceNative American/First Nations                       raceNonwhite  
##                          33562.06                              95.02  
##                         raceOther               racePacific Islander  
##                         -35533.18                          -19283.01  
##               raceSoutheast Asian                          raceWhite  
##                           7638.73                           -3803.41
race_pay <- ggplot(ppm_corrected, aes(x = race, y = payment_usd))+
  geom_boxplot()+
  geom_jitter(width = 0.1) +
  theme_bw() +
   theme(axis.text.x = element_text(angle=90, vjust = 0.3)) +
  xlab("Race") +
  ylab("Payment (USD)") +
  ggtitle("Advance payments by self-reported racial groups \n (excluding outliers above $1M USD)")
plot(race_pay)

#add in the outliers
race_pay_2 <- ggplot(ppm, aes(x = race, y = payment_usd))+
  geom_boxplot()+
  geom_jitter(width = 0.1) +
  theme_bw() +
  theme(axis.text.x = element_text(angle=90, vjust = 0.3)) +
  xlab("Race") +
  ylab("Payment (USD)") +
  ggtitle("Advance payments by self-reported ethnic groups \n (including outliers above $1M USD)") +
  geom_text(x = 9, y = 2e+06, label = "Top outliers above $1M in the NA category: \n John Bolton \n James Comey \n Jeanine Cummins \n Ronan Farrow")
plot(race_pay_2)

look at relationship between gender and advance

genderpay <- lm(payment_usd ~ gender, data = ppm_corrected)
gender_pay <- ggplot(ppm_corrected, aes(x = gender, y = payment_usd))+
  geom_boxplot()
plot(gender_pay)

#add in the outliers
gender_pay_2 <- ggplot(ppm, aes(x = gender, y = payment_usd))+
  geom_boxplot() +
  geom_jitter(width = 0.1) +
  theme_bw() +
  theme(axis.text.x = element_text(angle=90, vjust = 0.3)) +
  xlab("Gender") +
  ylab("Payment (USD") +
  ggtitle("Advance payments reported in the Publishing Paid Me dataset \n grouped by self-reported Gender (USD)") +
  geom_text(x = 7, y = 2e+06, label = "Top outliers above $1M \n in the None Reported category: \n John Bolton \n James Comey \n Ronan Farrow \n Several unidentified authors")
plot(gender_pay_2)

year and advance

lm(payment_usd ~ sale_or_pub_year, data = ppm_corrected)
## 
## Call:
## lm(formula = payment_usd ~ sale_or_pub_year, data = ppm_corrected)
## 
## Coefficients:
##      (Intercept)  sale_or_pub_year  
##         64576.37            -11.28
year_pay <- ggplot(ppm_corrected, aes(x = sale_or_pub_year, y = payment_usd))+
  geom_smooth() +
  geom_point()
plot(year_pay)
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 460 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 460 rows containing missing values (`geom_point()`).

#add in the outliers
year_pay_2 <- ggplot(ppm, aes(x = sale_or_pub_year, y = payment_usd))+
  geom_smooth() +
  geom_point() +
  geom_jitter(width = 0.1) 
plot(year_pay_2)
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 462 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 462 rows containing missing values (`geom_point()`).
## Removed 462 rows containing missing values (`geom_point()`).

Plot a histogram of the overall pattern in payments

hist_payments <- ggplot(ppm, aes(x = payment_usd)) +
  geom_histogram(bins = 75)+
  theme_bw() +
  theme(axis.text.x = element_text(angle=90, vjust = 0.3)) +
  xlab("Payment (USD)") +
  ylab("Count") +
  ggtitle("Advance payments reported in the Publishing Paid Me dataset (USD)") +
  geom_text(x = 2e+06, y = 1250, label = "Minimum: $-100 \n Mean: $49820 \n Median: $18000 \n Maximum: $3M")
hist_payments

Do proportions of those reporting for gender

#make a table with the count data for gender
gender_counts <- ppm[, c(16, 6)] %>% 
  group_by(gender) %>%
  summarise(
    gender = unique(gender),
    count = n(),
    gender.index = paste(gender, count, sep = "\n")
  )
summary(gender_counts)
##                       gender      count         gender.index      
##  Cis Man                 :1   Min.   :   4.00   Length:8          
##  Cis Woman               :1   1st Qu.:   9.25   Class :character  
##  Genderfluid/Multi-Gender:1   Median :  52.00   Mode  :character  
##  Nonbinary/Agender       :1   Mean   : 357.00                     
##  None Reported           :1   3rd Qu.: 454.75                     
##  Other                   :1   Max.   :1810.00                     
##  (Other)                 :2
#import the treemap package
#install.packages("treemap")
library(treemap)
## Warning: package 'treemap' was built under R version 4.2.3
treemap(dtf = gender_counts, vSize = "count", index = "gender.index", fontsize.labels = 10, force.print.labels = TRUE, vColor = "count", type = "value") 

Do proportions of those reporting for race

#make a table with the count data for race/ethnicity
race_counts <- ppm[, c(12, 6)] %>% 
  group_by(race) %>%
  summarise(
    race = unique(race),
    count = n(),
    race.index = paste(race, count, sep = "\n")
  )
summary(race_counts)
##                              race       count         race.index       
##  Arab/West Asian/Middle Eastern:1   Min.   :   3.0   Length:13         
##  Black                         :1   1st Qu.:  14.0   Class :character  
##  East Asian                    :1   Median :  66.0   Mode  :character  
##  Indian/South Asian            :1   Mean   : 219.7                     
##  Latin American                :1   3rd Qu.: 131.0                     
##  (Other)                       :7   Max.   :1952.0                     
##  NA's                          :1
treemap(dtf = race_counts, vSize = "count", index = "race.index", fontsize.labels = 10, force.print.labels = TRUE, vColor = "count", type = "value") 

pub_count <- ppm[, c(9, 6)] %>% 
  group_by(publisher) %>%
  summarise(
    pub = unique(publisher),
    counts = n(),
    pub.index = paste(pub, counts, sep = "\n")
  )
summary(pub_count)
##        publisher            pub          counts       pub.index        
##             :  1              :  1   Min.   :  1.0   Length:218        
##  &NOW books :  1   &NOW books :  1   1st Qu.:  1.0   Class :character  
##  10 Speed   :  1   10 Speed   :  1   Median :  1.0   Mode  :character  
##  Abrams     :  1   Abrams     :  1   Mean   : 13.1                     
##  Abrams     :  1   Abrams     :  1   3rd Qu.:  3.0                     
##  Abrams Kids:  1   Abrams Kids:  1   Max.   :505.0                     
##  (Other)    :212   (Other)    :212
bar_publishers <- ggplot(pub_count, aes(x = pub)) +
  geom_bar()+
  theme_bw() +
  theme(axis.text.x = element_text(angle=90, vjust = 0.3)) +
  xlab("") +
  ylab("") +
  ggtitle("Advance payments reported in the Publishing Paid Me dataset (USD)") 
bar_publishers

agent_counts <- ppm[, c(11, 6)] %>% 
  group_by(agented) %>%
  summarise(
    agent = unique(agented),
    count = n(),
    agent.index = paste(agent, count, sep = "\n")
  )
summary(agent_counts)
##                            agented                             agent  
##                                :1                                 :1  
##  For 12                        :1   For 12                        :1  
##  No                            :1   No                            :1  
##  Short Story collection contest:1   Short Story collection contest:1  
##  Yes                           :1   Yes                           :1  
##                                                                       
##      count        agent.index       
##  Min.   :   1.0   Length:5          
##  1st Qu.:   1.0   Class :character  
##  Median : 397.0   Mode  :character  
##  Mean   : 571.2                     
##  3rd Qu.: 780.0                     
##  Max.   :1677.0
agented <- lm(payment_usd ~ agented, data = ppm)
summary(agented)
## 
## Call:
## lm(formula = payment_usd ~ agented, data = ppm)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
##  -58504  -46004  -28504   -3444 2946238 
## 
## Coefficients:
##                                       Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                              53762       4951  10.859  < 2e-16 ***
## agentedFor 12                           -53762     138363  -0.389    0.698    
## agentedNo                               -48118       8525  -5.644 1.82e-08 ***
## agentedShort Story collection contest   -52762     138363  -0.381    0.703    
## agentedYes                                4742       5993   0.791    0.429    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 138300 on 2851 degrees of freedom
## Multiple R-squared:  0.01657,    Adjusted R-squared:  0.01519 
## F-statistic: 12.01 on 4 and 2851 DF,  p-value: 1.122e-09