<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Adrien Peltzer on Medium]]></title>
        <description><![CDATA[Stories by Adrien Peltzer on Medium]]></description>
        <link>https://medium.com/@adrienpeltzer_17089?source=rss-5667a28f795b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*cXQU3CaD6GaO1FtFt98F_A.jpeg</url>
            <title>Stories by Adrien Peltzer on Medium</title>
            <link>https://medium.com/@adrienpeltzer_17089?source=rss-5667a28f795b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 25 Nov 2026 01:45:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@adrienpeltzer_17089/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Extending an example from Ross’s “A First Course in Probability”]]></title>
            <link>https://medium.com/@adrienpeltzer_17089/extending-an-example-a-a-first-course-in-probability-57b24d14a197?source=rss-5667a28f795b------2</link>
            <guid isPermaLink="false">https://medium.com/p/57b24d14a197</guid>
            <dc:creator><![CDATA[Adrien Peltzer]]></dc:creator>
            <pubDate>Sun, 16 Nov 2025 01:03:09 GMT</pubDate>
            <atom:updated>2025-11-16T03:34:00.506Z</atom:updated>
            <content:encoded><![CDATA[<h3>Extending an example from Sheldon Ross’s “<em>A First Course in Probability”</em></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*TckSdk3ozYtUemp0EYwhvQ.jpeg" /></figure><p>As a gradute student TA, I really enjoyed working out of <a href="https://en.wikipedia.org/wiki/Sheldon_M._Ross"><em>Sheldon Ross</em></a>’s textbook <em>*A First Course in Probability*</em> (8th edition). It was filled with many real-world examples. One example, notable for a gamer like me, was found in <strong>Section 7.5</strong> on Conditional Expectation. It calculates the average number of rolls in a round of <a href="https://en.wikipedia.org/wiki/Craps"><strong>C<em>raps</em></strong></a>, a classical dice game found in almost all Las Vegas casino floors. Here is the problem:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/1*m-a_tgrMscigdFbVXsSzXw.png" /></figure><p>The textbook leads to the conclusion that the expected number rolls is around <strong>3.376. </strong>The point here is not to explain the math, but to tweak the setup of the problem to make it match the true number of rolls one would expect to have in a turn of Craps. In Las Vegas Casinos, a shooter gets to keep rolling until they <strong>“seven out”</strong>. That is, it is only when they set a number and subsequently roll a <strong>7</strong> before re-rolling that set number that the dice are finally passed to the next person at the table.</p><p><strong>Method 1: </strong>Hand Calculations</p><p>By using <a href="https://www.google.com/search?client=safari&amp;rls=en&amp;q=conditional+expwectation&amp;ie=UTF-8&amp;oe=UTF-8">conditional expectation</a><em>, </em>I arrived at a formula that looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*bynC9AKKqYhxrwLx01DKXQ.png" /></figure><p>Here, “R” represents the number of rolls, “E[R]” stands for “expectation of R”, and “P_i” represents the probability of rolling a sum of “i”. This gives a result of:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/249/1*5bnN7AiMlUsb11muDBf59g.png" /></figure><p><strong>Method 2: </strong>Simulating</p><p>A simulated version of this could be written as follows:</p><pre>import random<br><br>def simulate_shooter():<br>    &quot;&quot;&quot;Simulate one shooter&#39;s turn. Return total rolls until seven-out.&quot;&quot;&quot;<br>    rolls = 0<br>    <br>    while True:<br>        # Come-out roll<br>        rolls += 1<br>        d1, d2 = random.randint(1,6), random.randint(1,6)<br>        total = d1 + d2<br>        <br>        # Natural or craps: shooter continues with a new come-out<br>        if total in (7, 11, 2, 3, 12):<br>            continue<br>        <br>        # Point established<br>        point = total<br>        <br>        while True:<br>            rolls += 1<br>            d1, d2 = random.randint(1,6), random.randint(1,6)<br>            t = d1 + d2<br>            <br>            if t == 7:<br>                # Seven-out ends the shooter&#39;s turn<br>                return rolls<br>            <br>            if t == point:<br>                # Point made → new come-out roll<br>                break<br><br><br>def estimate_expected_rolls(n_trials=1_000_000):<br>    total = 0<br>    for _ in range(n_trials):<br>        total += simulate_shooter()<br>    return total / n_trials<br><br><br>if __name__ == &quot;__main__&quot;:<br>    est = estimate_expected_rolls(200_000)  # Use 1–5M for more accuracy<br>    print(&quot;Estimated expected rolls per shooter:&quot;, est)</pre><p>When running this locally, I get the following out put:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/869/1*_2UcUz4f3sMyYXiZkg_SpQ.png" /></figure><p><strong>Conclusion: </strong>I’ve played about 20–30 hours of Craps in my life; enough to know the rules and to get a good sense of how long it takes for the dice to be passed on to the next player. To know that rolling only <strong><em>9</em></strong> times or more in a turn is better than average makes me feel better about those turns where I felt I let the table down. It’s a thrilling game, but the thrill is ephemeral. The house always wins.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57b24d14a197" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The effect of winning an NBA game at the buzzer]]></title>
            <link>https://medium.com/@adrienpeltzer_17089/the-effect-of-winning-an-nba-game-at-the-buzzer-93f087ce2200?source=rss-5667a28f795b------2</link>
            <guid isPermaLink="false">https://medium.com/p/93f087ce2200</guid>
            <dc:creator><![CDATA[Adrien Peltzer]]></dc:creator>
            <pubDate>Mon, 10 Nov 2025 23:57:53 GMT</pubDate>
            <atom:updated>2025-12-04T00:10:15.381Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Is there a let-down effect from making a game-winning buzzer-beater?</strong></h3><p>On Basketball Reference, you can find a <a href="https://www.basketball-reference.com/friv/buzzer-beaters.html">complete list</a> of all game-winning buzzer beaters in NBA history. We’ve seen three so far this season, including a <a href="https://www.youtube.com/watch?v=IbbOxW8jOzc">Kobe-esque fadeaway</a> buzzer beater by <a href="https://youtu.be/pFfmzpxQNLw?si=ss_t_YVs1kq3BqP2&amp;t=987">Giannis Antetokounmpo</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*cI1bG3is8Q7cH3OJiHqSwA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oR-JOVgdhyKs2RW1uxCN0w.jpeg" /></figure><p>With these games in mind, I wanted to see whether there was a let-down effect following such an emotional victory. The question to answer: do teams perform less well following a game — winning buzzer beater?</p><p><strong>Null hypothesis</strong>: Winning a game at the buzzer has no effect on the outcome of the team’s next game.</p><p><strong>Alternative Hypothesis</strong>: A team’s chances of winning it’s next game goes down after a game-winning buzzer beater.</p><p>Overall, teams are <strong>421–427</strong> in the game immediately following a buzzer beater. Teams are <strong>399–392</strong> in the regular season, and <strong>22–35</strong> in the playoffs in this situation. However, in recent years teams have been performing <strong><em>substantially worse</em></strong> after a buzzer beating game. Since <strong>2022–23</strong>, teams are <strong>13–30</strong> in the regular season following a buzzer beater, and <strong>2–1</strong> in the playoffs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*gPGlIhWJMSNW_GVbmM3sjg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*7ID1XOLq0EZH6BlT-X_U7w.png" /></figure><p>The corresponding regular season z-score here is <strong>-2.59</strong>, which roughly equates to a <strong>0.5%</strong> chance of occurring under the null hypothesis. <em>Even a </em><strong><em>99%</em></strong><em> threshold</em> would reject <strong>H0</strong> here. So the results do suggest that, at least recently, there is a noticeable drop in performance in the game following a buzzer beating win. Whether this is due to a let-down effect, or simply a managerial decision to take the night off is hard to say.</p><p><strong>A storied example:</strong></p><p>One example that comes to mind is Josh Giddey’s<a href="https://www.google.com/url?sa=t&amp;source=web&amp;rct=j&amp;opi=89978449&amp;url=https://www.youtube.com/watch%3Fv%3DEAn7-VVIECs&amp;ved=2ahUKEwjyt-jb0aKRAxVjDTQIHT_lNpcQtwJ6BAgSEAI&amp;usg=AOvVaw3tJP19Z-8PMXMVsTTGyBnj"> half court heave</a> to win the game against the Lakers in March of 2024. The following game, the Bulls lost at home to a Dallas Mavericks team, even in a game they were favored to win.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZUgaq21f9RGGqUmXhFM5Zw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I8vK5Sj3IQdo9lSR-8jPNg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93f087ce2200" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Dopamine Dump Theory]]></title>
            <link>https://medium.com/@adrienpeltzer_17089/the-dopamine-dump-theory-e817d7cfdfcf?source=rss-5667a28f795b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e817d7cfdfcf</guid>
            <dc:creator><![CDATA[Adrien Peltzer]]></dc:creator>
            <pubDate>Wed, 05 Nov 2025 18:53:56 GMT</pubDate>
            <atom:updated>2025-11-05T19:29:17.356Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*ZlaFbEI4wyY9aRqvKjef6A.png" /></figure><p>My brother and I like to bet on the NBA. Yes we are degenerates, but it is also fun to forecast sports, find edges, and make predictions. I also like to slice data. With that said, let’s talk about the <em>Dopamine Dump Theory. </em>The theory is that, when one team wins a close game the night before, they tend to lose the next game. The naming comes from the idea that you have a temporary high from winning and the next game is kind of a let-down game (shout out to the <a href="https://www.youtube.com/watch?v=BUPT5r5P7os&amp;t=1943s"><strong>Great Western Podcast</strong></a> for coining the term).</p><p>Let’s test our theory by running numbers on how such a team performs <strong>against the spread</strong> and <strong>straight up</strong> in the previous years. To define <em>winning a close game</em>, I choose a game that finishes with a team winning by 1 to 5 points. Teams that just won such a close game win at a 39% rate the next night versus 44% for a team simply on a back to back. Let’s now see how this performs against the spread when we <em>bet against</em> a team in this situation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*-xhvBDESVcWG9zYsFKxewg.png" /></figure><p>Following this theory, your ROI against the spread is 8.04%, and 4.61% on the moneyline. Not bad for a sample size of 457 (the data goes back to 2016–17). Let’s now run it by season:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*owPBQ_aSPMcV6ylDoh88ow.png" /></figure><p>This season is off to a good start. Let’s look at who would have won us some money in this season so far.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hhVngITXPvhjc2WjQVAIMA.png" /></figure><p>If you watched Giannis’ recent <a href="https://www.google.com/url?sa=t&amp;source=web&amp;rct=j&amp;opi=89978449&amp;url=https://www.youtube.com/watch%3Fv%3DxpW8zVsEbO8&amp;ved=2ahUKEwjPt7nv29uQAxXSHjQIHSy1F7QQtwJ6BAgPEAI&amp;usg=AOvVaw2PRpBgYy9ORfqO3dZ0MoDW"><em>Game Winner</em></a> against the Pacers, you would have seen an emotionally charged team in the Bucks that was happy to take down a Pacers team that took them out of the playoffs the season prior. Little do you know, the dopamine dump occurs, and the Raptors steamroll their way to an easy victory the following day against the Milwaukee Bucks... Now I am not saying this theory is bullet-proof, but the stats don’t lie. Rockin’ with this theory, we can <strong>Fade the Pelicans</strong> tonight against the <strong>Mavericks</strong>. If history repeats itself, your bet should return you a decent profit.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e817d7cfdfcf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MLB Pitchers — Pitch Speed versus Pitch Count]]></title>
            <link>https://medium.com/@adrienpeltzer_17089/mlb-pitchers-pitch-speed-versus-pitch-count-c2937ecbf061?source=rss-5667a28f795b------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2937ecbf061</guid>
            <dc:creator><![CDATA[Adrien Peltzer]]></dc:creator>
            <pubDate>Thu, 12 Jun 2025 22:56:12 GMT</pubDate>
            <atom:updated>2025-06-12T22:56:12.471Z</atom:updated>
            <content:encoded><![CDATA[<h3>MLB Pitchers — Pitch Speed versus Pitch Count</h3><p>Using a <a href="https://github.com/toddrob99/MLB-StatsAPI">python wrapper</a> for MLB stats, I was able to answer a question of mine: How do pitch speeds correlate with pitch count?</p><p>The longer a pitcher stays in the game, the slower his average pitch speed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AFF0RZ2g-0atxJMfPHDBwg.jpeg" /></figure><p>To explain how I found the data, I used ChatGPT (pasted below for informational purposes)</p><pre>import statsapi<br><br># Define the season year<br>season_year = 2025<br><br># Define the start and end dates for the season<br>start_date = f&#39;03/18/{season_year}&#39;<br>end_date = f&#39;05/31/{season_year}&#39;<br><br># Retrieve the schedule<br>schedule = statsapi.schedule(start_date=start_date, end_date=end_date, sportId=1)<br><br># Display the number of games retrieved<br>print(f&quot;Total games retrieved for {season_year}: {len(schedule)}&quot;)<br><br><br><br><br><br># Extract gamePk values from the schedule<br>game_pks = [game[&#39;game_id&#39;] for game in schedule]<br><br><br># Example: Retrieve play-by-play data for the first game<br>first_game_pk = game_pks[-1]<br>play_by_play_data = statsapi.get(&#39;game_playByPlay&#39;, {&#39;gamePk&#39;: first_game_pk})<br><br># Display some information from the play-by-play data<br>print(play_by_play_data[&#39;allPlays&#39;][0])  # First play of the game<br><br><br><br><br><br>def extract_pitches_from_game(game_id):<br>    try:<br>        pbp = statsapi.get(&#39;game_playByPlay&#39;, {&#39;gamePk&#39;: game_id})<br>        game_info = statsapi.get(&#39;game&#39;, {&#39;gamePk&#39;: game_id})<br>        boxscore = statsapi.get(&#39;game_boxscore&#39;, {&#39;gamePk&#39;: game_id})<br><br>        all_plays = pbp[&#39;allPlays&#39;]<br>        game_date = game_info[&#39;gameData&#39;][&#39;datetime&#39;][&#39;originalDate&#39;]<br>        home_team = game_info[&#39;gameData&#39;][&#39;teams&#39;][&#39;home&#39;][&#39;name&#39;]<br>        away_team = game_info[&#39;gameData&#39;][&#39;teams&#39;][&#39;away&#39;][&#39;name&#39;]<br><br>        home_starter_id = boxscore[&#39;teams&#39;][&#39;home&#39;][&#39;pitchers&#39;][0] if boxscore[&#39;teams&#39;][&#39;home&#39;][&#39;pitchers&#39;] else None<br>        away_starter_id = boxscore[&#39;teams&#39;][&#39;away&#39;][&#39;pitchers&#39;][0] if boxscore[&#39;teams&#39;][&#39;away&#39;][&#39;pitchers&#39;] else None<br><br>        rows = []<br>        pitch_counts = {}<br><br>        for play in all_plays:<br>            play_events = play.get(&#39;playEvents&#39;, [])<br>            matchup = play.get(&#39;matchup&#39;, {})<br>            pitcher = matchup.get(&#39;pitcher&#39;, {})<br>            pitcher_id = pitcher.get(&#39;id&#39;)<br>            pitcher_name = pitcher.get(&#39;fullName&#39;)<br>            pitcher_team = matchup.get(&#39;pitcherTeam&#39;, {}).get(&#39;name&#39;)<br>            batter_team = away_team if pitcher_team == home_team else home_team<br><br>            is_starter = pitcher_id in {home_starter_id, away_starter_id}<br>            pitcher_hand = matchup.get(&#39;pitchHand&#39;, {}).get(&#39;code&#39;)  # &#39;R&#39; or &#39;L&#39;<br>            batter_hand = matchup.get(&#39;batSide&#39;, {}).get(&#39;code&#39;)     # &#39;R&#39; or &#39;L&#39;<br><br>            inning = play.get(&#39;about&#39;, {}).get(&#39;inning&#39;)<br>            half_inning = play.get(&#39;about&#39;, {}).get(&#39;halfInning&#39;)<br>            runs_home = play.get(&#39;result&#39;, {}).get(&#39;homeScore&#39;)<br>            runs_away = play.get(&#39;result&#39;, {}).get(&#39;awayScore&#39;)<br><br>            # Determine base occupancy<br>            on_1b = on_2b = on_3b = False<br>            for runner in play.get(&#39;runners&#39;, []):<br>                end_base = runner.get(&#39;movement&#39;, {}).get(&#39;end&#39;)<br>                if end_base == &#39;1B&#39;:<br>                    on_1b = True<br>                elif end_base == &#39;2B&#39;:<br>                    on_2b = True<br>                elif end_base == &#39;3B&#39;:<br>                    on_3b = True<br><br>            if pitcher_id not in pitch_counts:<br>                pitch_counts[pitcher_id] = 0<br><br>            for event in play_events:<br>                if event.get(&#39;isPitch&#39;) and &#39;pitchData&#39; in event:<br>                    pitch_data = event[&#39;pitchData&#39;]<br>                    pitch_details = event.get(&#39;details&#39;, {})<br>                    pitch_type = pitch_details.get(&#39;type&#39;, {}).get(&#39;code&#39;)<br>                    pitch_desc = pitch_details.get(&#39;type&#39;, {}).get(&#39;description&#39;)<br>                    pitch_outcome = pitch_details.get(&#39;description&#39;)<br>                    pitch_number = event.get(&#39;pitchNumber&#39;)<br>                    pitch_count = event.get(&#39;count&#39;, {})<br><br>                    pitch_counts[pitcher_id] += 1<br>                    pitcher_total_pitch_number = pitch_counts[pitcher_id]<br><br>                    rows.append({<br>                        &#39;game_id&#39;: game_id,<br>                        &#39;game_date&#39;: game_date,<br>                        &#39;pitcher_id&#39;: pitcher_id,<br>                        &#39;pitcher_name&#39;: pitcher_name,<br>                        &#39;pitcher_team&#39;: pitcher_team,<br>                        &#39;batter_team&#39;: batter_team,<br>                        &#39;is_starter&#39;: is_starter,<br>                        &#39;pitcher_hand&#39;: pitcher_hand,<br>                        &#39;batter_hand&#39;: batter_hand,<br>                        &#39;inning&#39;: inning,<br>                        &#39;half_inning&#39;: half_inning,<br>                        &#39;runs_home&#39;: runs_home,<br>                        &#39;runs_away&#39;: runs_away,<br>                        &#39;on_1b&#39;: on_1b,<br>                        &#39;on_2b&#39;: on_2b,<br>                        &#39;on_3b&#39;: on_3b,<br>                        &#39;pitch_type&#39;: pitch_type,<br>                        &#39;pitch_desc&#39;: pitch_desc,<br>                        &#39;pitch_outcome&#39;: pitch_outcome,<br>                        &#39;start_speed&#39;: pitch_data.get(&#39;startSpeed&#39;),<br>                        &#39;end_speed&#39;: pitch_data.get(&#39;endSpeed&#39;),<br>                        &#39;pitch_number&#39;: pitch_number,<br>                        &#39;pitcher_total_pitch_number&#39;: pitcher_total_pitch_number,<br>                        &#39;balls&#39;: pitch_count.get(&#39;balls&#39;),<br>                        &#39;strikes&#39;: pitch_count.get(&#39;strikes&#39;),<br>                        &#39;outs&#39;: pitch_count.get(&#39;outs&#39;)<br>                    })<br><br>        return pd.DataFrame(rows)<br><br>    except Exception as e:<br>        print(f&quot;Error with game {game_id}: {e}&quot;)<br>        return pd.DataFrame()<br><br><br><br><br><br><br>import sqlite3<br><br># Create or connect to SQLite database file<br>conn = sqlite3.connect(&quot;mlb_pitch_data.sqlite&quot;)<br><br># You can use this cursor to execute SQL if needed<br>cursor = conn.cursor()<br><br><br><br><br><br>import time<br><br>start_date = &#39;03/18/2025&#39;<br>end_date = &#39;05/31/2025&#39;<br><br># Step 1: Get list of games in a season<br>schedule = statsapi.schedule(start_date=start_date, end_date=end_date, sportId=1)<br>game_ids = [g[&#39;game_id&#39;] for g in schedule]<br><br># Step 2: Loop through game IDs and store pitch data<br>for gid in game_ids:<br>    df = extract_pitches_from_game(gid)<br><br>    if not df.empty:<br>        try:<br>            # Save to SQLite: append mode, don&#39;t write index<br>            df.to_sql(&quot;pitch_data&quot;, conn, if_exists=&#39;append&#39;, index=False)<br>            print(f&quot;Saved game {gid} with {len(df)} pitches.&quot;)<br>        except Exception as e:<br>            print(f&quot;Failed to save game {gid}: {e}&quot;)<br><br>    # Optional: Delay to avoid overwhelming the API<br>    time.sleep(0.5)<br><br><br><br>import sqlite3<br>import pandas as pd<br><br>conn = sqlite3.connect(&quot;mlb_pitch_data.sqlite&quot;)<br><br>query = &quot;&quot;&quot;<br>SELECT pitcher_id, pitcher_name, pitcher_total_pitch_number, start_speed<br>FROM pitch_data<br>WHERE start_speed IS NOT NULL AND pitcher_total_pitch_number IS NOT NULL<br>ORDER BY pitcher_id, pitcher_total_pitch_number<br>&quot;&quot;&quot;<br><br>df = pd.read_sql(query, conn)<br><br><br>import matplotlib.pyplot as plt<br><br># Bin pitch numbers<br>df[&#39;pitch_bin&#39;] = (df[&#39;pitcher_total_pitch_number&#39;] // 10) * 10<br><br><br>df_no_outliers = df[df[&#39;pitch_bin&#39;]&lt;=90]<br><br># Average speed by bin<br>grouped = df_no_outliers.groupby(&#39;pitch_bin&#39;)[&#39;start_speed&#39;].mean().reset_index()<br><br># Plot<br>plt.figure(figsize=(10, 5))<br>plt.plot(grouped[&#39;pitch_bin&#39;], grouped[&#39;start_speed&#39;], marker=&#39;o&#39;)<br>plt.xlabel(&#39;Pitch Number (binned by 10)&#39;)<br>plt.ylabel(&#39;Average Start Speed (mph)&#39;)<br>plt.title(&#39;Average Pitch Speed vs Pitch Count&#39;)<br>plt.grid(True)<br>plt.show(block=False)<br>#plt.savefig(&quot;pitchspeed_vs_pitchcount.pdf&quot;)<br><br>conn.close()</pre><p>There are several articles on related topics (see <a href="https://fivethirtyeight.com/features/pitchers-are-slowing-down-to-speed-up/">here</a> and <a href="https://www.reddit.com/r/mlb/comments/1joxykw/are_starting_pitchers_suddenly_throwing/">here</a>).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2937ecbf061" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The role of a UC Lecturer: academic job titles and compensation]]></title>
            <link>https://medium.com/@adrienpeltzer_17089/the-role-of-a-uc-lecturer-academic-job-titles-and-compensation-8be495a4877f?source=rss-5667a28f795b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8be495a4877f</guid>
            <dc:creator><![CDATA[Adrien Peltzer]]></dc:creator>
            <pubDate>Tue, 13 May 2025 19:40:25 GMT</pubDate>
            <atom:updated>2025-05-14T18:45:13.146Z</atom:updated>
            <content:encoded><![CDATA[<p>Working as Lecturer and PhD student the last ten years in Mathematics departments within the UC system, I have experienced how students perceive Lecturers versus Professors (they think they have the same job), and what the University expects out of both (they expect the same teaching quality, but with different workloads).</p><p>Compensation reporting is <a href="https://ucannualwage.ucop.edu/wage/">publicly available</a>, and before a recent added layer of security I was able to parse the backend json file from the api that runs the website. I have the years 2012 through 2021 for all 9 UC campuses (UCSF not included).</p><p>Here is a slice of our data:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qjK7iDy4cqA9T3CM87FIjg.png" /></figure><p>The dataset is not clean. For example, the job titles change from year to year, and there is no employee ID (if an employee undergoes a title or name change, I cannot match them on Employee ID for different years). With that said, let’s visualize some of the data in our dataset.</p><p><strong>Average Number of Years in DataSet:</strong></p><p>After making a brief grouping of jobs that have similar job titles (e.g. if ‘LECT’ is in the Job Title, then I categorize this as part of the ‘Lecturer’ group) I make a bar chart representing the <em>average number of years</em> each unique employee is in the dataset. I do this by grouping by <strong>FirstName</strong>,<strong> LastName</strong>,<strong> </strong>and <strong>Location</strong>. Keep in mind that it is not <em>perfect. </em>As mentioned above, some employees may change names, and also I am limited to the years 2012 to 2020.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/989/1*fxbsWID6tAcOhFh62i2DzA.png" /></figure><p><strong>Average GrossPay by Job Title</strong></p><p>We see that those in ‘Professor’ category stay the longest. Let’s now look at average ‘GrossPay’ among the groups.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J7w8LNfxx-io99D46eRwxg.png" /></figure><p>The order is not the same, but the first and last groups are: ‘Professors’ make the most and stay the longest within the same campus, whereas those in the group ‘Recreation’ make the least and have the shortest stay.</p><p><strong>Comparing Lecturers and Professors</strong></p><p>As an early career Lecturer in the UC system, you can see why I am interested in this data. I also just want to figure out whether I am on the right career path. When I talk to my colleagues, they say I should find another job (the non-senate Lecturer position is known as the one that plays the role of filler). So let’s look at a histogram of salaries (GrossPay) of Lecturers versus Professors in the year 2021.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xhrNOVRs4SRNCvGX3LEY6A.png" /></figure><p>I see several details from this graph. One is that it is clear that some lecturers are hired only to fill one or two courses, and maybe only for one quarter or semester. Then there are full time Lecturers, and you can see that they are capped at about 150K/yr. The Professor Series, on the other hand, can go up to 500K/yr in gross pay (this includes regular pay and other pay, for example for research done during the summer). This data mirrors the <a href="https://www.ucop.edu/academic-personnel-programs/compensation/historic-academic-salary-scales/2020-21-academic-salary-scales.html">historical salary scales</a> for the school year 2020-21.</p><p><strong>Lecturers versus Professors: What is the difference?</strong></p><p>Let’s review a brief description found of the two job titles found <a href="https://academicpersonnel.ucmerced.edu/resources/academic-titles">here</a>.</p><p><strong>Senate Faculty (Professors):</strong></p><p>“Characteristics that distinguish appointments in these title series from other titles include:</p><ul><li>Have a permanent, state funded position (FTE)</li><li>On track to tenure or security of employment</li><li>Confer Academic Senate membership, with the associated rights and responsibilities”</li></ul><p><strong>Lecturers:</strong></p><p>“Non-Senate faculty, or Unit 18 Lecturers, provide critical instructional services to the campus. Appointees have full or partial responsibility for the instruction of approved regular University courses for campus credit. They may also perform other types of instruction-related work ... Appointees are not expected to engage in research, are not members of the Academic Senate, and may not be enrolled as a student on any UC campus…”</p><p><strong><em>Concluding Thoughts</em></strong>:</p><p>Both positions are necessary to run a research/teaching institution like the University of California. A Lecturer <em>can</em> also<em> </em>become a Teaching Professor, though it is rare. More importantly is that employees in both positions should feel valued for what they bring to the table, whether it is in the form of research or teaching.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8be495a4877f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using python’s NBA_API to look at recent Playoff history]]></title>
            <link>https://medium.com/@adrienpeltzer_17089/using-pythons-nba-api-to-look-at-recent-playoff-history-eca772e97890?source=rss-5667a28f795b------2</link>
            <guid isPermaLink="false">https://medium.com/p/eca772e97890</guid>
            <category><![CDATA[nba-playoffs]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[nba]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[data-visualization]]></category>
            <dc:creator><![CDATA[Adrien Peltzer]]></dc:creator>
            <pubDate>Tue, 06 May 2025 22:51:52 GMT</pubDate>
            <atom:updated>2025-05-06T22:51:52.283Z</atom:updated>
            <content:encoded><![CDATA[<p>The python package I use most often for NBA data is a python wrapper called <a href="https://github.com/swar/nba_api"><strong><em>nba_api</em></strong></a>. There is also a slack channel for it with many helpful users.</p><p>Here, I will go over how I use the <a href="https://github.com/swar/nba_api/blob/master/docs/nba_api/stats/endpoints/teamgamelogs.md">TeamGameLogs</a> endpoint, and how I transofrm the data to make it meaningful. You can see the full notebook <a href="https://github.com/apelt001/Data-Analysis---NBA/blob/main/playoffs%20-%20tutorial/code.ipynb"><strong><em>here</em></strong></a>.</p><p>Let’s compare how often the team with home court advantage wins based on the game number in the series.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*xhk2RwsbZDu6C6OzCZYKXw.png" /><figcaption>The game by game winning percentage of the team with home court advantage</figcaption></figure><p>We can see that home court has been less advantageous in recent years (recall that games 3,4, and 6 are played on the road). Let’s talk about the data pre-processing needed to make this chart.</p><p><strong>Step 1</strong>: import libraries</p><pre>import nba_api.stats.endpoints as nba<br>import pandas as pd<br>import time<br>from nba_api.stats.static import teams</pre><p><strong>Step 2</strong>: pull the data for all seasons 1996–97 through 2024–25</p><pre>def get_game_log(season,measure_type=&quot;Base&quot;,stype = &quot;Playoffs&quot;,location = None):<br> df = nba.TeamGameLogs(season_nullable=season,location_nullable = location,measure_type_player_game_logs_nullable=measure_type,season_type_nullable = stype).get_data_frames()[0]<br> df = df.rename(columns = {&quot;SEASON_YEAR&quot;:&quot;season&quot;,&quot;TEAM_ABBREVIATION&quot;:&quot;team&quot;,&quot;GAME_DATE&quot;:&quot;date&quot;})<br> return df<br><br>seasons = [str(i)+&#39;-&#39;+str(i+1)[2:] for i in range(1996,2025)]<br>season = seasons[0]<br>df = get_game_log(season)<br>for season in seasons[1:]:<br> P = get_game_log(season)<br> df = pd.concat([df,P])<br> time.sleep(0.5)</pre><p>A slice of the DataFrame with some relevant columns looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*qDc-bMXyZ2JJCH5aojx9mQ.png" /></figure><p><strong>Step 3</strong>: Create playoff-related columns.</p><p>For playoff data, we may want to know the following:</p><ul><li><strong><em>Round number </em></strong>(numbered 1–4)</li><li><strong><em>Game number </em></strong>(numbered 1–7)</li><li><strong><em>Series Standing </em></strong>(e.g. 3–0, 1–1, or 1–3).</li></ul><p>The code below produces there <em>S</em><strong><em>eries Standing</em></strong> column which I call <strong>‘series’</strong>. First, let’s get the current number of <strong>wins</strong> and <strong>losses </strong>in the series.</p><pre># get the current number of series wins<br>df[&#39;win&#39;] = 0<br>df.loc[df[&#39;WL&#39;]==&#39;W&#39;,&#39;win&#39;] = 1<br>df[&#39;series_wins&#39;] = df.groupby([&#39;season&#39;,&#39;team&#39;,&#39;opp&#39;])[&#39;win&#39;].transform(lambda x: x.cumsum().shift().fillna(0))<br>df[&#39;series_wins&#39;] = df[&#39;series_wins&#39;].astype(int)</pre><pre><br>#get the current number of series losses<br>df[&#39;loss&#39;] = 0<br>df.loc[df[&#39;WL&#39;]==&#39;L&#39;,&#39;loss&#39;] = 1<br>df[&#39;series_losses&#39;] = df.groupby([&#39;season&#39;,&#39;team&#39;,&#39;opp&#39;])[&#39;loss&#39;].transform(lambda x: x.cumsum().shift().fillna(0))<br>df[&#39;series_losses&#39;] = df[&#39;series_losses&#39;].astype(int)</pre><p>Now we can make the <strong>‘series’<em> </em></strong>column.</p><pre># create a &#39;series&#39; column (represents what the series is at going into the game)<br>def get_series_standing(s):<br>    w,l = s[&#39;series_wins&#39;],s[&#39;series_losses&#39;]<br>    return str(w)+&#39;-&#39;+str(l)<br>df[&#39;series&#39;] = df.apply(get_series_standing,axis = 1)</pre><p>After adding a few other columns, our new data looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VGtojCoWS7bbgLBLeZUXsA.png" /></figure><p><strong>Step 3:</strong> How can I use this data?</p><p>The point of the wrangling was not for nothing; I personally like to test strategies, make inferences, and validate stats I see on projected on ESPN. The only way I can do this is if I have a dataset which I can work with on my own; the only queries I can make through <a href="https://www.nba.com/stats/teams/traditional">stats.nba.com</a>, for example, are limited.</p><p>One claim I am making here is that home court advantage has been less advantageous in recent years. Let’s make that more apparent by plotting a timeline of home court win percentage for the higher seeded team.</p><pre>FILTER = (df[&#39;is_home&#39;]) &amp; (df[&#39;has_home_court&#39;])<br>DATA = df.loc[FILTER].groupby(&#39;season&#39;)[&#39;win&#39;].mean()<br>DATA.plot(title = &quot;Higher-seeded Home Win Percentage in the Playoffs&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*ClQ7wD7FXozt75vFSwCbtA.png" /></figure><p><strong>Conclusion: </strong>There is a noticeable decline in win percentage for the higher seeded team in home games. My guess is that this is primarily due to <a href="https://sports.yahoo.com/nba-parity-reaching-levels-not-190625858.html"><strong><em>more parity</em></strong></a> across the league (this season, west teams seeded 2–8 were separated by four games in the standings.)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eca772e97890" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Accessing MLB statistics using Python]]></title>
            <link>https://medium.com/@adrienpeltzer_17089/accessing-mlb-statistics-using-python-e5b539985a96?source=rss-5667a28f795b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5b539985a96</guid>
            <category><![CDATA[mlb]]></category>
            <category><![CDATA[sports-statistics]]></category>
            <category><![CDATA[sports-analytics]]></category>
            <category><![CDATA[baseball-statistics]]></category>
            <category><![CDATA[baseball]]></category>
            <dc:creator><![CDATA[Adrien Peltzer]]></dc:creator>
            <pubDate>Mon, 22 May 2023 18:03:10 GMT</pubDate>
            <atom:updated>2023-05-22T18:03:10.718Z</atom:updated>
            <content:encoded><![CDATA[<h3>Accessing MLB statistics using python</h3><p>Using python to access a rich dataset can be very rewarding; something about the structure of an API makes it a pleasureful activity, especially when the data is something that interests you. Here I will talk about the easiest way <em>I </em>was able to access MLB API data. A quick google search led me to MLB-StatsAPI, a python wrapper created by Todd Roberts (see <a href="https://pypi.org/project/MLB-StatsAPI/">https://pypi.org/project/MLB-StatsAPI/</a> for more info).</p><p>Step 1: Install statsapi</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9X118Nf7ZkDFsfyquI0e5w.jpeg" /></figure><p>Step 2: Import the requisite libraries</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*egIAtahtBho4358mlAe4ig.jpeg" /></figure><p>Step 3: Now the fun part. Let’s first look at the games played so far this season.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n6SSstqrz2QUSJGGzhsJYw.jpeg" /></figure><p>Step 4: This DataFrame has some information in itself, but for today’s mini-project, I will go ahead and access the pitch count for every half-inning through the first 100 games of the season. Using the above DataFrame, I gather the unique game_ids for every game and access the pitch count using the <em>requests </em>module to access the API. I then read the data as a json object, gather the pitch count for every at — bat, and store it in a list which I call <em>data</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ayGLoCY_ZVC1N1BtxfTWNw.jpeg" /></figure><p>Step 5: Now we create a DataFrame where every row is an at-bat:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y0znS9F7t2RE8wi5wIDXkg.jpeg" /></figure><p>Step 6: Let’s now groupby halfInning, aggregate the pitch count and calculate the average number of pitches thrown per half-inning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n3JRdjrSxNIlUu6ZHMv9YQ.jpeg" /><figcaption>Average number of pitches thrown per half-inning through the first hundred games of 2023</figcaption></figure><p>It looks like the first inning has the most pitches thrown on average, and if the game goes to extra innings, not as many pitches are thrown in those innings (though this may be due to small sample size).</p><p>Step 7: I want to display visually the distribution of the number of pitches, so I’ll create a histogram to finish it off.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T7Z2nkF2LIdvxw-jZ7Ps7A.jpeg" /></figure><p>It looks like the distribution is skewed to the left, which suggests a non-gaussian distribution. This is not immediately clear, but after a little thinking I convinced myself it was reasonable. The pitch count depends on the number of batters that come up to bat during the inning. If a batter gets on base, then the pitcher has to throw again to try and record an out, and the pitches thrown to the previous batter don’t help end the inning (no recorded outs). I am guessing the long right tail is due to those innings in which there are many batters that go up to the plate.</p><p>Hope you enjoyed!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5b539985a96" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>