How many data types can you name?
By: Cassie Kozyrkov
Tags: Math, Statistics, Editors Pick, Technology, Data Science

How many data types can you name?

Close your eyes and try to name as many data types as you can. Got them? Now let’s play bingo! (Look for the bolded words.)

Data types in statistics and analytics

Back when dinosaurs roamed the earth, it was fashionable to kick a statistics textbook off with a first chapter on the basics of data.

Don’t worry, it’s not this complicated of a data taxonomy. Some of these critters look wonderfully derpy. Image: SOURCE.

To make sure that students had something to memorize for their first test, opening chapters usually included some jargon for different kinds of data:

Continuous data (measured, not counted), e.g. 176.5 cm (my height), 12% (free space on my phone), 3.141592… (pi), -40.00 (where Celsius meets Fahrenheit), etc.

(measured, not counted), e.g. 176.5 cm (my height), 12% (free space on my phone), 3.141592… (pi), -40.00 (where Celsius meets Fahrenheit), etc. Discrete data (counted, not measured), e.g. 1 short story, 6 words, 2 baby shoes, 0 times worn, etc.

What is counting versus measuring? Poetry. It sounds cute if you’re a beginner, until you recall a lesson from elementary school about how integers are real numbers too. (And is any measurement really continuous if your instruments aren’t precise? And aren’t those instruments just counting?) Or you take a math class on measure theory, whereupon your head explodes. Never mind, you’ll get the gist if you don’t think about it too much.

What’s that in the discrete data example? “For sale: baby shoes, never worn.” That’s the whole six-word story, attributed to Ernest Hemingway. Image: SOURCE.

If your Baby’s First Stats book didn’t make the continuous-versus-discrete distinction, it might have preferred these terms:

Numerical data , e.g. 176.5 cm (my height), 12% (free space on my phone), 3.141592… (pi), -40.00 (where Celsius meets Fahrenheit), etc.

, e.g. 176.5 cm (my height), 12% (free space on my phone), 3.141592… (pi), -40.00 (where Celsius meets Fahrenheit), etc. Count data , e.g. 1 short story, 6 words, 2 baby shoes, 0 times worn, etc.

, e.g. 1 short story, 6 words, 2 baby shoes, 0 times worn, etc. Categorical data, e.g. cat, cat, dog, cat.

Difference between count and categorical? Meh. It’s a matter of perspective and aggregation level. Taking the column sums would have given us 3 cats and 1 dog.

Categorical data can be divided into:

Binary data (only two categories), e.g. Yes, No.

(only two categories), e.g. Yes, No. Multiclass data (at least three categories), e.g. Animal, Vegetable, or Mineral?

You might also have been taught jargon like:

Nominal data (conveys identity), e.g. water, tea, coffee.

(conveys identity), e.g. water, tea, coffee. Ordinal data (conveys rank), e.g. small, medium, large.

(conveys rank), e.g. small, medium, large. Cardinal data (conveys quantity), e.g. Tall, Grande, Venti.

When the data are nominal, they identify a category but they don’t carry any notion of rank or scale. Ordinal data tells you about order (thank goodness for sensible jargon), but — as with clothing sizes — the distance between small and medium might have nothing to do with the distance between medium and large. Cardinal data means you’ve got a constant interval between ranks, as with Starbucks cups (where the increment is 4 ounces of liquid: Tall = 12 oz, Grande = 16 oz, Venti = 20 oz). Cardinal data can easily be reduced down to ordinal or nominal, but you need context (outside data / experience) to attempt augmenting your data in the opposite direction. If I tell you that I drank “a lot of espresso” this morning, you’d have to know me better to understand what that actually means.

You may have learned to split numerical data into:

Interval data (no true zero, so talking about ratios sounds daft), e.g. temperature in Celsius/Fahrenheit (100°F is not “5 times as hot as” 20°F).

(no true zero, so talking about ratios sounds daft), e.g. temperature in Celsius/Fahrenheit (100°F is not “5 times as hot as” 20°F). Ratio data (there is a true zero and ratios make sense), e.g. temperature in Kelvin, length, weight, amount in your wallet, etc.

The reason students are taught this ratio versus interval distinction is to remind them to be careful with mathematical operations on quantities of arbitrary scale, since that’s something only someone half as smart as you would do.*

Be careful with mathematical operations on quantities of arbitrary scale.

If you keep your wits about you and your nonsense radar tuned, you needn’t worry about this distinction.

Please don’t do silly math with scales that have arbitrary zeroes. Image: SOURCE.

Another subcategory of numerical data has to do with imperfect information. Imagine attempting to record the IQ of an alien whose intelligence so far outstrips ours that we can’t begin to measure it.

Missing data (record it as empty space), e.g. {human 1: 103, human 2: 114, human 3: 94, human 4: 164, alien: ___.}

(record it as empty space), e.g. {human 1: 103, human 2: 114, human 3: 94, human 4: 164, alien: ___.} Inaccurate data (make something up), e.g. {human 1: 103, human 2: 114, human 3: 94, human 4: 164, alien: 165.}

(make something up), e.g. {human 1: 103, human 2: 114, human 3: 94, human 4: 164, alien: 165.} Truncated data (pretend it never happened), e.g. {human 1: 103, human 2: 114, human 3: 94, human 4: 164.}

(pretend it never happened), e.g. {human 1: 103, human 2: 114, human 3: 94, human 4: 164.} Censored data (instead of the exact value, record it as “anywhere in a range”), e.g. {human 1: 103, human 2: 114, human 3: 94, human 4: >160, alien: >160.}

Note that sometimes censored data will be recorded without any kind of > indicator, so what you’ll see is relatively few 159s and then a whole surprise of 160s. Aha! That’s the calling card of data censorship.

Not all data you encounter will be accurate or useful. In fact, most of it will be dodgy. Keep your wits about you.

It’s bad enough when our tools aren’t able to fulfill our measurement wishes, but things get even stickier when bad data has a cognitive/social origin. Humans make data, so it tends to inherit the (potentially flawed) perspectives of its authors… which brings us to the concept of biased data. That topic deserves its own set of articles, available here.

Getting fancier

The discussion above is in danger of giving you the impression that a datapoint always fits in a single number and that every observation is hermitically sealed from its neighbors. Not so! Time for more jargon:

Univariate data (fits in a single number), e.g. your height.

(fits in a single number), e.g. your height. Multivariate data (too complicated for a single number), e.g. the set of measurements a tailor needs in order to create a custom suit for you.

In moving from univariate to multivariate, you’ll be expanding your view from random variable to random vector… but why stop there? There’s a whole array of fun to be had with a random matrix. By the way, you’re looking at a random matrix at this very moment, since that’s how images are stored.

The world’s least mathematical introduction to linear algebra terminology. Image: SOURCE.

If random vectors are too bland for you, feel free to play with random sequences or random processes instead.** These are sequential data, characterized by an obsession with order. Examples include songs, stock market data, reinforcement learning training sets, and predator-prey systems. What makes order so important is that the previous step in the sequence or process has an important influence on the next one. In other words, we’re talking about the kind of dependent data (as opposed to independent data) where nearby entries of the vector are correlated.

The stock market is a classic source of time series data examples.

When it comes to real-world sequential data, the culprit behind the correlation structure is often either time (time series data) or space (spatial data) or both (spatiotemporal data). Some people prefer the term panel data for multidimensional time series data. Special cases include longitudinal data and cross-sectional data.

While we’re enjoying this bingo frenzy, I’d better not forget to mention sample data versus population data as well as some provenance-related terms, such as structured data versus unstructured data, primary data versus inherited (secondary) data, captured data versus exhaust data, raw data versus processed data. If you’re interested in snarky explanations, head over to my article on data provenance.

Data types in computer science

If you’re a computer science enthusiast, your instinctive answer is probably, “The number of data types depends on the programming language.”

In this context, data types are much stricter, defining the operations that can be done and how those data are stored. The tricky thing is that there’s usually more than one way to skin, er, *store* a cat and the whole question of the “right” data type boils down to what’s efficient given the underlying rules of the language you’re using.

For example, if you were working with a five in a language like C++ or Python, your needs dictate whether you’d choose to store it as int (5) or as float (5.000000000000000) or some of the other types from the bingo boards below.

Different programming languages have different data types. Here’s the one for Python. SOURCE.

Different programming languages have different data types. Here’s the one for C/C++. SOURCE.

Additional precision often comes at a memory cost, so when you’re working with data at scale, choosing the leanest data type for your needs could yield huge savings in terms of hardware cost/time. Similarly, you might try to save on memory use in C++ by storing that 5 as a char (just the character “5”, costing 1 byte instead of 4) but then you’d have to deal with the annoyance of converting it back to some kind of number in order to do math with it. This can also be costly in terms of hardware and time. If you’re considering becoming a professional software engineer or a data engineer, you’ll need to commit the effort to become one with your languages’ data types.

Statistics versus computer science

In computer science, the pedagogical focus is on preventing the computer from doing stupid things with data. In statistics, it’s about preventing *you* from doing stupid things with data.

These statistical terms are useful as clues about the information you can tease out of your data and which mathematical operations will produce nonsense.

In other words, the various statistical terms are useful as clues about the information you can tease out of your data and which mathematical operations will produce nonsense. Consider, for example, all these different ways of recording the day of the week:

If you think column 3 is cuckoo bananas and no sane person would do it (much less take the average), think again. I’ve had the joy of finding exactly this kind of mess while debugging professional machine learning code.

From the Python coder’s point of view, you’ll be mumbling “integer, string, float, string (okay, date, but… string), integer” as you read the columns. When you peer at it through a statistics lens, you’ll struggle to restrain a few expletives.

The bottom row shows what happens if you try to take an average. When it works, you’ll wish it didn’t. While you might have chosen to store the day as an integer (see how that November date messes with the last column?) or as a float with week.day (the average in column 3 says week 1 day 9), that’s not what the information, ahem, means.

When you’re in the data science game, it’s vital to think about the kind of information you’re working with so you can torture it humanely, only subjecting it to transformations that preserve meaning.

It’s your responsibility to prevent your tools from committing crimes against common sense.

If you shove your data into someone else’s code, it will mindlessly attempt to follow instructions written by some caffeine-guzzling engineer who knows nothing about your situation. Don’t expect the software to tell you that you shouldn’t take an average of 1.1 through 2.7. That’s on you.

Analogs

Data types in statistics typically have analogs in your favorite programming language, though it’s not a one-to-one mapping (there’s an art to choosing data types to make your code purr). To oversimplify, continuous data maps nicely to the floating-point number, count data to the integer, binary data to the Boolean, and categorical data to the enumerated type. Everything has a buddy on both sides of the fence, though I’ll be the first to admit that multiple names for the same thing doesn’t make learning all this any easier. The good news is that you needn’t memorize anything (unless your professor sets silly exams) since you’ll naturally absorb what’s useful as you make use of it.

Summary

In computer science and engineering, the concept of data types is strict, since each programming language comes with concrete rules on how data types are treated, what you can do with them, and how they’re stored.

In computer science, it’s about preventing the computer from doing stupid things with data. In statistics, it’s about preventing *you* from doing stupid things with data.

In statistics, data types relate to how we think about the information conveyed by a quantity rather than how that quantity is encoded (although eventually, one hot day of coding, we’ll find ourselves rolling up our sleeves to ponder the encoding as well).***

Footnotes

*Try not to take my jokes too literally; IQ is another example of interval data. And it’s also an example of major issues with bias and measurement validity, but that’s a story for another time.

**Yes, you can upgrade to matrix versions here too, e.g. video data. These are called random fields. Other extensions of the random vector include random networks, which let you play with a bunch of random vectors / matrices / processes all linked by a graph. You’ll know you’ve arrived in this part of town when the jargon includes “random trees” or “Bayesian networks” or “multilevel models.”

***One hot encoding is the standard approach for converting categorical data (column B below) to a (numerical) format that works with most machine learning tools (columns C and D).