How I Generated the Models and Charts for My Activity/Sleep/Writing Correlations

In case anyone was curious about how I generated the models and charts in the previous post, I used Mathematica. It took only a few lines of code to calculate the models and generate the charts. Here is the code I used:

data = Import["C:/Users/rubin/Downloads/WritingWalking.xlsx"][[1]];
data2 = Import["C:/Users/rubin/Downloads/WritingWalking.xlsx"][[3]];
data3 = Import["C:/Users/rubin/Downloads/WritingWalking.xlsx"][[4]];
sleepdata =
Import["C:/Users/rubin/Downloads/WritingWalking.xlsx"][[5]];

lm = LinearModelFit[data, x, x];
lm2 = LinearModelFit[data2, x, x];
lm3 = LinearModelFit[data3, x, x];
lmsleep = LinearModelFit[sleepdata, x, x];

Show[ListPlot[data], Plot[lm[x], {x, 0, 2500}],
AxesLabel -> {"Words", "Steps"}]
Show[ListPlot[data2], Plot[lm2[x], {x, 0, 2500}],
AxesLabel -> {"Words", "Steps"}]
Show[ListPlot[data3], Plot[lm3[x], {x, 0, 800}],
AxesLabel -> {"Words", "Steps"}]
Show[ListPlot[sleepdata], Plot[lmsleep[x], {x, 0, 2000}],
AxesLabel -> {"Minutes", "Words"}]

That’s it. The data itself comes from two sources:

  1. Step and sleep data come from my FitBit device. I exported the data for the 300 days in question to an Excel spreadsheet.
  2. Word count data come from my Google Writing Tracker scripts.

Published by Jamie Todd Rubin

Jamie Todd Rubin writes fiction and nonfiction for a variety of publications including Analog, Clarkesworld, The Daily Beast, 99U, Daily Science Fiction, Lightspeed, InterGalactic Medicine Show, and several anthologies. He was featured in Lifehacker’s How I Work series. He has been blogging since 2005. By day, he manages software projects and occasionally writes code. He lives in Falls Church, Virginia with his wife and three children. Find him on Twitter at @jamietr.