607 Week 10 B only one question

Author

Enrique Delamonica

Preliminaries

The libraries expected to be used are downloaded.

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.2.1     ✔ readr     2.2.0
✔ forcats   1.0.1     ✔ stringr   1.6.0
✔ ggplot2   4.0.3     ✔ tibble    3.3.1
✔ lubridate 1.9.5     ✔ tidyr     1.3.2
✔ purrr     1.2.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(jsonlite)

Attaching package: 'jsonlite'

The following object is masked from 'package:purrr':

    flatten
library(repurrrsive)

These are the questions I set out to explore:

  1. List those who won more than once

  2. Filter men and women. Calculate the proportion of women and men winners

  3. Compare the proportion of men and women winners in economics against all the other disciplines combined.

  4. Filter and combine winners by science and by continent of birth. I am thinking of continent rather than country because I would like to create a table and with many countries, it will be difficult to read.

The data

For this exercise data had to be requested from the Nobel Prize organization developer API. I was able to download the data and uploaded it in GitHub. From there I was able to retrieve them in R.

The Nobel Prize organization developer API provides two endpoints I have used both. I have explored their nested structure.

Winners<- read_json("https://raw.githubusercontent.com/Enrique01234/607-Fall-2026/refs/heads/main/Laurates2.json", simplifyVector = TRUE)
NobelWinners<- read_json("https://raw.githubusercontent.com/Enrique01234/607-Fall-2026/refs/heads/main/NobelWinners.json", simplifyVector = TRUE)
##Winners
##NobelWinners

I started with the data frame “Winners”. I selected each winner’s ID to start creating a data frame (Winners_id) to use for my analysis.

At this point I realized I did not have all the winners. I have tried several times to go back to the Nobel Prize API and retrieve all of them. I did manage to do so every time. However, when converting it to a JSON file, it got truncated every time, Nevertheless, I decided to continue with the exercise with a smaller set of winners (which hampered some of the questions I wanted to explore).

Winners_id<-Winners$laureates|>
  select(id)
Winners_id
     id
1   745
2   102
3   779
4   259
5  1004
6   114
7   982
8   981
9   843
10  866
11  199
12  164
13  185
14  541
15  292
16  853
17  978
18  819
19 1012
20  729
21  376
22  730
23   11
24  628
25  403

The, I added some of the other variables I am interested in exploring.

Winners_id<-Winners$laureates|>
  select(id, fileName, gender)
Winners_id
     id    fileName gender
1   745      spence   male
2   102        bohr   male
3   779 ciechanover   male
4   259        klug   male
5  1004      gurnah   male
6   114       salam   male
7   982    banerjee   male
8   981        abiy   male
9   843      yonath female
10  866       riess   male
11  199   butenandt   male
12  164      baeyer   male
13  185     windaus   male
14  541    esquivel   male
15  292      zewail   male
16  853      suzuki   male
17  978     yoshino   male
18  819        gore   male
19 1012      aspect   male
20  729      heeger   male
21  376     hodgkin   male
22  730  macdiarmid   male
23   11   michelson   male
24  628       camus   male
25  403      claude   male

Selecting these variables was rather straightforward. Selecting the continent the winners are from was more difficult, given the nested structure. So I created a different data frame (Winners_loc).

Winners_loc<-Winners$laureates$birth$place$continent|>
    select(en)
Winners_loc
              en
1  North America
2         Europe
3           Asia
4         Europe
5           <NA>
6           Asia
7           Asia
8         Africa
9           Asia
10 North America
11        Europe
12        Europe
13        Europe
14 South America
15        Africa
16          Asia
17          Asia
18 North America
19        Europe
20 North America
21        Europe
22       Oceania
23        Europe
24        Africa
25        Europe

In order to be able to join these two data frames, I created a new variable (newid) in each data frame.

Winners_loc$newid <- 1:nrow(Winners_loc)
Winners_id$newid <- 1:nrow(Winners_id)

Then I created a new data frame (Winners_idloc), basically replicating (Winners_id). to be used for joining the two data frames.

Winners_idloc<- Winners_id

I did a simple inner-join.

Winners_idloc<- Winners_idloc|> 
  inner_join(Winners_loc)
Joining with `by = join_by(newid)`

As the categories (sciences) for each winner were deeply nested in the data frame Winners (at least for me), I found it easier to retrieve them from the NobelWinners data frame.

Winners_cat<-NobelWinners$nobelPrizes$category|>
  select(en)
Winners_cat
                       en
1               Chemistry
2              Literature
3                   Peace
4                 Physics
5  Physiology or Medicine
6               Chemistry
7              Literature
8                   Peace
9                 Physics
10 Physiology or Medicine
11              Chemistry
12             Literature
13                  Peace
14                Physics
15 Physiology or Medicine
16              Chemistry
17             Literature
18                  Peace
19                Physics
20 Physiology or Medicine
21              Chemistry
22             Literature
23                  Peace
24                Physics
25 Physiology or Medicine

However, these 25 entries are not the same as the 25 in the other data frame Thus, I cannot join them.

I know they are not the same because, when analyzing the structure, I can see the names are different.

I have also tried unnesting from the Winners data frame.

Categories<-Winners
Categories2<-tibble(tounnest = Categories)
Categories2 |> unnest_wider(tounnest)
# A tibble: 3 × 24
           id   knownName givenName familyName fullName fileName gender    birth
  <list<chr>> <list<df[,> <list<df> <list<df[> <list<d> <list<c> <list> <list<d>
1        [25]    [25 × 2]  [25 × 2]   [25 × 2] [25 × 2]     [25]   [25] [25 × 3]
2                                                                               
3                                                                               
# ℹ 16 more variables: wikipedia <list<df[,2]>>, wikidata <list<df[,2]>>,
#   sameAs <list<list>>, links <list<list>>, nobelPrizes <list<list>>,
#   death <list<df[,2]>>, offset <int>, limit <int>, count <int>, terms <chr>,
#   license <chr>, disclaimer <chr>, first <chr>, self <chr>, `next` <chr>,
#   last <chr>

The list with the categories is there. I just could not find a way to retrieve it.

The One Result

There are famous cases of persons who won more than one Nobel Prize (e.g. Marie Curie). However, I have used a truncated data set (he first 25 winners with first name starting with A). Thus, I did not find any repeat winner. I could not answer two of the remaining questions.

I could only answer (partially, as I had only 25 winners), the question about the proportion of women and men winners.

Grouping these winners by male and female is simple. Counting them and producing a bar graph to show them is also easy.

Winners_idloc|>
  group_by(gender)|>
  count()
# A tibble: 2 × 2
# Groups:   gender [2]
  gender     n
  <chr>  <int>
1 female     1
2 male      24
ggplot(Winners_idloc, aes(x = gender)) + 
  geom_bar()

Identifying specifically the female winner is also easy.

Winners_f<- Winners_idloc|>
  filter(gender == "female")
Winners_f
   id fileName gender newid   en
1 843   yonath female     9 Asia

Besides the count, the proportions of male and female winners can also be calculated.

Winners_idloc |>
  group_by(gender) |>
  summarise(n = n()) |>
  mutate(freq = n / sum(n))
# A tibble: 2 × 3
  gender     n  freq
  <chr>  <int> <dbl>
1 female     1  0.04
2 male      24  0.96