6
$\begingroup$

Disclaimer: I know absolutely nothing about statistics. I've had trouble searching for answers to my question, as I don't have much knowledge about the terminology of statistics.

I'm currently trying to plot a graph with two sets of values that are widely different. This doesn't really matter, but I'm doing this in Python with the matplotlib library.

One of my sets of values is a company's stock price over several days. My second set of data has much, much smaller values, but I'd like to be able to compare both lines side by side. I'm more interested in the magnitude of the changes than in the actual values.

For the moment, the only idea I've had is the following:

  • Average the first values.

  • Average the second values.

  • Divide the first average by the second one, as to find a coefficient.

  • Divide every single value in the first set of data by this coefficient.

Now, this looks fine, but I don't know anything about statistics, so is this correct? If it isn't, what's a better way to do it?

$\endgroup$
  • 2
    $\begingroup$ A first start would be to normalize each series by subtracting the mean from each data point and then dividing each point of the resulting series by the standard deviation. Do this separately for each series and then plot them together. $\endgroup$ – cardinal Jan 13 '12 at 1:30
7
$\begingroup$

If you are interested in the changes as a fraction, then simply plot the logarithm of the values. A fixed distance in log space is a fixed fractional change, so if one line is steeper than the other it is changing more rapidly.

The log scale may also allow you to conveniently get both sets of values onto one graph without having to normalize the values in any way.

$\endgroup$
3
$\begingroup$

You ask "is this correct?" and "is there a better way to do it?" but the answers to these questions depend on what exactly you are trying to do. A statistical graph is "wrong" only if it does things like distort the data; it is "bad" if it is hard to read, etc.

Are you interested in the difference between the two stock prices? Then subtract one from the other and plot that. Are you interested in the ratio? Then divide the larger by the smaller and plot that. (Cleveland showed that it is easier to interpret a single line than the relationship between two lines; his example was imports and exports from some country (England, IIRC) over time).

Do you need both series? Well, you could standardize (see earlier answers) or you could just multiply one series by some convenient number (be sure to state this!) - the latter may be easier for your audience to grasp.

I highly recommend William Cleveland's books.

$\endgroup$
  • $\begingroup$ +1 Peter Flom. Cleaveland has two books, which one would you recommend if cost is a constraint to two purchase both books. $\endgroup$ – forecaster Jan 7 '15 at 1:11
  • 2
    $\begingroup$ @forecaster The Elements of Graphing Data is the timeless classic people are usually referring to $\endgroup$ – shadowtalker Jan 7 '15 at 1:35
  • $\begingroup$ @ssdecontrol, thanks so much for the recommendation. $\endgroup$ – forecaster Jan 9 '15 at 20:49
3
$\begingroup$

In the financial press, a common way to display two or more time series (such as GDP or - relevant to the original question - stock prices) in a way that allows changes over time to be compared, is rebasing. A base time is selected, and the values of the series are scaled so that they are all 100 there. If the first series is €40 in the base period, but €48 later, these become 100 and 120 (which indicates a 20% rise since the base period). If the second series was €500 in the base period and €450 later, these become 100 and 90 (showing a 10% fall). Here is an example in the Economist (in case that is paywalled, this is link to the image itself).

Alternatively, just the percentage changes might be shown. So in my example, the first series would start at 0 and move up to 20, while the second series will start at 0 and move down to -10. Here is an example from the Financial Times (image link).

Usually the first time included in the graph, on the far left, is chosen as the base period. Occasionally we see plots rebased so the final value is 100, like this one (taken from this BBC article). I've also seen charts which have been rebased to a period in the middle of the graph. This might make sense if you were comparing GDP series for two countries before and after a financial crisis - to make the results comparable you might rebase them to the period with the peak pre-crisis GDP. Note that the faster-growing economy in the run-up to the crisis will have a steeper graph to the left of the crisis, but this means its graph will dip below the one it is being compared to. To someone who doesn't understand how to interpret the vertical scale of the graph, this might suggest it is the weaker economy prior to the crisis! This sort of confusion is avoided by rebasing to the left, but that is not always appropriate.

There are some advantages to just plotting the ratio of the two series. One is that it is possible to extend this concept to more than two series on the same graph (see this example from BBC - taken from this article).

But beware of the disadvantages of rebasing - the choice of the base period is important, because it makes the series arbitrarily cross there. Generally people rebase so that the graphs all start together at 100, and the series will appear to cross over again if they ever return to their "original" ratio. But unless there is a very good reason to start the graph of the series there - perhaps because the stock price graph begins at flotation, or a GDP graph begins at national independence - then the starting point doesn't really represent anything genuinely original or special. If you'd made a different choice about where in the data series you start the graph from, then features like subsequent cross-overs can look quite different. This kind of arbitrary crossing-over is one reason that people are skeptical of charts with two separate y-axes for two time series. I would also second Peter Flom's answer, that it is easier to interpret one line than two, so if only the ratio of the two series is interesting, then only the ratio of the series need be plotted!

$\endgroup$
1
$\begingroup$

Try plotting both numbers using different scales for each one's Y-axis? (I don't know Python's matplotlib library, but I'd be suprised if it can't handle that.) The idea would be to make the Y-axis for the stock prices range between the lowest and highest prices seen, and the range for the other values to also be the lowest/highest values seen.

$\endgroup$
  • 1
    $\begingroup$ If the two series are to be plotted on the same graph, this practice is quite controversial. Hadley Wickham refuses to implement this on ggplot2 because he feels it is misleading, and his opinion (and the article he cites) is worth a read. For putting the two series on different graphs (e.g. on a 1-by-2 facet grid) would be less controversial but might make the comparison a bit harder. $\endgroup$ – Silverfish Jan 7 '15 at 0:36
  • $\begingroup$ Having said that faceting may make comparison harder, this kind of panel/trellis chart does have some important fans - see Tufte's "small multiples" and also "sparklines". $\endgroup$ – Silverfish Jan 7 '15 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.