by George Taniwaki

A Dec 2011 article in The Fiscal Times purports to show that eating at restaurants is cheaper than cooking at home. It’s an intriguing idea that has appeared in many articles in the past. However, the analysis presented in The Fiscal Times article is flawed and the conclusions are not supportable.

Before going into the specifics of the errors in The Fiscal Times article, let’s consider how one could compare whether cooking at home is more expensive than eating at restaurants. The typical cost-benefit analysis for eating in versus dining out goes something like as follows. Cooking a meal at home isn’t free. From a classical economic point of view one should include the opportunity cost of the time needed to buy groceries , drive it home, store it,  prepare a meal, and clean up afterwards. Further, one should include the implicit rental value of the automobile used to transport the groceries and the kitchen and dining room used to prepare and serve the meal.

However, shopping, cooking, and cleaning are not just chores that one is required to do. They are a form of entertainment, social interaction, and a way to share your skills with others as Nathan Myhrvold insightfully states in this Dec 2011 Slate interview. The cook receives utility from hosting a meal, even if it is a regular daily event. Naturally, if one hates to shop, cook, or clean, then there can be disutility as well. When deciding whether to eat at home or dine out, a person will want to maximize the expected utility from the decision.

The Fiscal Times article has two time series charts which I will reproduce below. Some of the problems I found in the first chart:

Examining the wrong factors

The Fiscal Times article briefly mentions some of the above factors, but then totally ignores them when doing the price comparisons. Instead, it mentions differing inflation rates between in-home meals and restaurant meals. Relative inflation rates should be irrelevant to the decision to eat at home or dine out. The author also throws in a few additional factors that also seem to be irrelevant in comparing costs,

“We also didn’t factor in whether one meal or another would be healthier, or friendlier to the environment. But that’s part of the point: Eating right and finding the extra savings that could be had by comparison shopping comes with a time trade-off that many families can’t afford to make these days.”

Hard to interpret charts

The Fiscal Times article has two time series charts which I will reproduce below. Some of the problems I found in the first chart:

  1. For some reason the first chart is labeled Chart 2 and the second is labeled Chart 1.
  2. Chart 2 (the first chart) has two different scales (left scale has a range of 1.4% while the right scale has a range of 0.4%) even though both display values from the same dataset (percent share of consumption). This means the data using the right scale will appear to be more variable
  3. The black arrows both point toward the right scale, though “Grocers” (what’s with the quotation marks?) says it is set to the left hand scale (LHS)
  4. Neither scale shows the 0% origin point or the 100% end point (Note that if the scale did go from 0 to 100%, then there would be no need for two different scales.
  5. Assuming the left scale applies to “Grocers” and the right scale to “Restaurants”, then “Grocers share is always above “Restaurants”. It does not cross as the chart shows
  6. There is no source attribution for the data so no way to judge how valid it is or to review the original data

The second chart (entitled Chart 1) also has several flaws.

  1. The color code has been reversed. Dining out share was shown in the blue line in the first chart, while inflation is shown in gold. Similarly, eat at home share was shown in gold in the first chart, while inflation is in blue
  2. The label for each line has changed. “Restaurants” in the first chart is now called Food away from home while “Grocers” is now Food at home
  3. The use of different labels makes one wonder if the same assumptions, data sets, and cost allocations are used in the two charts and whether the same analysts produced both charts. My guess is no, which means the two charts cannot be used together
  4. As mentioned above, relative inflation rate should not directly impact the consumer’s choice to eat at home or at a restaurant, so this chart isn’t very useful

Nonequivalent price comparisons

The Fiscal Times article includes a slideshow that compares the cost of selected meals at restaurants with the cost of preparing the meal at home. In five out of six cases, the restaurant meal is cheaper.

If you only consider the price of store-bought food to the price of a cooked meal at a restaurant, there is probably no way the prices of food ingredients in a competitively priced retail store could exceed the price in a non-subsidized restaurant. Certain restaurants can serve meals at lower than expected prices because of subsidized food (school lunch programs), volunteer labor (homeless shelters or church meal programs), or subsidized rent (canteen stores or cafeterias in office buildings).

So how did The Fiscal Times get these unlikely results? I think the following errors were made:

  1. The restaurant meal prices are for a single serving while the grocery store prices are for full cans, boxes, or other package. This will provide much more food than the restaurant meal
  2. The grocery store prices are for FreshDirect, a grocery delivery service in New York. Delivery groceries are more expensive than self-serve and NYC is the most expensive city in the U.S.
  3. The restaurant meal prices exclude the tip
  4. The grocery store prices include some prepared deli foods. Grocery store deli food can be more expensive than restaurant food since it is an impulse buy

*An orangery is a British term for a greenhouse. They were mostly used to grow citrus fruit (hence the term orangery). Now most citrus fruit in Great Britain is imported. One of the most famous orangeries is located in the Royal Botanic Gardens in London. It is now used as a restaurant where people dine out, not a greenhouse used to grow oranges that people eat at home.

* * * *

[Update: Expanded the footnote to make clear the irony of an orangery being used as a restaurant.]

[Update2: For a clearer explanation why differing inflation rates should not affect the choice between eating in and going to a restaurant, see this Sep 2013 blog post.]

The rise and fall of the music industry. Image from Bain

Charts showing data over time, called time series, are an excellent way to show trends and to make forecasts for the future. However, time series data may need to be adjusted before plotting to avoid errors in analysis.

First, if the data being displayed is in monetary units (for instance, dollars), then one has to be careful to take into account the effect of inflation. For short periods, omitting inflation isn’t a critical error. However, as the time scale increases, the error can become significant, especially if the time scale includes the 1970s and 1980s when inflation was quite high.

When looking at historical price or monetary data, the unadjusted raw dollar amounts are called nominal values.  The adjusted dollar amounts are called real. (One has to be aware that there are many different inflation adjustments available, but that is beyond the scope of this blog post.)

Second, when comparing country economic data such as gross domestic product (GDP) across multiple years, it should be corrected for population growth. Both the U.S. and the world population are much larger today than 50 years ago while the population of many European countries and Japan are stable or shrinking. Thus, when comparing the well-being of these countries, one should use changes in per capita real GDP. Notice that the U.S. nominal GDP must grow about 4 percent a year just to keep per capita real GDP constant.

Finally, when comparing spending on a particular good or service, the data should be adjusted for changes in household income, consumption patterns, and the quality of the good or service. This is often difficult to do and there are disagreement on the best way to do this. The biggest example is change in house prices. For example, the median house today is much larger than a house 20 years ago. Also, the quality of appliances and materials is much higher than 20 years ago. This is true for the median home and can be very expensive in high-end homes, which will cause the average to be skewed.

Consumption patterns are changing as income increases. The median U.S. and world household income is higher today that it was 50 years ago, even adjusting for inflation). However, much of this gain has been directed toward college graduates who work in jobs that are located in big cities on the east and west coast. This has driven the price of houses upward in cities like New York, Boston, San Francisco, and Los Angeles relative to houses in smaller cities away from the coasts. The interaction between income and house prices is hard to analyze separately.

Rising income also affects the composition of goods and services a household consumes. As a proportion of income, people spend less on food and durable goods and more on entertainment, education, and health care.

Example of a badly drawn chart and a corrected version

In January 2011, Bain & Company released a report on electronic publishing that included a warning that publishers should not repeat the mistakes of the music industry. The warning was illustrated the following chart.

Michael DeGusta picks apart this chart in a Feb 2011 Business Insider article. He notes that the chart makes it look like the music industry grew steadily from 1973 a peak in 1999 and has since fallen about 40%.

However, he corrects the chart for changes in purchasing power and population growth as shown in the revised chart below.

The rise, fall, rise, and collapse of the music industry. Image from Business Insider

This revised chart is much more interesting. It shows that real per capita music sales peaked in 1978 and began to fall until CDs arrived. Sales reached a new peak in 1999, but then fell. Digital music sales have not been able to stem the fall and per capital sales in 2009 have fallen 63% (not 40%) from the level of ten years earlier.

Mr. DeGusta goes on to provide an insightful analysis of why sales of digital music have not been able to replace CDs. Read his blog for more details.

Look at all the pretty circles. Image from Chron. Higher Educ.

by George Taniwaki

A front-page story in Chron. Higher Educ. Jan 2011 claims that newly elected Republican governors are more likely to cut spending than Democrats or even incumbent Republicans. Since education (which includes both K-12 and higher ed) is one of the largest components of state budgets, this implies that the higher education expenditures will fall in states where governors plan to make budget cuts.

As evidence, the article contains the graphic shown above. It plots total projected budget shortfall in 2012 for six states and their higher education appropriation in 2010.

Poor graphic design

There are so many problems with this graphic that it is hard to know where to begin. But I will try to critique it.

1. The most serious problem is that this chart displays a meaningless comparison. There is no a priori reason to believe that higher-education appropriations in FY2010 and total projected budget shortfall two years later in FY2012 should be correlated. Nor should one expect the two numbers to be about the same size. My guess is the fact that the two numbers appear to be the same magnitude for these six states for these two years is just a coincidence.

2. The chart should include more years. If expenditures and budget gap are correlated, then the relationship should be stable over time. Prove it by showing time series data of total budget and higher-education appropriations during previous years. It would be even better if data from previous recessions was available. My guess is that the numbers vary greatly and the relationship disappears.

3. The chart should include more states. The article and the chart predicts newly elected Republican governors will cut higher education budgets more than other classes of governors. But the chart only shows data for six states with newly elected Republican governors. There is no comparative data for incumbent Republicans or any Democrats. Again, if the relationship is due to party affiliation and incumbency of governor, then showing data for all states will emphasize it. My guess is such data would show there is little or no relationship between governor status and budgets.

4. The chart should be adjusted to aid comparisons. The size of state budgets and higher education expenditures vary because of many factors. At a minimum, the data should be adjusted for population. A few other possible adjustments that come to mind are median household income, population of 18-25 year olds, proportion of population with college degrees (presumably, grads will be more likely to favor higher ed spending), enrollment at in-state public colleges (presumably parents of current students will be more likely to favor higher ed spending), etc.

5. The chart should not use areas to represent linear values. Look at the two circles under Ohio. The red circle representing the budget gap of $3,000 million is more than twice as large as the orange circle showing the higher education appropriation of $1,900 million even though $3,000 million is less than 60% bigger than $1,900 million. That’s wrong. The area of a circle is proportional to the square of the diameter. One of the basic rules of drawing a graph (for example, see Edward Tufte’s The Visual Display of Quantitative Information) is to make sure the size and shape of data markers actually assist in understanding the values being measured.

My proposed solution

My proposed improvement to the original chart is shown below. The data come from the same sources used in the Chron. Higher Educ. chart, state budget gaps from the Center on Budget and Policy Priorities, state higher education expenditures from the  Illinois State Univ. Grapevine Project, and political alignment from the Nat. Conf. State Legis. I also added U.S. Census annual estimates of population and U.S. Census counts so that I could calculate per capita state budget gaps and higher education expenditures. The data are posted on SkyDrive in case you want to create your own charts.

My scatterplot shows the cumulative budget gap per capita at the end of FY2009 for each state on the horizontal axis and the increase or decrease in higher education expenditures for state monies (excludes federal stimulus monies) from FY2009 to FY2010. My hypothesis is that deficits at the end of one fiscal year may impact changes in expenditures in the following year.

Each data point is colored to show the political affiliation of the governor (using blue for Democrat and red for Republican). The marker shape indicates if the party changed hands (triangle) or if it did not (square or diamond) in the 2010 election. The green line shows the least squares line through the data (not weighted for state population).

Look at all the tiny dots. Chart by George Taniwaki

I didn’t spend much time analyzing this chart but a few things caught my eye. First, the slope of the regression line is negative meaning that states with the largest deficits tended to cut education expenditures the least. Specifically, California, with the largest deficit at the end of 2009 at $1,004 per capita actually increased higher education expenditures in FY2010 by $7 per capita.

Second, the states with the largest budget gaps at the end of FY2009 were more likely to have Republican governors. They were also more likely to elect a Democratic governor in 2010. The three states that fit this pattern are California, Rhode Island, and Connecticut.

Finally, the states that made the biggest cuts in higher education expenditures in FY2010 were more likely to have a Democratic governor. They were also more likely to elect a Republican governor in 2010. The three states that fit this pattern are Wyoming, Iowa, and New Mexico.

It could be that these correlations are spurious. But my conclusions are no more unreliable than those claimed based on the weak analysis in the original chart.

Much thanks to Susan Wolcott who pointed out the original chart to me.

Figure 1. Frequency of 4 different seasonal greetings. Image from Google labs

by George Taniwaki

Google Books is a project sponsored by search engine giant Google to scan the pages of every book available, convert the scans to text using OCR, and make the resulting text corpus searchable. Not withstanding any remaining copyright disputes surrounding the project, Google has reached an agreement with most of the major copyright holders (authors and the publishers that represent them) around the world. So far, Google has scanned over 15 million books, most of which are no longer in print or commercially available. This database is a treasure trove for history scholars.

Last week, Google released a new statistics tool for the Google Books project called the Ngram Viewer. It it simple to use. You simply enter a list of words or phrases separated by a comma (each called an n-gram and is case-sensitive), the language (American English and British English can be searched separately), the date range (starting from 1500 to 2008, though the number of books is sparse before 1780 which makes the early data very spiky), and the amount of moving average smoothing to apply (long trends are easier to see with smoothing, but the individual yearly data is lost).

The Ngram Viewer is the best time series graphing toy I’ve seen.

There have been lots of stories in the press showing interesting trends in the popularity of certain words and phrases in books. For instance, Jennifer Valentino-DeVries of the Wall St. J. shows that Merry Christmas beats Happy Holidays by a big margin.

Slate’s Tom Scocca has been posting an Ngram of the Day on the site comparing the frequency of words like shopping vs salvation and television vs the Bible. He even does a comparison between words and shows the year in which the two cross in popularity. For instance, anxiety passes shame in 1942.

Figure 2. Frequency of “anxiety” vs. “shame”. Image from Google labs

Here’s a couple charts I created for the n-grams “independence” and “rebellion” in U.S. and British English. I have no idea what conclusions to draw from this data, but it is just begs for an explanation based on unfounded speculation. There is a spike in both words in U.S. books in the 1770s, but no spike in British literature. Independence becomes more popular than rebellion in books from both countries after about 1820. The word rebellion has a spike again in the U.S. from 1860 to 1870. The absolute occurrence of both words are similar in the two countries starting around 1900. Independence shows a spike from 1940 to 1942 and another spike around 1968 to 1970.

Figures 3a and 3b. Frequency of “independence” vs. “rebellion”, in British text (top) vs. American (bottom). Images from Google labs.

For the truly hardcore programmer, the n-gram datasets are available for download from Google. Their use is covered under the Creative Commons Attribution 3.0 Unported license.

The next step is for Google to add its Ngram Viewer toolkit to its Public Data Explorer visualization tool (see Mar 2010 blog post) to allow animations and drill down. I can hardly wait.

* * * *

[Update: I rescaled the first two graphs to normalize the time spans from 1700 to 2000.]

Figure 1. Country fertility rate by life expectancy. Image by George Taniwaki

by George Taniwaki

Time series data are hard to display in a way that shows other relationships. That’s because one generally uses a static 2-dimensional chart. The x-axis is used to display time, leaving only one other axis to show another variable. The display can be greatly enhanced by using animation. Time can flow while the x and y axes can display relationship data or geographic data. This can aid in understanding how relationships vary over time.

Last week, Google announced the release of Google Public Data Explorer. This web-based data visualization tool (because all Google tools are web-based) takes time series data from public sources and provides a way to create animations. Data Explorer allows you to create line charts, bar charts, maps and scatterplots from web data. It has a pretty clear interface to change the axes. For scatterplots you can also change the color and size of the data points.

Google’s animated trend charts are based on technology called Trendalyzer it acquired in 2006 from Gapminder, a nonprofit foundation in Sweden. I mentioned Gapminder in a 2008 blog post that has been accidentally deleted.

Fertility rate by life expectancy

Figure 1 (at top of this blog entry) is an example scatterplot I created using World Bank data for fertility rate by life expectancy worldwide by country. The data covers 1960 to 2007. First note that in 1960, there was a strong correlation between high fertility rate and low life expectancy. Also note the strong correlation between high income and high life expectancy. Many researchers have shown that women are likely to have more children if they fear that some of the children will not grow to adulthood. Note the one outlier among the high income countries that in 1960 had low life expectancy (54 years) and high fertility (5.7). That country is South Korea. If you play the animation, you can see Korea move down and to the right over time.

I’ve marked a few countries that display unusual behavior over time. China is an interesting outlier because in 1960 it was poor with a low life expectancy, but also with a low fertility rate. But if you play the animation, you see that this may have been a statistical anomaly because in 1962, the fertility rate jumps to 7.5. The fertility rate rapidly falls to under 3 as the one-child policy takes effect and continues to fall below the 2.1 replacement level in the 1990s. Rwanda, Timor-Leste, and Cambodia show short, horrifying drops in both life expectancy and fertility during genocide campaigns. Guinea-Bissau shows large fluctuations in fertility rate without a corresponding change in life expectancy. I can’t explain it. The country is very poor and perhaps its health statistics are unreliable, though this is true for many other countries. Lesotho and Zimbabwe are poor countries with high levels of HIV infection and AIDS that are causing both fertility rates and life expectancy to fall. The AIDS epidemic is taking a toll even on wealthier countries like South Africa.

Population by income

Figure 2 shows a scatterplot I created showing population by income in the U.S. by state. I would have liked to have shown income by education, city/rural ratio, or some other correlated variable, but no such variable was available in the dataset. I use log scale for population since there is such a large range in state size. I also use a log range for income because the data is not adjusted for inflation and I want the data range to show the change in income dispersion over time.

Figure 2. State population by income. Image by George Taniwaki

One of the most surprising things about the chart is that over the 40 years the rankings of state incomes doesn’t vary much. In 1969 the poorest state was Mississippi, and all the poorest states were in the southeast census region. If you play the animation, you’ll see some horizontal reordering, but not much. Even fast growing states like Nevada and Arizona don’t change order. They shoot up, but their income ranking doesn’t move much. Same with states with falling populations like Michigan and Ohio. The only exceptions are small states and districts like Hawaii, Alaska, and Washington DC. They zip around like flies. And maybe that explains why the data doesn’t move much. State level data is too coarse and it would be better to see data for the 100 largest cities or some other finer geographic region.

Maps using FlowingData

About a year ago, my friend Steve Duenser pointed me to a couple of nice animations by FlowingData that shows the growth of Target and Wal-Mart. The animations use Modest Maps, a Flash-based mapping tool.

By an odd coincidence, the three biggest discount store chains, Wal-Mart, Target, and Kmart, all started in 1962 which makes a time series comparison of store openings easier. Target is headquartered in Minneapolis and slowly began to expand throughout the U.S., jumping to large metropolitan areas. Wal-Mart grew much more quickly, but was invisible to most people because it concentrated on rural areas near its headquarters in Bentonville. It blanketed the southeastern U.S. before its steady expansion to the rest of the country. The videos showing geographic distribution make the different growth strategies more easy to observe than a tabular list would. It would be even more obvious if the two animations were combined to show overlays.

Figure 3a and 3b. Target vs Wal-Mart. Images from FlowingData

Twitter firehose

Finally, my friend Carol Borthwick pointed out an interesting way of visualizing Twitter feeds across both time and space. An interactive map was shown in The New York Times after the Super Bowl last year. It’s a fun chart and makes you realize that there’s a lot of data on the web that’s just waiting to be mined. Unfortunately, there is no story indicating how the data was collected and organized, what tools were used, or how you can make your own Twitter charts.

Figure 4. Map of Popular Twitter comments in real-time. Image from New York Times

* * * *

[Update: I added a paragraph stating that Google’s animated trend charts are based on technology it acquired from Gapminder.]

Figure 1. Example dataset, sales of three products over seven months. All screenshots by George Taniwaki

by George Taniwaki

Edward Tufte is one of my favorite writers. He’s a specialist in creating information graphics and a proponent of dense data displays. He is the author of several books, most of which I own. In his latest book, Beautiful Evidence, he introduced sparklines, little graphs that can fit in the same line as text. Sparklines are a wonderful way to combine words and graphics to tell a story with statistics.

Here’s an example of how they can help improve your understanding of numeric data. Assume your company has three products called A, B, and C. Here’s a spreadsheet created in Excel 2010 that shows sales for the products over a seven month period along with total sales.

Which product is doing best? Is it Product C with the highest total sales? Or is it Product A, with the highest sales in July? I suppose I could create a graph of the three products, but that would take up a lot of space. Wouldn’t it be nice to create a dashboard that displayed and compared the sales of the three products?

Figure 2. A sparkline of the same data reveals trends

Well, why don’t I create a sparkline? Voilà! Now we can see that sales of Product C are falling rapidly, Product B are flat, and Product A are quite erratic. Pretty nifty, n’est pas? Now I can investigate the reason for these numbers.

Since publication of Tufte’s book, several companies and open source groups have built add-ins for Excel to create sparklines and embed them within a cell of a spreadsheet. In fact, sparklines are so useful that Microsoft decided to implement them in the upcoming version of Excel, as explained in a Jul 2009 MSDN blog post.

I’ve had a chance to play around with this new feature and find it to be quite easy to use. First you select a sparkline type from the Insert ribbon. You select the data range and the destination cell and click OK. This causes the sparkline to be inserted and a Design ribbon to appear on the far right (see below). The ribbon displays quite a few options to make your sparkline pretty. You can group multiple sparklines so that they all have the same min, max, and formatting.

Figure 3. Sparkline ribbon in Excel 2010

I found two annoyances though. First, you only get three choices for chart types, line, column, and win/loss. I wish there were more, especially a scatterplot, since most interesting data is not evenly spaced. Most of the 3rd party sparkline add-ins provide scatterplots, so hopefully Microsoft will add them in the next version of Excel. A good comparison between Excel 2010 and the open source Sparklines for Excel add-in is provided in a recent blog post.

The second annoyance deals with copy-paste. Because sparklines are so compact, it would be nice to be able to embed them in a Word document. However, as you can see in the example below, copying a range of cells containing a sparkline and then pasting it in Word causes the sparklines to disappear. Note that this limitation is due to the way the clipboard works in Office, so will affect all sparklines, not just Microsoft’s implementation.

Figures 4a and 4b. Copying a group of cells containing sparklines in Excel. Resulting paste in Word. Oops. What happend to my sparklines?

Having some software experience, I understand why this happened. But most users won’t and will just be frustrated. The sparklines are not static pictures, they are charts generated from the data in the Excel spreadsheet. Word can’t draw the graphs, so when I paste them, it just ignores them. If I want to retain the sparklines, I need to paste the selection as a graphic. But I don’t really want to paste the entire selection as a picture. I want to paste the cells and the text as an editable Word table and have the three sparklines pasted as 3 separate images inside their respective cells of my table.

Hopefully, the Office team will improve paste fidelity of sparklines in the next version of Office, though my guess it would be somewhat difficult to implement and they may decide it’s not worth the effort.

Tufte’s take on Excel

I wanted to see what Edward Tufte thought of the new sparkline feature in Excel and so visited his blog. It turns out he’s a bit apoplectic and so are his fans. But not about Microsoft adding sparklines to Excel. He’s actually happy about that. Rather, it is because Microsoft filed for a patent covering its implementation. This probably isn’t the place to discuss the validity of software patents. However, I will say it is really easy to get a software patent. All it takes is a few hours of thinking about the best way to solve a computer problem and anyone can file a patent. For instance, check out U.S. patent 7437659 that was implemented in Publisher 2003.

* * * *

[Update1: I clarified my example with screenshots and clarified that the paste problem is not a fault of the sparkline feature.]

[Update2: I just posted a blog entry that talks a bit more about software patents (see Mar 6).]

[Update3: President Obama just named Edward Tufte to the Recovery Independent Advisory Panel. Let’s hope that he can improve transparency and communications in reporting financial matters.]