Showing posts with label Graphics. Show all posts
Showing posts with label Graphics. Show all posts

Tuesday, April 10, 2012

Biplots in Stata

I've been examining qualitative data using biplots, which are readily available in Stata using Ulrich Kohler's excellent package. For example, here is a biplot of a rich data set of poor white men on variables such as drug use and other risk factors:
There are several useful features of biplots: first, they concisely summarize a wealth of information in one graph, including relationships among both cases and variables; second, in line with Tufte's dictum, biplots have a high data-to-ink ratio; third, since cases are not directly modeled, biplots help with integrating qualitative and quantitative data (i.e., cases are not "hidden" by a hyperplane, as in a classical linear regression model); finally, there are absolutely no frequentist statistics to deceive the analyst.

Sunday, March 25, 2012

Popularity of Programming Languages

As you can see, R is relatively popular (but more so on StackOverflow than GitHub):

For the original graph, click here. This scatter plot is a reminder that R is useful to learn not only for statistical modeling (since there are so many excellent packages available), but also as a way to become familiar with programming more generally.

Tuesday, March 13, 2012

Scatter Plot Matrix in R

Stata has a large number of graphics capabilities (and I highly recommend Stata over other statistical packages for a variety of reasons), but in a few instances R is more useful. In particular, I find R useful for creating beautiful scatter plot matrices and 3-D graphical displays. To my knowledge, currently these kinds of graphics are very difficult (if not impossible) to create in Stata 12. What I like about scatter plot matrices is that can have a high data-to-ink ratio, packing together fitted lines, scattered data, histograms,  correlations (proportional to the size of the correlation), and statistical significance "stars" (since reviewers seem to like them). Moreover, I like that all the information effectively puts the "stars" associated with statistical significance in appropriate context: there is an incredible amount of variability in the size of correlations and distribution of data among all the "three-star" correlations, underscoring the limited usefulness of statistical significance as a tool for understanding the social reality given to us by data.

Sunday, March 11, 2012

3-D Scatter Plots Redux

One weakness of Stata versus R is the lack of 3-D graphing capabilities, in particular 3-D scatter plots. However, with some modifications, Stata can indeed provide a suitable substitute for R in most graphical problems, as shown here (I use the infamous auto data set available in Stata with the sysuse command). The main weakness is that the x-y and y-z planes do not have grid lines; nevertheless, this graph is another indication that Stata's graphing capabilities are much stronger than many R users (and perhaps even Stata users) realize. Here's the graph:

Thursday, March 08, 2012

Ternary (or Triaxial) Plots

One rarely-used graphic is the ternary (or triaxial) plot, which is a very useful way of examining a tripartite decomposition of a variable. For example, the graph in this post displays the composition (which I constructed in Stata using Nicholas J. Cox's commands) of an economy over time. Note that the three percentages add to 100 (or, equivalently, the three proportions add to 1).


It's a bit surprising that this graph appears so infrequently; it would appear to be especially useful for political scientists showing voting fractions over time (with the three most prominent parties for each axis), economists examining the composition of an economy (such as above), or sociologists examining over-time trends in any three-part categorical variable (such as "agree," "disagree," or "neutral" on a question of values or attitudes).

However, note that simply because a graph looks like it's a ternary plot does not make it one! For example, Junk Charts dissects this pseudo-ternary plot in the New York Times.

Monday, March 05, 2012

Visualizing a Correlation Table

Correlation tables are ubiquitous in social science research, but very rarely they are visualized. As I've emphasized in previous posts, I'm a strong advocate for visualizing data and models whenever possible. For example, for my research I graphed correlations using Adrian Mander's plotmatrix command in Stata. Using Mander's package, I could create a graph that clearly shows all the information in a parsimonious way; moreover, unlike a correlation table, correlation patterns are intuitively grasped from the shading of the cells, and there is an implicit emphasis on the correlation size rather than statistical significance.

Sunday, March 04, 2012

Why Models are Not Data

In doing research, sometimes it can be easy to think that the models one is using are in fact the data -- but this is clearly not true. Even the mean of a sample of data is a model of the central tendency of the data, and not the data itself. One clear example of why models are not data is Anscombe's quartet. For example, take the following:

What is remarkable about this quartet is that for all of these scatter plots the mean of x is the same (exactly), the variance of x is the same (exactly), the mean of y is the same (to two decimal places), the variance of y is the same (to three decimal places), the correlation between x and y is the same (to three decimal places), and the linear regression equation is the same (to two or three decimal places). In other words, the models of the data (e.g., mean, variance, correlation, etc.) are the same, but the data are not!

So what's the solution? As I've mentioned in previous posts, graphing the data is crucial, because we're forced to confront the actual data, and not models of the data.

Friday, February 24, 2012

3-D Bar Graph "Masterpiece"

I encountered this post on how to turn a "boring" bar graph into a 3-D "masterpiece." What's striking to me is that most of the people commenting actually want to replicate this graph, even though it violates the basic principles of effective statistical graphics, according to Tufte and others. For example, the 3-D effect distorts the information displayed by the "boring" bar graph, making comparisons difficult, and the visualization effects distract from the underlying data as conveyed by the differing heights of the bars. Here's the "masterpiece" in its full glory:

Thursday, February 23, 2012

Violin Plots

Violin plots are an excellent way of displaying the distribution of a continuous variable by levels of a categorical variable. In essence, violin plots are box plots and kernel density plots combined. For instance, here are a set of violin plots from Stata's auto data:

These same data could also be displayed in tabular form, but again this is case in which a graphical display is a more effective way to examine and convey the patterns in the data.