Author Archives: Patrick

TidyX 25: Intro to Shiny Apps

This week, Ellis Hughes and I begin a series on building Shiny apps. We’ve built several Shiny apps in the past (for example TidyX 3 or TidyX 24) but always feel rushed to explain some of the fundamental coding that is necessary for people to get off the ground. As such, and because the syntax for Shiny apps can be a little funky, we decided to create a series where we of episodes on Shiny apps where we will take a data set and iteratively build a Shiny app from scratch.

In this week’s episode we help get you off the ground with your first Shiny app by walking you through my very own starter template. When I sit down to develop a Shiny app (which is pretty much weekly at this point) I always start with this exact template just to help me get going and get the data showing up in a webpage. From there I begin to customize the app based on need.

To watch the screen cast, CLICK HERE.

For our code, CLICK HERE.

Python Tips & Tricks: Coding A Tensorflow Neural Network to Predict Yards After Catch

As I work to improve my python skills, I’ll keep adding my efforts to the blog. This week, I saw a nice article showing a basic approach to coding a neural network in R to predict yards after catch in NFL receivers from the folks at www.opensourcefootball.com. So, I decided to take that idea and try and create my own neural network in Python.

Some notes:

  1. This is not a to say that the neural network was the best method to answer the question. Rather, it was just a way for me to try and take stuff I’d already do in R and see if I could learn it in Python.
  2. This is not a blog post to cover all aspects of neural networks (not even close). It just so happened that the original article used a neural network via tensorflow in R and I happened to be doing some work in tensorflow in Python this week, so it was an easy connection to make.
  3. My Python coding is pretty messey and at times I feel like it takes me several steps to do what someone might do in a few lines. Feel free to comment and offer suggestions.
  4. Harking back to point one, I finish the script by coding a linear regression model to answer the same question (predict yards after catch) as it is a simpler and more interpretable than a neural network. I construct the regression model in two ways. First, I do it in sklearn, which seems to be the preferred approach to coding models by pythoners. I then do it in the statsmodels library. I’m sure this is more a function of my poor python programming skills but I do feel like the model output from statsmodels is more informative than what I can get returned from sklearn (and I show this in the script).

The data came from nflfastR, which is an R package for obtaining NFL play-by-play data created by Ben Baldwin et al.

I provide a step-by-step explanation for coding the model on my GITHUB page.

 

TidyX 24: Waffle Plots, Shiny Apps, and Wide Receiver Target Shares

This week, Ellis Hughes and I break down code that Jared Braggins wrote to construct waffle plots describing plant extinction in Africa using data from TidyTuesday.

For those that are unfamiliar, a waffle plot is a great way for showing counts of data and the relative contribution of one value to a group. This type of plot lends itself well to the number of targets each receiver on an NFL team receives relative to other receivers on that team. So, we took Jared’s idea, used the {waffle} package, and constructed our own waffle plot. We then extended this out into an interactive {shiny} app so that the user can select a team of interest and get returned back a waffle plot for that team along with a team of data providing the receiver statistics for that given season. Finally, we provide the option to download the output as a PDF report directly from the {shiny} app. When it is all done, it looks a little something like this:

To watch the screen cast, CLICK HERE.

To obtain our code, CLICK HERE.

TidyX 23: for loops & functions

This week, Ellis Hughes and I delve into our mailbag and answer a viewer’s question about writing for loops and custom functions. To explain these two topics we walk through our script on how to optimize the exponent in Bill James’ Pythagorean Win Formula for baseball.

To watch our screen cast, CLICK HERE.

To get our code, CLICK HERE.

If you have any questions or topics you’d like to have explained, feel free to reach out to us a tidy.explained@gmail.com or connect with us on Twitter at @tidy_explained.

TidyX 22: Dumbbell Plots for NBA Player Stats

This week, Ellis Hughes and I go over how to create dumbbell plots. Dumbbell plots are a nice way of showing differences between two time points or between two variables that are on the same scale within a group or within individual.

To explain dumbbell plots, we first go through code provided by Kelly Cotton, who used this data visualization technique on the latest TidyTuesday data set to show changes in energy production over time within different European countries.

Ellis and I then take Kelly’s approach and apply it to NBA players to show differences between their Assists per Game and Shots per Game within the 2019 season. A report we termed the “Ball Hog Report”.

To watch our screen cast, CLICK HERE.

To access our code, CLICK HERE.