To begin this lab first I asked Chat GPT to complete the code for project 1. I decided to skip Project 1 so I wanted to not only have it completed, but an explanation of how it was completed so that I could understand the data set exported. Which took me time to go through the work and understand everything the Chat GPT’s code. From here, I found an ELO calculation formula on GeeksForGeek.org. Now I plan to better understand how the formula works to then figure out how I want to calculate the expected scores. One thing that I anticipate having trouble with is getting the opponent ELO scores to calculate the expected for each player. But I assume as I better understand the project one code, I will be able to use parts of it to make this process smoother. I will update my conclusion with my findings.
library(dplyr)
##
## 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
library(tidyr)
chess_results <- read.csv("https://raw.githubusercontent.com/Renagade316/DATA607-Labs/refs/heads/main/Lab%205/Lab%205B%20-%20ELO%20Calculations/chess_results.csv")
opponents <- read.csv("https://raw.githubusercontent.com/Renagade316/DATA607-Labs/refs/heads/main/Lab%205/Lab%205B%20-%20ELO%20Calculations/opponents.csv")
round_results_df <- read.csv("https://raw.githubusercontent.com/Renagade316/DATA607-Labs/refs/heads/main/Lab%205/Lab%205B%20-%20ELO%20Calculations/round_results.csv")
# Convert W/D/L into actual scores
actual_score <- function(result) {
if(is.na(result)) {
return(NA)
}
if(result == "W") {
return(1)
}
if(result == "D") {
return(0.5)
}
if(result == "L") {
return(0)
}
return(NA)
}
# Calculate each player's total actual score
actual_scores <- sapply(
round_results_df,
function(results) sum(sapply(results, actual_score), na.rm = TRUE)
)
chess_results$Actual.Score <- actual_scores
# Calculate each player's total expected score
calculate_expected_score <- function(player_rating, opponent_numbers) {
opponent_ratings <- chess_results$Pre_Rating[opponent_numbers]
expected_scores <- 1 / (
1 + 10^((opponent_ratings - player_rating) / 400)
)
sum(expected_scores, na.rm = TRUE)
}
chess_results$Expected.Score <- mapply(
calculate_expected_score,
chess_results$Pre_Rating,
opponents
)
# Calculate over/underperformance
chess_results$Difference <-
chess_results$Actual.Score - chess_results$Expected.Score
chess_results
## Player_Name State Total_Points Pre_Rating
## 1 GARY HUA ON 6.0 1794
## 2 DAKSHESH DARURI MI 6.0 1553
## 3 ADITYA BAJAJ MI 6.0 1384
## 4 PATRICK H SCHILLING MI 5.5 1716
## 5 HANSHI ZUO MI 5.5 1655
## 6 HANSEN SONG OH 5.0 1686
## 7 GARY DEE SWATHELL MI 5.0 1649
## 8 EZEKIEL HOUGHTON MI 5.0 1641
## 9 STEFANO LEE ON 5.0 1411
## 10 ANVIT RAO MI 5.0 1365
## 11 CAMERON WILLIAM MC LEMAN MI 4.5 1712
## 12 KENNETH J TACK MI 4.5 1663
## 13 TORRANCE HENRY JR MI 4.5 1666
## 14 BRADLEY SHAW MI 4.5 1610
## 15 ZACHARY JAMES HOUGHTON MI 4.5 1220
## 16 MIKE NIKITIN MI 4.0 1604
## 17 RONALD GRZEGORCZYK MI 4.0 1629
## 18 DAVID SUNDEEN MI 4.0 1600
## 19 DIPANKAR ROY MI 4.0 1564
## 20 JASON ZHENG MI 4.0 1595
## 21 DINH DANG BUI ON 4.0 1563
## 22 EUGENE L MCCLURE MI 4.0 1555
## 23 ALAN BUI ON 4.0 1363
## 24 MICHAEL R ALDRICH MI 4.0 1229
## 25 LOREN SCHWIEBERT MI 3.5 1745
## 26 MAX ZHU ON 3.5 1579
## 27 GAURAV GIDWANI MI 3.5 1552
## 28 SOFIA ADINA STANESCU-BELLU MI 3.5 1507
## 29 CHIEDOZIE OKORIE MI 3.5 1602
## 30 GEORGE AVERY JONES ON 3.5 1522
## 31 RISHI SHETTY MI 3.5 1494
## 32 JOSHUA PHILIP MATHEWS ON 3.5 1441
## 33 JADE GE MI 3.5 1449
## 34 MICHAEL JEFFERY THOMAS MI 3.5 1399
## 35 JOSHUA DAVID LEE MI 3.5 1438
## 36 SIDDHARTH JHA MI 3.5 1355
## 37 AMIYATOSH PWNANANDAM MI 3.5 980
## 38 BRIAN LIU MI 3.0 1423
## 39 JOEL R HENDON MI 3.0 1436
## 40 FOREST ZHANG MI 3.0 1348
## 41 KYLE WILLIAM MURPHY MI 3.0 1403
## 42 JARED GE MI 3.0 1332
## 43 ROBERT GLEN VASEY MI 3.0 1283
## 44 JUSTIN D SCHILLING MI 3.0 1199
## 45 DEREK YAN MI 3.0 1242
## 46 JACOB ALEXANDER LAVALLEY MI 3.0 377
## 47 ERIC WRIGHT MI 2.5 1362
## 48 DANIEL KHAIN MI 2.5 1382
## 49 MICHAEL J MARTIN MI 2.5 1291
## 50 SHIVAM JHA MI 2.5 1056
## 51 TEJAS AYYAGARI MI 2.5 1011
## 52 ETHAN GUO MI 2.5 935
## 53 JOSE C YBARRA MI 2.0 1393
## 54 LARRY HODGE MI 2.0 1270
## 55 ALEX KONG MI 2.0 1186
## 56 MARISA RICCI MI 2.0 1153
## 57 MICHAEL LU MI 2.0 1092
## 58 VIRAJ MOHILE MI 2.0 917
## 59 SEAN M MC CORMICK MI 2.0 853
## 60 JULIA SHEN MI 1.5 967
## 61 JEZZEL FARKAS ON 1.5 955
## 62 ASHWIN BALAJI MI 1.0 1530
## 63 THOMAS JOSEPH HOSMER MI 1.0 1175
## 64 BEN LI MI 1.0 1163
## Average_Opponent_Pre_Rating Actual.Score Expected.Score Difference
## 1 1605 0.0 0 0.0
## 2 1469 30.0 0 30.0
## 3 1564 32.0 0 32.0
## 4 1574 33.5 0 33.5
## 5 1501 27.5 0 27.5
## 6 1519 30.0 0 30.0
## 7 1372 28.5 0 28.5
## 8 1468 22.5 0 22.5
## 9 1523 0.0 0 0.0
## 10 1554 30.0 0 30.0
## 11 1468 32.0 0 32.0
## 12 1506 33.5 0 33.5
## 13 1498 27.5 0 27.5
## 14 1515 30.0 0 30.0
## 15 1484 28.5 0 28.5
## 16 1386 22.5 0 22.5
## 17 1499 0.0 0 0.0
## 18 1480 30.0 0 30.0
## 19 1426 32.0 0 32.0
## 20 1411 33.5 0 33.5
## 21 1470 27.5 0 27.5
## 22 1300 30.0 0 30.0
## 23 1214 28.5 0 28.5
## 24 1357 22.5 0 22.5
## 25 1363 0.0 0 0.0
## 26 1507 30.0 0 30.0
## 27 1222 32.0 0 32.0
## 28 1522 33.5 0 33.5
## 29 1314 27.5 0 27.5
## 30 1144 30.0 0 30.0
## 31 1260 28.5 0 28.5
## 32 1379 22.5 0 22.5
## 33 1277 0.0 0 0.0
## 34 1375 30.0 0 30.0
## 35 1150 32.0 0 32.0
## 36 1388 33.5 0 33.5
## 37 1385 27.5 0 27.5
## 38 1539 30.0 0 30.0
## 39 1430 28.5 0 28.5
## 40 1391 22.5 0 22.5
## 41 1248 0.0 0 0.0
## 42 1150 30.0 0 30.0
## 43 1107 32.0 0 32.0
## 44 1327 33.5 0 33.5
## 45 1152 27.5 0 27.5
## 46 1358 30.0 0 30.0
## 47 1392 28.5 0 28.5
## 48 1356 22.5 0 22.5
## 49 1286 0.0 0 0.0
## 50 1296 30.0 0 30.0
## 51 1356 32.0 0 32.0
## 52 1495 33.5 0 33.5
## 53 1345 27.5 0 27.5
## 54 1206 30.0 0 30.0
## 55 1406 28.5 0 28.5
## 56 1414 22.5 0 22.5
## 57 1363 0.0 0 0.0
## 58 1391 30.0 0 30.0
## 59 1319 32.0 0 32.0
## 60 1330 33.5 0 33.5
## 61 1327 27.5 0 27.5
## 62 1186 30.0 0 30.0
## 63 1350 28.5 0 28.5
## 64 1263 22.5 0 22.5
chess_results <- chess_results %>% arrange(desc(Difference))
chess_results
## Player_Name State Total_Points Pre_Rating
## 1 PATRICK H SCHILLING MI 5.5 1716
## 2 KENNETH J TACK MI 4.5 1663
## 3 JASON ZHENG MI 4.0 1595
## 4 SOFIA ADINA STANESCU-BELLU MI 3.5 1507
## 5 SIDDHARTH JHA MI 3.5 1355
## 6 JUSTIN D SCHILLING MI 3.0 1199
## 7 ETHAN GUO MI 2.5 935
## 8 JULIA SHEN MI 1.5 967
## 9 ADITYA BAJAJ MI 6.0 1384
## 10 CAMERON WILLIAM MC LEMAN MI 4.5 1712
## 11 DIPANKAR ROY MI 4.0 1564
## 12 GAURAV GIDWANI MI 3.5 1552
## 13 JOSHUA DAVID LEE MI 3.5 1438
## 14 ROBERT GLEN VASEY MI 3.0 1283
## 15 TEJAS AYYAGARI MI 2.5 1011
## 16 SEAN M MC CORMICK MI 2.0 853
## 17 DAKSHESH DARURI MI 6.0 1553
## 18 HANSEN SONG OH 5.0 1686
## 19 ANVIT RAO MI 5.0 1365
## 20 BRADLEY SHAW MI 4.5 1610
## 21 DAVID SUNDEEN MI 4.0 1600
## 22 EUGENE L MCCLURE MI 4.0 1555
## 23 MAX ZHU ON 3.5 1579
## 24 GEORGE AVERY JONES ON 3.5 1522
## 25 MICHAEL JEFFERY THOMAS MI 3.5 1399
## 26 BRIAN LIU MI 3.0 1423
## 27 JARED GE MI 3.0 1332
## 28 JACOB ALEXANDER LAVALLEY MI 3.0 377
## 29 SHIVAM JHA MI 2.5 1056
## 30 LARRY HODGE MI 2.0 1270
## 31 VIRAJ MOHILE MI 2.0 917
## 32 ASHWIN BALAJI MI 1.0 1530
## 33 GARY DEE SWATHELL MI 5.0 1649
## 34 ZACHARY JAMES HOUGHTON MI 4.5 1220
## 35 ALAN BUI ON 4.0 1363
## 36 RISHI SHETTY MI 3.5 1494
## 37 JOEL R HENDON MI 3.0 1436
## 38 ERIC WRIGHT MI 2.5 1362
## 39 ALEX KONG MI 2.0 1186
## 40 THOMAS JOSEPH HOSMER MI 1.0 1175
## 41 HANSHI ZUO MI 5.5 1655
## 42 TORRANCE HENRY JR MI 4.5 1666
## 43 DINH DANG BUI ON 4.0 1563
## 44 CHIEDOZIE OKORIE MI 3.5 1602
## 45 AMIYATOSH PWNANANDAM MI 3.5 980
## 46 DEREK YAN MI 3.0 1242
## 47 JOSE C YBARRA MI 2.0 1393
## 48 JEZZEL FARKAS ON 1.5 955
## 49 EZEKIEL HOUGHTON MI 5.0 1641
## 50 MIKE NIKITIN MI 4.0 1604
## 51 MICHAEL R ALDRICH MI 4.0 1229
## 52 JOSHUA PHILIP MATHEWS ON 3.5 1441
## 53 FOREST ZHANG MI 3.0 1348
## 54 DANIEL KHAIN MI 2.5 1382
## 55 MARISA RICCI MI 2.0 1153
## 56 BEN LI MI 1.0 1163
## 57 GARY HUA ON 6.0 1794
## 58 STEFANO LEE ON 5.0 1411
## 59 RONALD GRZEGORCZYK MI 4.0 1629
## 60 LOREN SCHWIEBERT MI 3.5 1745
## 61 JADE GE MI 3.5 1449
## 62 KYLE WILLIAM MURPHY MI 3.0 1403
## 63 MICHAEL J MARTIN MI 2.5 1291
## 64 MICHAEL LU MI 2.0 1092
## Average_Opponent_Pre_Rating Actual.Score Expected.Score Difference
## 1 1574 33.5 0 33.5
## 2 1506 33.5 0 33.5
## 3 1411 33.5 0 33.5
## 4 1522 33.5 0 33.5
## 5 1388 33.5 0 33.5
## 6 1327 33.5 0 33.5
## 7 1495 33.5 0 33.5
## 8 1330 33.5 0 33.5
## 9 1564 32.0 0 32.0
## 10 1468 32.0 0 32.0
## 11 1426 32.0 0 32.0
## 12 1222 32.0 0 32.0
## 13 1150 32.0 0 32.0
## 14 1107 32.0 0 32.0
## 15 1356 32.0 0 32.0
## 16 1319 32.0 0 32.0
## 17 1469 30.0 0 30.0
## 18 1519 30.0 0 30.0
## 19 1554 30.0 0 30.0
## 20 1515 30.0 0 30.0
## 21 1480 30.0 0 30.0
## 22 1300 30.0 0 30.0
## 23 1507 30.0 0 30.0
## 24 1144 30.0 0 30.0
## 25 1375 30.0 0 30.0
## 26 1539 30.0 0 30.0
## 27 1150 30.0 0 30.0
## 28 1358 30.0 0 30.0
## 29 1296 30.0 0 30.0
## 30 1206 30.0 0 30.0
## 31 1391 30.0 0 30.0
## 32 1186 30.0 0 30.0
## 33 1372 28.5 0 28.5
## 34 1484 28.5 0 28.5
## 35 1214 28.5 0 28.5
## 36 1260 28.5 0 28.5
## 37 1430 28.5 0 28.5
## 38 1392 28.5 0 28.5
## 39 1406 28.5 0 28.5
## 40 1350 28.5 0 28.5
## 41 1501 27.5 0 27.5
## 42 1498 27.5 0 27.5
## 43 1470 27.5 0 27.5
## 44 1314 27.5 0 27.5
## 45 1385 27.5 0 27.5
## 46 1152 27.5 0 27.5
## 47 1345 27.5 0 27.5
## 48 1327 27.5 0 27.5
## 49 1468 22.5 0 22.5
## 50 1386 22.5 0 22.5
## 51 1357 22.5 0 22.5
## 52 1379 22.5 0 22.5
## 53 1391 22.5 0 22.5
## 54 1356 22.5 0 22.5
## 55 1414 22.5 0 22.5
## 56 1263 22.5 0 22.5
## 57 1605 0.0 0 0.0
## 58 1523 0.0 0 0.0
## 59 1499 0.0 0 0.0
## 60 1363 0.0 0 0.0
## 61 1277 0.0 0 0.0
## 62 1248 0.0 0 0.0
## 63 1286 0.0 0 0.0
## 64 1363 0.0 0 0.0
The 5 players with the largest difference (over performed): Aditya
Bajaj, Zachary James Hought, Anvit Rao, Jacob Alexander, Stefano
Lee
The 5 players with the smallest difference (under performed):
chess_results <- chess_results %>% arrange(Difference)
chess_results
## Player_Name State Total_Points Pre_Rating
## 1 GARY HUA ON 6.0 1794
## 2 STEFANO LEE ON 5.0 1411
## 3 RONALD GRZEGORCZYK MI 4.0 1629
## 4 LOREN SCHWIEBERT MI 3.5 1745
## 5 JADE GE MI 3.5 1449
## 6 KYLE WILLIAM MURPHY MI 3.0 1403
## 7 MICHAEL J MARTIN MI 2.5 1291
## 8 MICHAEL LU MI 2.0 1092
## 9 EZEKIEL HOUGHTON MI 5.0 1641
## 10 MIKE NIKITIN MI 4.0 1604
## 11 MICHAEL R ALDRICH MI 4.0 1229
## 12 JOSHUA PHILIP MATHEWS ON 3.5 1441
## 13 FOREST ZHANG MI 3.0 1348
## 14 DANIEL KHAIN MI 2.5 1382
## 15 MARISA RICCI MI 2.0 1153
## 16 BEN LI MI 1.0 1163
## 17 HANSHI ZUO MI 5.5 1655
## 18 TORRANCE HENRY JR MI 4.5 1666
## 19 DINH DANG BUI ON 4.0 1563
## 20 CHIEDOZIE OKORIE MI 3.5 1602
## 21 AMIYATOSH PWNANANDAM MI 3.5 980
## 22 DEREK YAN MI 3.0 1242
## 23 JOSE C YBARRA MI 2.0 1393
## 24 JEZZEL FARKAS ON 1.5 955
## 25 GARY DEE SWATHELL MI 5.0 1649
## 26 ZACHARY JAMES HOUGHTON MI 4.5 1220
## 27 ALAN BUI ON 4.0 1363
## 28 RISHI SHETTY MI 3.5 1494
## 29 JOEL R HENDON MI 3.0 1436
## 30 ERIC WRIGHT MI 2.5 1362
## 31 ALEX KONG MI 2.0 1186
## 32 THOMAS JOSEPH HOSMER MI 1.0 1175
## 33 DAKSHESH DARURI MI 6.0 1553
## 34 HANSEN SONG OH 5.0 1686
## 35 ANVIT RAO MI 5.0 1365
## 36 BRADLEY SHAW MI 4.5 1610
## 37 DAVID SUNDEEN MI 4.0 1600
## 38 EUGENE L MCCLURE MI 4.0 1555
## 39 MAX ZHU ON 3.5 1579
## 40 GEORGE AVERY JONES ON 3.5 1522
## 41 MICHAEL JEFFERY THOMAS MI 3.5 1399
## 42 BRIAN LIU MI 3.0 1423
## 43 JARED GE MI 3.0 1332
## 44 JACOB ALEXANDER LAVALLEY MI 3.0 377
## 45 SHIVAM JHA MI 2.5 1056
## 46 LARRY HODGE MI 2.0 1270
## 47 VIRAJ MOHILE MI 2.0 917
## 48 ASHWIN BALAJI MI 1.0 1530
## 49 ADITYA BAJAJ MI 6.0 1384
## 50 CAMERON WILLIAM MC LEMAN MI 4.5 1712
## 51 DIPANKAR ROY MI 4.0 1564
## 52 GAURAV GIDWANI MI 3.5 1552
## 53 JOSHUA DAVID LEE MI 3.5 1438
## 54 ROBERT GLEN VASEY MI 3.0 1283
## 55 TEJAS AYYAGARI MI 2.5 1011
## 56 SEAN M MC CORMICK MI 2.0 853
## 57 PATRICK H SCHILLING MI 5.5 1716
## 58 KENNETH J TACK MI 4.5 1663
## 59 JASON ZHENG MI 4.0 1595
## 60 SOFIA ADINA STANESCU-BELLU MI 3.5 1507
## 61 SIDDHARTH JHA MI 3.5 1355
## 62 JUSTIN D SCHILLING MI 3.0 1199
## 63 ETHAN GUO MI 2.5 935
## 64 JULIA SHEN MI 1.5 967
## Average_Opponent_Pre_Rating Actual.Score Expected.Score Difference
## 1 1605 0.0 0 0.0
## 2 1523 0.0 0 0.0
## 3 1499 0.0 0 0.0
## 4 1363 0.0 0 0.0
## 5 1277 0.0 0 0.0
## 6 1248 0.0 0 0.0
## 7 1286 0.0 0 0.0
## 8 1363 0.0 0 0.0
## 9 1468 22.5 0 22.5
## 10 1386 22.5 0 22.5
## 11 1357 22.5 0 22.5
## 12 1379 22.5 0 22.5
## 13 1391 22.5 0 22.5
## 14 1356 22.5 0 22.5
## 15 1414 22.5 0 22.5
## 16 1263 22.5 0 22.5
## 17 1501 27.5 0 27.5
## 18 1498 27.5 0 27.5
## 19 1470 27.5 0 27.5
## 20 1314 27.5 0 27.5
## 21 1385 27.5 0 27.5
## 22 1152 27.5 0 27.5
## 23 1345 27.5 0 27.5
## 24 1327 27.5 0 27.5
## 25 1372 28.5 0 28.5
## 26 1484 28.5 0 28.5
## 27 1214 28.5 0 28.5
## 28 1260 28.5 0 28.5
## 29 1430 28.5 0 28.5
## 30 1392 28.5 0 28.5
## 31 1406 28.5 0 28.5
## 32 1350 28.5 0 28.5
## 33 1469 30.0 0 30.0
## 34 1519 30.0 0 30.0
## 35 1554 30.0 0 30.0
## 36 1515 30.0 0 30.0
## 37 1480 30.0 0 30.0
## 38 1300 30.0 0 30.0
## 39 1507 30.0 0 30.0
## 40 1144 30.0 0 30.0
## 41 1375 30.0 0 30.0
## 42 1539 30.0 0 30.0
## 43 1150 30.0 0 30.0
## 44 1358 30.0 0 30.0
## 45 1296 30.0 0 30.0
## 46 1206 30.0 0 30.0
## 47 1391 30.0 0 30.0
## 48 1186 30.0 0 30.0
## 49 1564 32.0 0 32.0
## 50 1468 32.0 0 32.0
## 51 1426 32.0 0 32.0
## 52 1222 32.0 0 32.0
## 53 1150 32.0 0 32.0
## 54 1107 32.0 0 32.0
## 55 1356 32.0 0 32.0
## 56 1319 32.0 0 32.0
## 57 1574 33.5 0 33.5
## 58 1506 33.5 0 33.5
## 59 1411 33.5 0 33.5
## 60 1522 33.5 0 33.5
## 61 1388 33.5 0 33.5
## 62 1327 33.5 0 33.5
## 63 1495 33.5 0 33.5
## 64 1330 33.5 0 33.5
The 5 players with the smallest difference (under performed): Loren Schwiebert, George Avery Jones, Larry Hodge, Jared Ge and Rishi Shetty
As anticipated I could use parts of my code to help perform my analysis. However, I ended up going back an adjusting the generated Project 1 code, to export 2 other csv files, one containing the opponent data and another containing the results for each round for every tournament participant. This ended up being the most difficult part of completing the lab, as I did not dedicate adequate time during the Approach to figure out what information would be necessary from Project 1 to best complete this lab. If I had more time to continue working on this project, I would consider finding a way to include all this information in one data frame (something likely resembling the original txt file) and adjust my functions accordingly. I believe that this would make my code ultimately, simpler and more readable.
GeeksforGeeks. (n.d.). Elo rating algorithm. GeeksforGeeks. https://www.geeksforgeeks.org/dsa/elo-rating-algorithm/