Regressions: An Electoral College Example

The most recent presidential election — where Donald Trump beat Hillary Clinton in terms of electoral college votes but lost the popular vote — had many people wondering just how electoral votes were assigned to states.

Suppose you read on the internet that the number of electoral votes a state received, was based on its population. In other words: electoral votes (Y) were determined by population (X).

You go on Twitter or Facebook, and post this “fact”. Of course, being social media, someone challenges you to prove it. Here’s how you do it.
You can do this with a statistical technique known as a regression. Here’s how:

Step 1. Collect the Data

Electoral votes and population are already measurable, you just have to find the data, and hope it’s reliable. Fortunately, has the population data and has the number of electoral votes:

Source: ( for the population data and ( for the electoral votes


Step 2. Run a Statistical Operation

If you chart population versus electoral votes, you get the following figure, which suggests using a regression as the statistical operation. A regression finds the best line or curve that fits the data.

A Chart of Population versus Electoral Votes

The chart below show the results of the regression. In this case a line best fit the data. This particular regression was done in Microsoft Excel using Data > Data Analysis > Regression, on the table above.

A Regression for Population vs Electoral Votes. Because the curve is a line, this is known as a Linear Regression.

Step 3. See if the Results are Significant

Statistical operations often include a significance measure. For regressions, this measure is R-squared, which ranges from 0 (not significant) to 1 (significant). In the chart above R-squared is .9991 and since it is close to 1 it is significant.

Step 4. Declare your Hypothesis is a Theory, if Significant

Since R-squared is .9991, and this is a significant value, you can proudly post on social media that you’ve proven your theory:

“population determines number of electoral votes.”

And no one can argue with you, because your theories are backed up with reliable data and appropriate statistics.

An Aside on Predictive Power

What’s even better for you is that your theory is predictive. Let me explain.

When you run a regression, you also get the values you need to reconstruct the equation for the curve. For a line, this is an equation of the form:


If you remember your high school algebra, m is the slope and b is the y-intercept.

You can partly see this equation in the chart above: y=1E-06x+1.9602. I say partly because 1E-06 is really 1.41874E-06. The Excel regression gives the exact values in a table:

Plugging these values in, you get the equation:

ELECTORAL VOTES = 1.41871/1,000,000 * POPULATION+ 1.96

In plain English, take a state’s population, divide by 1 million, multiply by 1.42, add 1.96, and round up.


California’s Population: 37,253,956
Divide by 1,000,000 = 37.253956
Multiply by 1.42=52.90
Add 1.96=54.86
Round up: 55 ← CORRECT

Wyoming’s Population: 563,626
Divide by 1,000,000: .563626
Multiply by 1.42=0.80
Add 1.96=2.76
Round up: 3 ← CORRECT

So the regression yields an equation with the correct value, but what does this equation actually mean? According to

Electoral votes are allocated among the states based on the Census. Every state is allocated a number of votes equal to the number of senators and representatives in its U.S. Congressional delegation — two votes for its senators in the U.S. Senate plus a number of votes equal to the number of its members in the U. S. House of Representatives.

The 1.42 times the population in millions denotes the number of representatives a state has. The 1.92 denotes the 2 senators. It’s quite astonishing that a simple statistical operation was able to discover precisely what that statement means!

Programming 101: Key Mental Models

Programming is about casting spells on machines so that they serve your will.

Okay, okay. So maybe it’s not really magic. But it is magic-like. You have to learn a cryptic language, and you have to speak (type) the symbols in the right order for your spell to work properly.

So why does programming have a reputation for being hard? Because there are many pieces involved, which require many different “Mental Models”.  What’s a mental model, you ask? A mental model is something in your head that helps you make predictions about how things in the world (people, animals, machines, etc.) will react in response to your actions or events in the world.

Suppose you’re a teen and you stay out late—past midnight on a school day. You know your parents will be very upset with you, and possibly yell at you the next day. How do you know that? You have a mental model of your parents! Another example: Don’t stare a dog in the eye because you might make it mad and it will bite you. How do you know that? You have a mental model of dogs.

A mental model doesn’t have to be 100% accurate. It’s merely a guide for your expectations and actions. You create mental models constantly and you constantly update your mental models in response to new information.

So let’s go through the mental models you need to know for programming.

Mental Model: Programming as Communication

Setting aside colorful magic, wizard, and spell metaphors, how should you think about programming?

Programming is communicating directions to a computer. So, you know how you sometimes give driving directions to other people? It’s like that. But instead of driving directions to a person (in English), it’s directions to a computer (in a language like C# or Java) for taking information and either

  • Storing the information in memory, disk/USB drives, across the network;
  • Calculating new information by using information in equations;
  • Displaying the information.

And technically it’s only storing and calculating, because displaying information is a kind of storing of the information on screen or on paper.


So if someone asks you what programming is, tell them:

A. Programming is communicating directions to computers. But instead of communicating with a person, you’re communicating with a computer. Instead of communicating in English, you’re communicating in C# (or Java, JavaScript, C, C++, python, Pascal, or some other programming language).

B. Computers only know how to follow three directions:

  1. store information,
  2. calculate new information, or
  3. display information.


Mental Model: Programming as Communicating With Computers

But how exactly do you communicate with a computer? Can you simply talk to it? Technically yes, but let’s pretend our computer doesn’t have voice recognition like our smart phones. And let’s continue using “communicating with people” as our starting point for understanding programming computers.

When we communicate with other people we simply talk and if they’re paying attention, they hear us and respond appropriately.

When we’re communicating with a computer, instead of speaking words in English, we’re:

  1. Typing code from a computer language into an editor.
  2. Saving our code as a file on the computer. And then telling the computer to
  3. Run the code.


Mental Model: Coding as Storytelling

Almost every well-written story consists of three parts: a beginning, a middle, and an end.  In the beginning, the hero encounters a problem. The middle is spent searching for a solution. And in the end the hero solves the problem.

Similarly, almost all code also has a three-part structure:

  1. Input: getting information from the user, or from storage or from the network
  2. Processing: running calculations on the information
  3. Output: displaying the information to the user, or storing it, which may involve sending the information across the network.


Mental Model: Syntax as Grammar

Just like you can’t randomly mix words in a sentence and expect people to understand what you’re saying, you can’t randomly mix programming terms and expect the computer to run your program without crashing.

English has a grammar, and Programming Languages have a syntax. When you hear the term “syntax” think grammar. Bad syntax leads to your code crashing, just like bad grammar leads to people misunderstanding you (a kind of human crash).


Mental Model: How Software and Hardware Interact

A computer consists of storage (hard drive, usb drive), memory (RAM), a processor (Intel or AMD), and a graphics card (NVidia, AMD). Yes, there’s the network too, but let’s ignore it for now.

  • Your program is kept in storage.
  • When you run your program, it gets moved into memory.
  • The processor reads and executes each line of code in memory.
  • Any code for displaying information gets sent to the graphics card.


Those are the key mental models. Again they are not necessarily 100% accurate, but they should help organize your learning, and keep you from getting lost, as I teach you the syntax of the computer language. We’ll start off with JavaScript & HTML.

The 2D Rotation Matrix

Nick V. Flor • March 20, 2017 • @ProfessorF

Mathematicians on the internet are not only incomprehensible but annoying with some of their conventions: confusing subscripts, over reliance on symbols, etc.  They either don’t know how to communicate or they’re purposely trying to look smart.

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage — to move in the opposite direction.

 – E. F. Schumacher, Economist

One thing that particularly annoys me is how they treat rotation matrices.  This is what almost every mathematician on the internet gives as a rotation matrix:

Cos(angle) -Sin(angle)
Sin(angle) Cos(angle)

The reason I don’t like this rotation matrix is because it describes a clockwise rotation, which is BACKWARDS from what EVERY STUDENT is taught in school. For example, remember how you drew a 45 degree angle in junior high? Starting at the x-axis, you swept your pencil halfway between the x and y-axis, in a counter-clockwise motion, then drew a line. Same with a 90 degree angle, you swept your pencil counter-clockwise starting from the x-axis until it was vertical.

This is the “correct” rotation matrix, where “correct” means it corresponds to how we were taught rotation in school:

Cos(angle) Sin(angle)
-Sin(angle) Cos(angle)

Why mathematicians provide a “backwards” rotation matrix is beyond me. But I’m told one should never attribute to malice that which can be explained by ignorance. So I’ll close this very short essay by pleading with Math departments to force their mathematicians to take a communications or a technical writing course as a graduation requirement.