180 Decisions A Day

There’s a number that has been floating around the Diabetes Online Community (DOC) for a while now, mostly on Instagram. It says that people with type 1 diabetes make 180 extra decisions a day related to their diabetes. Wow, that seems like a lot! No wonder I’m so tired all the time.

The first time I saw this claim I was kind of surprised by the number (it seemed really big), but didn’t think too deeply about it. Every few months, this number would come around for another cycle of sharing and commiserating. And every time it would bother me more and more.

This last time, I decided to finally look into where this claim came from and, as it turns out, this claim doesn’t seem to have a basis in any research. Best I can tell, it originated in a 2014 blog post/press release from Stanford for a study that was about maintaining steady blood glucose levels overnight. The blog post, which was written by a staff science writer, makes this claim at the beginning without any citation or reference. People see the study cited and assume that this is where the number came from, but it’s not. When you actually look up the study, the word “decisions” isn’t even in the article. The number 180 comes up once, but only regarding the maximum number of minutes that the automated insulin pump delivery system should be suspended per night.

So why do people trust this claim? And why does it seem to be everywhere? If you Google “diabetes 180 decisions a day” almost 8 million results come up, many from very mainstream diabetes institutions. First of all, it’s a number, which conveys scientific certainty and research. People are likely to trust numbers because they believe that they are objective and represent some kind of fact or reality. Second, this claim’s source is Stanford Medicine, which is a reputable organization that people are familiar with. Most people (or literally anyone else, it seems) are not going to check the source to see if it’s accurate or not. We trust the article from Stanford Medicine because we don’t really have a good reason not to. And this is behavior of not just “regular” people on Instagram, but also other researchers, who should actually know better.

Moreover, and more importantly I think, the number doesn’t make any sense. Let’s say that you sleep 8 hours a night and are awake for 16 hours a day, which is 960 minutes. If you were making 180 diabetes decisions a day, you would need to be making a health-related decision every 5 minutes you were awake, all day every day. If you have a CGM, getting a blood sugar reading every 5 minutes, this would mean that you looked at every single one of those readings as they came in and made some kind of decision. No one is doing that. Humans are not great at estimating the frequency of events like this, so 180 seems right, even if it isn’t. Now, if you’re on an automated insulin pump system (like with Tandem t:slim x2 or Omnipod 5), that pump is making a decision every 5 minutes – but you are not.

And if we assume that you are not sleeping through the night, since diabetes occasionally makes that difficult, you’d still be making a diabetes decision every 8 minutes, all day and all night, if you were trying to get to 180.

There’s no way this claim can be true – and if you think you are actually making that many diabetes-related decisions in one day, please talk to a certified diabetes educator so that they can help relieve some of that burden because that is not normal or ok.

So why do people keep sharing it? I think the main reason is that it is really hard to explain to non-diabetics the mental burden of this disease. We do have to make a lot of extra decisions every day to keep ourselves alive and healthy. It is at times overwhelming. It is challenging and hard to predict. It is constantly in the back of your mind. I feel lucky when I can forget about it entirely for a couple hours. And we want other people to understand the weight of this burden. So when we find what we think is a reputable, research-based claim about how objectively difficult this is, and we share it. Because it feels true. Even when it actually isn’t.

Insulin-a-versary

It’s my two year insulin-a-versary! This is not to be confused with my dia-versary, the anniversary of my diabetes diagnosis which is in late December. These two dates, my initial diagnosis date and my correct diagnosis date, occurred more than a year apart from each other. Which is part of the reason why today is special for me. (You can read more about my diagnosis story here.)

It might seem strange to celebrate the day that my life entirely changed and I had to start injecting myself multiple times a day (and will have to do so for the rest of my life). But it is also the day that I started feeling relief, started feeling heard, and started really feeling better. This chronic illness had slowly been creeping up on me over years and years, taking away my energy, my happiness, and my ability to live my life. Getting my correct diagnosis as type 1 and starting daily insulin injections truly gave me my life back. I had been slowly dying, my body literally eating itself from the inside, and things were finally turning around.

What I didn’t know at the time of my initial diagnosis was that there was something called LADA, or latent autoimmune diabetes in adults, which is basically a very slow-progressing form of type 1. Before my original diagnosis I didn’t even realize that adults could get type 1, and had no idea there was a slow moving version of it1. Many doctors are not even aware of it, which is one reason why so many adults get misdiagnosed like I did, even though I presented with the classic symptoms. It was a frustrating year after my initial diagnosis and brief hospital stay, where the type 2 medications they original prescribed me worked ok for a few months but then slowly stopped helping. And I didn’t know why. I was doing all of the things I was supposed to and I was beginning to feel like utter crap all of the time again. I had one doctor blame me for not trying hard enough. It was not great. Luckily I eventually got a consult with an endocrinologist and within five minutes of just talking/listening to me, she told me I had type 1 and gave me some insulin.

Before that day two years ago, insulin had been held over my head as a punishment for not doing things properly. It really messed with me. And I think that a lot of the public also get this message (especially around type 2 diabetes), that having to inject a life-sustaining hormone into your body is a sign of weakness and failure. It is not. Everyone, every single person, needs insulin to survive. Most people’s bodies make their own. And most people have no idea how much insulin they use.

I tried hard for a long time to use as little insulin as possible. Because I had still internalized this message that insulin was bad. I didn’t eat foods that I wanted to eat because I knew I would need a lot of insulin for them and kept myself on a low-carb diet for months just because I was trying to be “good” and only use a certain amount of insulin every day. This was partly because my prescription was for a certain amount and I knew if I went over, I would run out early and that would be bad. But it was also because I didn’t think it was ok to just use the amount that my body needed for the food and life that I wanted.

I’m happy to say that I don’t feel that way anymore, but it took a long time. I also had to talk to my endo and have her prescribe more than my “average” amount per day so that I wouldn’t feel anxiety anymore about running out (which I almost did twice in my first eight months and actually only didn’t run out because I bought some extra insulin in Canada). I definitely use more insulin now than I did two years ago and there’s nothing wrong with that.

Some things that I didn’t realize two years ago would soon become a part of my life:

  • I have to schedule exercise into my day in a complex and nuanced way that I didn’t think twice about before
  • Some carbs are worth calculating for and some are not
  • I carb count things I see on TV without realizing I’m doing it
  • I hate the American health insurance system with every fiber of my being
  • Being your own pancreas is a lot of work and you never get a break from it
  • Anything can become a normal part of your day, even having two medical devices attached to you 24/7
  • Post-apocalyptic fiction is no longer as interesting to me as it once was because I can’t forget the fact that I would die a slow, painful death in any kind of scenario like that
  • I have opinions about different needle manufacturing companies (Tandem just changed the brand of needles that come with their insulin pump cartridges and I’m kind of annoyed)

This year, 2021, is also 100 years after insulin was first discovered. The 99th anniversary of the first insulin injection in a patient was earlier this week. In America, insulin is still too expensive. The list price, set by the pharmaceutical companies, is around $300 per vial when it only costs them about $5 to make it. They are extorting diabetics because we will literally die without it. It hasn’t changed in over twenty years and the price just keeps going up. In basically every other country, insulin is a reasonable price or even free. It can also be bought over the counter in most countries, which would be a huge positive change here. The prescription barrier, in addition to the financial one, is another way that insulin is not accessible here. It needs to stop. We need insulin for all and we need it now.

  1. Also, side note: fun fact! There are lots of types of diabetes! Not just the two that you’re familiar with. There’s gestational, type 3c, MODY, and some other ones. None of them – including type 2 – are caused by eating too much sugar.

My New Data Collection Project

2018 was a really hard year for me. So much changed in my life, the biggest of which might have been moving across the country to start my dream job as a professor at an R1 university. But in many ways, that huge change was overshadowed with another life-altering change: being diagnosed with diabetes.

What happened?

Let’s go back a few years, to 2016 when I started feeling awful a lot more than should be normal. I use the word ‘awful’ because it was a fairly non-specific symptom for a long time. I was really tired and I had bouts of depression, but I mostly chalked this up to being stressed out with work and traveling a lot. I usually felt the worst right after a trip, so that seemed to make sense to me. So I told myself that in 2017 I would travel less and try to be less stressed out with work stuff. And I feel like I did those things (I definitely traveled a lot less and was generally less stressed with work-related things). But I felt even worse. My depressive episodes were worse and lasted longer than before. I was tired all of the time. Just had no energy. It was really frustrating.

Then, around November of 2017 things got really bad. I had some new symptoms: extreme thirst and unexplained weight loss. I lost 20 lbs in about six weeks even though I wasn’t eating any less or exercising any more. Something was clearly wrong. I had one really horrible weekend where I couldn’t get off the couch at all. So that following Monday afternoon (after I turned in a proposal at work) I went into urgent care to see what was going on. I’m not sure exactly what I was expecting, but mostly I just wanted to feel ‘not awful’ any more.

They ran some tests (actually a lot of tests) and had a clear answer: it was diabetes. Because my blood glucose (BG) was still fairly high (it was a bit above 300 mg/dL if I remember correctly), they transferred me to the emergency room so they could make sure it got down to a normal level. The doctors in the ER at Stanford Hospital were great and explained some of the basics to me. (Also, big thanks to my BFF Britte who was a huge help that day.) At the time, they weren’t sure what type of diabetes it was. They initially were leaning toward type 1, but they weren’t sure. After talking with some more doctors they decided to treat as if it were type 2 initially and see how that went. Type 2 can be managed (especially at early stages) with oral medications and a good diet and exericse plan. So that’s what I did.

A few weeks later I had a follow-up appointment with my regular doctor and based on some blood test results that there was some insulin in my system and me responding well to the oral meds, they concluded that it was most likely type 2. (Spoiler alert: it wasn’t. More on that later.)

I had a lot of mixed emotions around this time. First and foremost I was relieved that I had a diagnosis and that I could do something that would make me feel not awful all of the time. I was a bit scared about what this meant for my life long-term and overwhelmed by the types of adjustments I would need to make to stay healthy. But part of me was also upset at myself for “letting” this happen. It was difficult because, even though I’ve always been overweight, I always felt like I ate pretty healthy and exercised a decent amount. I explained this to the doctor that I was basically already doing all of the things they suggested I needed to do (w/r/t diet and exercise) to in order to keep it under control. Sure, I could eat a couple more salads and go for a couple more runs; but it wasn’t like I was sitting on the couch all day eating garbage. It was very frustrating, but I didn’t make a big fuss about it at the time.

I only told my family and a few close friends what was going on. Our society definitely has a stigma around type 2 diabetes and I felt like I didn’t want to bring on any unnecessary judgment onto myself. I felt like I could’ve done something differently to have prevented it and so I felt ashamed of my diagnoses and what it signified. This is obviously a huge problem and it makes me think about why it took me so long to go to the doctor when I had a good idea that was going to be the diagnosis (WebMD isn’t always wrong) and how many other people are out there living with feeling awful because they are ashamed. It’s not good.

Now of course, since I had just lost a bunch of weight, people were now constantly commenting to me about “how good I looked”. There was one exception where somebody asked me if I was “well” (and I think it’s relevant to point out that this person did not grow up in the United States), but everyone else wanted to me to know that I looked great now that I’d lost this weight and most of them then followed up with the question “how’d you do it?”. Every time this happened my stomach dropped a little bit. I wasn’t about to tell these people, most of whom were just acquaintances or work colleagues, my situation. And it was enough weight and obvious enough that I couldn’t pretend that I hadn’t noticed. So I responded with “low-carb diet” usually with some kind of either enthusiasm for how fun it is to limit your carb intake or like a resigned annoyance (accompanied with a shrug) that I don’t eat big bowls of pasta anymore. This explanation usually worked. I do feel a bit bad because, while it was not a lie that was I on a low-carb diet, my weight loss was a symptom of an untreated disease that was turning my life upside down and a low-carb diet was not really how I lost that weight. But then I remember that I don’t owe these people any information about my life and I don’t feel so bad. Also, stop asking people this question. Please. You don’t know someone’s life and there are many reasons someone could have lost a bunch of weight. And if someone loses a lot of weight very quickly, that is not healthy.

Through most of the first half of 2018 things were going pretty well. My numbers were in the range they needed to be and for the first time in a long time I felt relatively normal. My depression had almost entirely gone away and I had energy again. It was wonderful. It’s a good thing too because I was on the academic job market and I’m honestly not sure I would have been able to deal with that if I had still been ill. The timing worked out.

But then, in the summer, things started to slide a bit. My BG numbers were creeping up. At the time, I attributed this to all of the stress I was dealing with – planning a move from California to Illinois, tying up loose ends at my job, and lots of travel (including a big international conference). There were six weekends in a row from late May to early July where I was going somewhere. It was a lot. But I had most of July to recover before moving the first week of August and I thought it would be fine. It wasn’t.

By the beginning of October, I was fairly settled in my new job and location and I was doing really well with my diet and exercising a lot. I was riding my bike to my office every day and eating the healthiest I had ever eaten. And yet, my BG numbers were bad. And nothing I was doing was making them go down. It was extremely frustrating. I went to my new doctor and told him the situation. He ordered some tests and a follow-up visit in a month.

On my second visit when things hadn’t improved, he upped all of my meds and added a new one to help lower my BG. He also told me I wasn’t trying hard enough, which was not only not true but kind of a crappy thing to say to someone. I kind of pleaded with him that I had been doing everything I was supposed to, and I was started to lose weight again and it was really frustrating. Almost on a whim (he was literally about to walk out the door), he asked me if I was sure it was type 2. I said no and then, luckily, he referred me to the endocrinologist to make sure.

So, finally, in January of this year I got in to see the endocrinologist and she very quickly figured out that it was type 1. She ordered some tests just to make sure and started me on insulin. Sure enough, about a week later the tests confirmed that it was type 1. Since then, I’ve been feeling so much better. I give myself about 4 injections of insulin every day (one long-acting insulin once a day, and usually three shots of fast-acting insulin before meals). It’s been a huge adjustment but I’m figuring it out and learning a lot.

img_6569
injecting some insulin

So why did this happen – the misdiagnosis and feeling good for a while and then bad again? Well, it turns out that when your pancreas decides to stop working, it doesn’t do it all at once. I’m in the “honeymoon” phase, where my pancreas is still producing a tiny bit of insulin, but it is tapering off and eventually (within a year or two, maybe sooner) it will stop completely. As that happens I will have to adjust the amount of insulin that I take to make up for it.

Type 1 and type 2 are actually very different and the only thing that really transferred across was my newly learned abilities in counting carbs (which I’m still getting better at). Type 1 is an autoimmune disease where your pancreas decides to stop producing insulin, which everyone needs to process the glucose in your body and turn it into energy. There is a genetic component, but it also just happens randomly (in something like 1% of the population). It used to be referred to as “juvenile diabetes” but that term isn’t really true (half of people with it are diagnosed after the age of 20). There is no cure and I will be dependent on insulin injections for the rest of my life. [Type 2 is when your body is resistant to the insulin that you are still producing. It also has a genetic component. It can usually be managed with diet, exercise, and oral medications and there is new evidence that it can be put into remission with certain amounts of weight loss. Some people with type 2 end up needing insulin as well.]

Data data data

There are so many numbers. And equations and ratios and graphs and trends. It’s a very good thing that I like all of those things and am good with numbers and doing math in my head. This would be a LOT harder if I didn’t. For example, before I eat anything, I need to: check and see what my current BG number is (a “normal” number should be between about 80 and 140), figure out if it’s going up or down or staying steady (this is currently a guess for me, but in the future it won’t be with a continuous glucose monitor), calculate the amount of carbs in what I’m about to eat (and also factor in the protein and fat and caffeine because those also has an effect on my BG), and decide whether or not I’m going to be exercising in the next 1-2 hours (exercise will generally lower my BG). Then, once I have that figured out I can give myself an injection of my fast-acting insulin that will balance out what I’m about to eat and keep my BG number in the normal range. If this sounds exhausting, you’re right! It is. And I have to do this multiple times a day, every day, for the rest of my life.

If my BG gets too high, I will feel super crappy and long-term high BG is associated with lots of adverse health outcomes and even death. If my BG gets too low, I could pass out or end up in a coma, which is obviously really bad as well. It’s important to keep my BG in range as much as possible.

There are many factors that can affect my blood sugar. Obviously food is the biggest one, but lots of other things make a difference as well. Exercise, hormones, the weather, and stress can all impact my BG number. Even if I eat the same thing every day, the numbers will be a bit different. Every day is a little experiment.

Soon (hopefully very soon), I will be adding a continuous glucose monitor (CGM) into my routine. Right now, in order to check my blood sugar, I have to prick my finger and use a test strip in a little device that I carry around to see what the number is. This is annoying because my fingers have become little pincushions, it takes a minute or so to do this every time, and I have to carry the pouch with the meter and supplies wherever I go if I want to do this (and, as I mentioned before, it’s good to do this before I eat anything or exercise and also at random points throughout the day). The CGM is a sensor and transmitter that I will insert/attach to my body once every 10 days or so and it will provide a blood glucose reading every 5 minutes directly to my smart phone (and watch). Amazing! This will make it so much easier to know what’s going on inside my body and how I’m reacting to the day. I will be able to see trends and do little experiments to better figure out my insulin to carb ratio and the right amount of long-acting insulin to take every day.

Science!

It’s really amazing that I’m alive. 100 years ago, type 1 diabetes was a death sentence. Then, in the 1920s, insulin was discovered and we were given a chance. The patent for producing insulin was sold to the University of Toronto for $1 so that everyone who needed it could have access to life-saving insulin. (Unfortunately, at least in the U.S., this equality of access is not a reality for many people so we still have some work to do. See below.)

It’s still fairly precarious as I need to carry around this little pen of insulin with me everywhere (I would probably not do well in a zombie apocalypse scenario), but I feel very thankful that I have a chance and, with good planning and control, I can still do pretty much whatever I want to do with my life. Hiking, soccer, and travel will still very much be a part of my life thanks to science and technology and I won’t ever forget that.

Why am I telling you this?

Well, it’s a huge, constant part of my life now and it feels weird to hide it (and I don’t want to hide it). But, really, for at least two reasons. One is that type 1 diabetes is a lot to manage. It is a 24/7 job for me to manage my blood sugars, count the carbs in whatever I’m eating, inject the right amount of insulin at the right time, and not get too discouraged or upset when the numbers get a bit unpredictable (because they will; it is the nature of this that I won’t be able to control it perfectly all of the time). And I need help from my friends and family to support me through this.

If we’re hanging out together, I need you to: not be alarmed when I give myself an injection; know what it means if I’m “low” and how to help me get some sugar into my system; understand that I might check my phone/watch a lot (I’m likely looking at my blood sugar numbers). If you’re not physically close by (or even if you are), I need you to: be there to listen if I’m having one of those days when it just feels like too much and I need to vent and to advocate for a better healthcare system in the U.S. so that people don’t have to ration their insulin because they can’t afford it.

The other reason is that this is a fairly “invisible” disease. You usually can’t tell that someone has it by looking at them (unless their CGM or pump is visible, and even then you might not know what those are for). Before my diagnosis, the only people I knew with type 1 diabetes were Stacy from the Babysitter’s Club books, the Julia Roberts character in Steel Magnolias, and one of my friend’s boyfriends in college. None of whom really taught me much about what the day-to-day would be like for this. So, I had a lot of learning to do fairly quickly. I also didn’t understand the situation with the affordability of insulin in the United States and how so many people are having to spend exorbitant amounts of money just to stay alive. To be clear, for me and other type 1 diabetics, insulin is not so much a medication as it is like oxygen; without it we will die. The fact that insurance companies and pharmaceutical manufacturers are allowed to make a profit on something that I need to stay alive makes me really angry. It costs the manufacturers about $5/vial to make insulin, the “modern” version of which has been around for about two decades and hasn’t changed in form or delivery nearly at all in that time, and yet they can charge hundreds of dollars for it (or more). The price has more than tripled in the last two decades. I have a good job and good insurance and it still costs me about $100/month for my insulin and other supplies I need (it will be more once I get my CGM). Other countries have either free insulin for people who need it or a much lower cost (something closer to $5-10/vial), so this is clearly achievable if we try.

Anyway, I’m here trying to live my best life despite this extra hassle. Your support and understanding and advocacy are much appreciated.

Back to academia!

In August I moved across the country (again) for a new opportunity that I am so excited about. I have started a new position as a tenure-track assistant professor at the University of Illinois at Urbana-Champaign. Yay! I am part of a new campus-level initiative called Technology Innovation in Educational Research and Design (or TIER-ED). I have a split appointment within the College of Education; I have a 75% appointment in the Educational Psychology department and 25% in the Curriculum and Instruction department. The plan is to do a lot of interdisciplinary work across campus (e.g., with VR/AR researchers, speech researchers, and the physics department).

img_5392

Continue reading “Back to academia!”

Eclipse pinhole projector

Yesterday I posted some videos on Instagram of step-by-step instructions on how to build your own pinhole projector to safely view the eclipse on August 21st. In order to make the instructions easier to share, I’ve compiled them all here (well, screenshots from them at least) to help you turn an ordinary cardboard box into a pinhole projector. 

For more information on the eclipse check out the NASA website eclipse2017.nasa.gov.

Step 1: Find a cardboard box and cut a white piece of paper to fit the bottom. 

Continue reading “Eclipse pinhole projector”

Going Deep with David Rees

Today on the blog: a TV show recommendation. Season 2 of Going Deep with David Rees started last week and I think it’s a really good show. The basic idea of each episode is that David is trying to figure out how to do something. Something simple, like how to make an ice cube, because it turns out that even simple things are actually really complex and interesting when you break them down. While that premise is immediately interesting to me, one of the things I like best about the show is its warm sense of humor and an open and sincere quest for knowledge of everyday life. It’s this same sense of wonder and propensity for questioning things around me that initially made me want to be a scientist (and now, study how people learn science).

David Rees is a well-known artisanal pencil sharpener. Ok, maybe not well-known to a large number of people, but still, if you send him a pencil he will sharpen it by hand for you. He wrote a book on How To Sharpen Pencils, so he probably knows what he’s talking about. He is probably actually more well-known for being the person responsible for the political cartoon Get Your War On which, at least for me, made the post-9/11 George W Bush years slightly more bearable.

Season 1 of GDDR focused on important questions like How to Open a Door, How to Flip a Coin, How to Shake Hands, and How to Dig a Hole. Those might sound like silly topics for a show, and they are to a certain extent, but that’s not really what episode is totally about.

Sadly, season 1 is not available to stream anywhere at the moment, but it’s not too late to get on the bandwagon for season 2. The first episode was about How to Pet a Dog and tonight’s second episode was about How to Eavesdrop. Tonight’s episode was a really good example of how they can take a simple question and expand it into a really interesting and engaging sciencey show.

How to Eavesdrop is not really about eavesdropping perse. It is about sound. Which is one of my favorite physics topics. As David says in the episode, “how do sound waves get turned into something my brain recognizes as sound?”. Even though he talks to a former CIA spy about actual eavesdropping, the heart of the episode (to me, at least) is talking to the audiologist and learning how the ear works and talking to the cognitive scientist about how we interpret sound waves to understand speech. They even talked about the McGurk illusion which is fascinating and is also something I wrote about on this very blog about four years ago. And, to make my little academic heart even happier, GDDR popped up a citation to the McGurk et al. paper when they talked about it!

If you’re looking for a fun and engaging bit of science on your TV (or computer), you should definitely check this show out.

Beethoven visualization

I came upon this amazing visualization of Beethoven’s 7th Symphony a little while ago. I found it when searching for this piece1 (one of my favorite classical music pieces) and realized it was also a super cool visualization.

Each color corresponds to one type of instrument, from the orange violins to the greenish flutes, the yellow trumpets, and the blue bassoons. I really like how it shows the complexity of the music and also allows you to see patterns in the piece as they develop over time and repeat.


  1. I was trying to remember if this was the music that was in Mr. Holland’s Opus when he was talking about Beethoven not being born deaf. It was

R Basics

This is the second part in an ongoing series I’m doing about why I think R is awesome and why you should be using it. (Check out part one!)

So now that you have downloaded and installed RStudio and have some data you want to play with, what are the next steps? How do you get started really working with your data? In this post I’ll cover an overview of the basics of working with R. Future posts will have more details on some of these topics.

Project spaces and working directories

So RStudio has you create a “project” when you get started. You tell it where you want the project to be and then it creates a file with “.Rproj” at the end. The location where this project resides is also your working directory. This will be relevant when trying to load in data

You can have more than one project (in different places if you want) and I have found creating multiple projects is mostly helpful for keeping different R projects separate. For instance, I have a main R project called “R Stuff” and then also separate projects for a couple of the bigger research projects that I work on. Things not attached to one of those two bigger research projects go in R Stuff and then I sort them out later and move them if they grow into their own thing.

My suggestion is to create most of your code/scripts/whatever in an R script file (extension .R) instead of just using the console to type in commands when you need them. You can load one of these in the main RStudio panel and type and edit your code here. Once you have some code/commands you like, you don’t need to copy them down into the console, you can just hit command-return (on a Mac, probably control-return on Windows) (or use the “Run” command in the upper right corner of that main window.

This script will allow you to do a couple of things: first, you can see your whole data manipulation/analysis/graphing workflow all at once; second, you can make changes to one step (e.g., switching the size of your graphed data points) and then re-run the code easily; third, you can write comments.

Now, I am not always the best at writing comments. But I try. And it’s really important. Even if you don’t think anyone else is ever going to see your code, you might need to look at it later. And no matter how smart and clever you think you are (well, actually I think if you’re super cleve then this is going to be more important because on a future day you may not be having a super clever day), you will probably need to read your code again. You are always, at a minimum, collaborating with yourself. And you deserver to have well-commented and documented code. So do yourself a favor and write some sensible comments.

Loading and viewing your data

Ok, so you have a data file and you want to start working with it. You have a few options. Most likely, it’s a .csv file and I’m going to assume to start that it’s in your working directory so you can use the command

d1 <- read.csv("MyDataFile.csv")

This will create a new dataset called d1 that is made up of what was in your csv file. You can use the “Import Dataset” button in the Environment panel. If your data file is in another location, you will have to enter the correct file path.

For the rest of the examples here, I’m going to use one of the sample data sets that comes with some R packages. The mpg dataset is one of the typical datasets for examples, as it comes in the base package. It is a datatset of car models and gas mileage data. Play along at home with the following commands.

To start, load the dataset: data(mpg). This should create an entry in the Data section of the Environment panel on the right. It should tell you the name of the dataframe and that there are 234 observations of 11 variables. Alright, but if we want to look at the data? If you type head(mpg) the console will output the header of the dataframe: the column names and the first six rows of data.

I prefer using glimpse(mpg) which is actually a command from the dplyr package. (If you haven’t already downloaded the dplyr package, now is a good time. We will be using it a lot in later posts.) Glimpse gives you a more compact view of more of the dataset and also tells you how R is interpreting each variable. For instance, R thinks that manufacturer is a factor (true) and that year is an integer (also true). displ is a “double integer” which is a bit weird, but for now, let’s just go with that it’s a special class of numerical variable. None of the text-based variables showed up as strings, which is good for our purposes with this dataset.

This is fine if you have a relatively small dataset, but it begins to get unwieldy if you have a lot of variables. The summary(mpg) call will give you a different view of your data. For the text-based variables, it gives you a count of them (up to a point) and for the numerical variables, it spits out the minimum, quartiles, mean, and maximum values. Pretty handy for a quick check.

If you want to see the whole dataset (or at least, a lot more of it, depending on how big it is) in a format more closely resembling that which you’re used to in Excel or something, you can use View(mpg). This will pop up a “normal” looking dataset in the main window for you to peruse.

Alright, now that we have looked at our data, let’s talk about variables. To access a specific variable, you will use the dollar sign. So, if you want to look at (or refer to) the model variable in the dataframe, you will call it by mpg$model. This way R knows that you are looking in the dataframe mpg and you want the variable model. You can use this in combination with lots of other things. For instance, if you wanted to find the minimum year of car that is in the dataset, you could use min(mpg$year) and it should output 1999.

If you make some changes to your dataset (e.g., adding a variable, reshaping it, filtering it, etc. — all topics for a future post), you can also save your dataset in a recognizable format. So if your new dataframe is called mpg2 you can export a csv of that using write.csv(mpg2, file="mpg2"). This will put a new csv file in your working directory with the filename mpg2.csv.

Other things to think about with R

In order to maintain an up-to-date version of R within RStudio, there are three separate things you need to update: RStudio itself (the application), R (the base), and all of your packages.

Updating your packages is easy in RStudio. In the Packages tab in the lower right corner (using the default set-up), there is an “Update” button that will easily show you which packages have updates available and let’s you download and install them. Super easy. (Updating RStudio is easy too: look in the Help menu (at least on Macs).)

When you start up RStudio, the console will give you a readout of the current version of R that you are running. As of today, that is version 3.2.2 (“Fire Safety”), but if you have an earlier version of R — as long as it’s not too old — most things should run fine. Updating R is sometimes a pain because you can’t do it directly in RStudio (which I think is confusing to people because you can update your packages easily in RStudio). When you download a new version of R, RStudio will automatically detect that, so that’s not too bad. However, RStudio tries to be helpful and store your downloaded packages in the correct place, but a major version update to R actually creates a new location and you have to migrate all of your packages over to that new place. It’s a bit of a hassle, but there is an easy way around it.

update.packages(checkBuilt = T, ask = F, type = "binary")

RStudio also has support for version control. Woo! You can use either git or SVN. I have more experience with SVN, but I am in the midst of switching over to git so maybe I’ll post about that at a later date. I’m not going to go into all of the details for how to set up and use version control, but, I will say that it’s a good idea even if you don’t need it for collaboration or sharing purposes.


Next post: we’ll look at how to organize and manipulate your data using my favorite package dplyr! Check it out here.

Je t’aime Paris

What happened tonight in Paris is just horrible. I don’t even know what else to say about it except it’s awful.

Paris is a beautiful city. I visited there in 2004 and want to go back someday soon.

DSCN0084

I have watched Casablanca probably 20 times. It is one of my favorite movies and one of the greatest movies ever made. And the most effecting scence for me, every time, is the part where the Nazis are in the bar and start singing their garbage Nazi song and then slowly the rest of the bar patrons (led by the freedom figher Victor Laszlo) start singing La Marseillaise and eventually drown out the Nazis. It is a very powerful scene and it always always always makes me cry.

The terrorists only win if we are afraid. But we can show them with our voices that together we are stronger than them and we will drown them out.

Disneyland is a TARDIS

Disneyland is a TARDIS. Let me explain.

The TARDIS is Doctor Who’s1 time machine. It is cleverly disguised as a blue police box. TARDIS stands for time and relative dimension in space but that’s just because acronyms are cool and don’t worry about it too much unless you’re asked that question at a trivia competition. The important things about the TARDIS (besides it’s big blue appearance) are twofold: it is a time machine and it is bigger on the inside.

Now while I do think that Disneyland is (or can be at its best) a kind of time machine, transporting someone to the wonder and awe of their childhood, I think the other aspect is more interesting. Disneyland is bigger on the inside.

I was listening to a podcast sometime last year (I wish I could remember which one it was – it was two dudes talking so it could be literally any podcast) and they were talking about some of the architectural design and design constrains of Disneyland. I had heard most of it before (the hub design, using high points in each land for orientation, making sure there was no bleed over between lands, etc.), but the conversation on the podcast then ventured into new territory for me: that some of the rides actually existed outside of the park boundaries (aka beyond the Disneyland Railroad loop). Once I heard this, it was so obvious, but I hadn’t thought about it before. Of course some of the rides went beyond the boundaries. That’s the only place they could go.

I have maintained for some time that Disneyland is superior to the Magic Kingdom in Disney World and one of the main reasons (besides being the original) is design constraints. Design constraints are usually a good thing. They make people more creative. Think about haikus, sonnets, and the 3 minute pop song. Enormous creativity can come out of sometimes harsh or even arbitrary constraints. Disneyland is no exception.

The land that Disneyland sits on in Anaheim is not that big. If you’ve ever run a half-marathon through the park or looked at it on Google maps, you will understand just how small it really is. But when you’re in the park, it doesn’t seem small at all. In the proper context, it is huge and seems to defy normal spatial dimensions. And that’s because it cheats.

Some of the “cheating” is just the normal kind of expected thing. For instance, it is pretty obvious that Pirates of the Caribbean is underground and you can kind of think of that as multiplying available space. But there is something else going on as well – actually extending the park beyond the apparent boundaries.

I have two examples of this. Now, to be clear, this is mostly just speculation on my part

Indiana Jones and the Temple of the Forbidden Eye (or just: the Indiana Jones ride like everyone calls it)

The full line is half a mile long. To put that in perspective, that is basically the same distance as walking from the main entrance plaza (near Great Moments with Mr. Lincoln) to the hub (the Mickey and Walt Disney statue) and back two times. So even if that line is snaking back and forth a lot (which, of course, it is), you are still going quite a distance in that full line and that line is taking you somewhere that is not that close to where you started.

And then the ride itself is quite large. It takes up even more space than the line, probably by a wide margin. And when you try to figure out where exactly that is, well, some of it is going to have to be outside the park boundaries.

Disneyland Google Maps

When you look at the satellite images of the park, it’s even more obvious. There is the big forrested area that is the Jungle Cruise and then there’s Pirates of the Caribbean which is already underground. So the Indiana Jones ride is pushed further out and has to be on the other side of the railroad. There is literally no other place for it to go.

The Haunted Mansion

The Haunted Mansion might also have a similar situation, but my guess is that it is not as much (i.e., not as far outside the park as the Indiana Jones ride is). Obviously, there is the clever downward elevator switcheroo at the beginning2 (which, as a kid, made me feel really awesome when I figured that out). So that gets you underground and then you have to walk a bit and then get on the conveyor belt ride3.

The Rivers of America is preventing too much underground construction in that direction, so it has to go the other way. And the Haunted Mansion isn’t exactly what I would space efficient. It is another large, winding ride and all of that has to go somewhere. And that somewhere is, at least in part, probably outside the park4.

TARDIS

I think it’s great that Disneyland is able to trick our perception of space so much. (And time, too, for that matter – either waiting in a long line or just spending time with family and friends – most of it seems to fly by.) It’s just another interesting aspect of the happiest place on Earth.

Untitled


  1. For those of you not familiar with Doctor Who, the longest running sci-fi series on television, you should do yourself a favor and watch some of it. The newer seasons are on Netflix. My favorite Doctor is the Tenth (David Tennant). Something about the suit and Converse combo, maybe. 
  2. with no windows and no doors 
  3. The Haunted Mansion is also another example of some of the problems I see with the Magic Kingdom in Florida. They basically copied the design and structure of Disneyland’s Haunted Mansion over there, but they didn’t have the same design constraints about it needing to be underground to save space. So it, and a lot of other things, feel a bit out of place because there is so much more space in Walt Disney World. They have basically unlimited space there and so the design constraints are different. 
  4. I think this is also why there are more larger rides on the west side of the park. If you look at the map again, the east side of the park goes up against the 5 freeway and my guess is that they can’t build under that. The park is kind of lopsided.