HTML/JavaScript

Monday, March 31, 2014

NCAA bracket odds

We're down to the "Elite 8" in the 2014 NCAA tournament. I've been hearing some discussion of the odds of filling a "perfect bracket." It has been discussed at On Point Radio, which I listen to frequently. The program aired on March 26, 2014. USA Today has a youtube video up of a DePaul math professor estimating the odds. He comes up with an estimate that a savvy bracket filler has about 1 in 128 billion odds of filling in a perfect bracket. It's March Madness.

Then I thought to myself, how did the professor get there? USA today does not go into the details. I wonder what the odds are of finding real math in USA today on a given today? Probably slimmer than 1 in 1 million. I'll point out that precision does not matter when we're finding astronomically long odds. I'll call this a ballpark estimate. With probabilities this small, the upshot is that you'll never win. It's worse than playing lotto.

Let's do some math. Sixty-four teams compete in the NCAA tournament. There are six rounds, including the final game. So we have 32+16+8+4+2+1 = 63 games played. In order to fill out a perfect bracket, I have to choose 63 winners correctly. If we were flipping a coin, there are


possible sequences of 63 coin flips. A bracket filler would have odds of about 1 in 9 quintillion of filling out the bracket correctly. There is no hope of winning here.

But we are not flipping a coin. Suppose you're a savvy odds maker. You know which teams are ranked highest in the tournament. You study basketball statistics, etc. I will quantify your savvy thusly: you have a 90% probability of picking a winner of 16 games in the first round. You have a 90% probability of picking a winner of 16 games in the second round. Your probability of picking all the other winners is 50/50, the same as flipping a fair coin. What is your probability of filling in the bracket correctly? You have to correctly choose 63 mutually exclusive events with a probability of .9 for 32 of them, and .5 for the other 31. Since the events are mutually independent, the individual probabilities multiply. That gives us a final probability of


or odds of
.

This is roughly twice as much probability as the DePaul math professor estimated. So, my hypothetical savvy guesser had roughly twice as much savvy, but he is still hopeless when it comes to filling in the bracket correctly.

Here is some R code to calculate and print the numbers here. We're right on the edge of R's basic precision, where p could be rounded down to zero. If I change the numbers slightly, I would need to use the Rmpfr package (or logarithms) to get a non-zero printout.

> p=c(0.9,0.5)
> games=c(32,31)
> prob=prod(p^games)
> prob
[1] 1.598934e-11
> 1/prob
[1] 62541682939
> format(1/prob,dig=3,sci=T)
[1] "6.25e+10"


Friday, March 14, 2014

Calculating pi with a random number generator

It's π day (3/14), so let's estimate π, the ratio of circle's diameter to its circumference, with a random number generator. This post is a blatant ripoff of Rhett Allain's post on the occasion of π day 2010. We're doing this just for fun, of course. The method used here is terribly inefficient. No doubt anyone reading this knows that google can give you a slice of pi. It's also easy to find a page with 100,000 digits of pi. Most calculators and calculator apps have a π key, of course. If you can't find a few digits of π, you're not looking very hard. There is a very nice page at Mathworld that is loaded with approximations for π. Check it out.

Ok. Let's get down to estimating the first few digits of π with a random number generator. I'll be using R and the default random number generator in R, which is the "Mersenne twister." It's used in R, python, php, ruby, and many other software systems. It has a period of $2^{19937} -1$; its "seed" is a vector of 626 integers. To be technically accurate, we should refer to it as a pseudorandom number generator (PRNG), since it is an algorithm. It is not truly random since its output is determined by initial conditions.

To calculate π, we'll focus on the first quadrant of the x,y plane within the square (0,0),  (1,0),  (1,1), and (0,1). We'll use our PRNG to generate $N = 2^{17}$ random pairs and then graph them. We'll be using a uniform random number generator, of course. Here is the R code used to generate the graph:


N=2^17
c1=6
r = function(z) { return(sqrt(z[1]^2 + z[2]^2)) }
x = runif(N) ; y = runif(N)
color = rep(c1,N)
dists = apply(cbind(x,y),1,r)
color[dists > 1] = 1
plot(y ~ x, pch=".", col = color)
ins = length(color[color == c1])
est = 4 * ins / N
cat(sprintf("estimate for pi = %.4f",est))



The apply() function is used here to calculate the distance from each point to the origin. Our interface to the PRNG is runif(), which returns a random uniform deviate. If the point lies within the unit circle, it is colored. If it lies outside, it will be black. When run, the following graph is generated:

Now, since the points were chosen with a uniform distribution, we expect a fraction π/4 of them to be colored, and 1 - π/4 to be black. The program simply counts the number of colored points and estimates π as 4 times this number divided by N. When I ran it just now, the program printed

estimate for pi = 3.1428.

So that's our Monte Carlo estimate for π.

Sunday, March 2, 2014

Hyperreal Numbers and Calculus without Limits

Once upon a time, I stumbled into a hyperreal number field on the internet when searching for something related to calculus. Maybe I was calculating the volume of a Steinmetz Solid? The so-called hyperreals can be used to develop the calculus without limits. The claim is made that, perhaps, the use of "infinitesimals" is less confusing than the concept of the limit for struggling calculus students. In fact, there is a calculus text using this approach that one can download for free from this page. The author, H. Jerome Keisler, is a professor emeritus of mathematics at UW-Madison.

What are the hyperreals? They are an extension R* of the field of real numbers, which is usually denoted by RR is a subset of R*. Without going in to too much detail, R* is obtained from R by adding in infinitesimals and infinitely large numbers. An infinitesimal number is infinitely small. What does this mean? For every real number a, a number ε > 0 is infinitesimal if -a < ε < a. That's it. In contrast, 1/ε is infinitely large (a "hyperinteger"). Conceptually, hyperreals are similar to complex numbers. However, unlike the complex numbers, they are depicted in one linear dimension, not a two-dimensional plane. The nitty gritty is all in Keisler's book. With the concept of the infinitesimal available, we can have the hyperreal quantity x + ε that is infinitely near x. This hyperreal x + ε can then be used to formulate the derivative, which won't be surprising to anyone who has studied calculus.

Here's figure 1.4.3 from Keisler's book. An "infinitesimal microscope" has been used to zoom in on the hyperreal number line:


The infinitesimal microscope is a captivating pedagogical concept. I claim that it's easier to grasp than the concept of a limit. Children learn about microscopes in grade school. Maybe they learn about it nowadays by zooming in on their iPads. In any case, R* is a useful mathematical concept that can be used to formulate the calculus without that ungainly Σ thing. All you need is a little ε guy. :-)  Keisler's book provides more than 800 pages of evidence.

The history of infinitesimals is interesting. The epilogue [pdf] to the aforementioned calculus text lays out the story. Archimedes anticipated both infinitesimals and the ε, δ approach of limits in some of his proofs. In the 17th century, the modern calculus was developed independently by Newton and Leibniz. In his reasoning, Newton used both infinitesimals and the concept of a limit as well as the so-called velocity method. Leibniz used infinitesimals. So there were three competing methods for doing calculus: infinitesimals, limits, and the velocity method. Jumping ahead (see Keisler's epilogue for whole story), the first truly rigorous treatment of calculus was formulated by Karl Weierstrass in the 1870's. I believe it was Weierstrass who introduced the  ε, δ notation that we still use today.

There can be little doubt that the limit approach is firmly entrenched in the current pedagogy. Other than Keisler's book, I am unaware of any other textbook that uses this approach. I never heard it in Altgeld Hall or Van Vleck. Mathematics teachers should be aware of this alternative approach and should consider using it to introduce students to derivatives and integrals.

Thursday, February 20, 2014

Raising the Minimum Wage

President Obama, in his recent State of the Union (SOTU) speech, called on congress to raise the federal minimum wage and to start reducing the enormous inequality that has arisen in this country in the last 30 years. The people at the top of the economic food chain in this country are doing fantastically well right now, in fact they are better off financially than any similar cohort has been in the history of the world. Congressman George Miller (D-CA) and Senator Tom Harkin (D-IA) have introduced the Fair Minimum Wage Act of 2013, which would raise the minimum wage to $10.10/hr.

As Robert Reich has pointed out, this is a no-brainer. Republicans are claiming that raising the minimum wage will cost jobs. This is untrue. As Reich points out in the 2:29 video embedded below, minimum wage jobs are service sector jobs such as flipping burgers or changing the linen as a hotel maid. Business owners can easily absorb the cost of an increased minimum wage for pennies on the dollar, which they would pass on to customers. Furthermore, workers on the bottom rungs of the economic ladder spend everything they earn. The dollars spent on increasing their wages have an immediate stimulus effect.


Economists agree that raising the minimum wage would reduce poverty. Arindrajit Dube, an economist at UMass Amherst, has calculated that raising the federal minimum wage to $10.10/hr could lift 4.6 million people out of poverty. Of course, republicans are currently howling that any raising of the minimum wage will wreck the economy. There is no evidence to support this doomsaying. What we aren't told is that the real value of the minimum wage has been falling now for decades. This is illustrated by the following graph:


The blue points are the federal minimum wage by year in 2009 dollars. The maximum value occurred more than 45 years ago in 1968. The value was $9.86. This was a time of great economic prosperity in the US. The dollar values were computed by dividing wage values by the consumer price index (CPI) for a given year. The CPI was normalized to 2009. The blue curve is a lowess smooth computed in R with a "smoother span" of 0.4. Note that it has leveled off. The red data points are federal minimum wage data before the CPI adjustment. The first data point in 1938 was $0.25 after the minimum wage was instituted by Roosevelt. The 1938 value is the minimum value on either curve.

Looking at the graph above, one notices that the smoothed fit from 1938 – 1968 is quite linear. It's a simple matter to fit a straight line to these data using R and then extrapolate. Here is the result in graphical form. R-squared was 0.85 for the linear fit with lm.
Minimum wage in real dollars with linear fit 1938 – 1968

Where does this take us? If we had stayed on that linear growth curve, the minimum wage in 2013 would have risen to $18.10!

Reich has been hammering on economic inequality for years. He has put his arguments into movie form, Inequality for All. Watch the official trailer or youtube if you dare. Raising the federal minimum wage to $10.10/hr would put it back to where it was back in the 60s before it started falling. It's the right thing to do for the poorest Americans.

For the first graph above, the data and the R code used to generate it.

[Apr 7, 2014. Edited to remove an html display bug]

Wednesday, February 19, 2014

Spreading misinformation with a bladder

Ray-finned fish are know as actinopterygii. They are the dominant class of vertebrates; most fish species are ray-finned fish, if we're counting species. If we are counting individual fish, I suspect the actinopterygii would not be so dominant. This is one of my favorite ray-finned, fish, the smallmouth bass:



Ray-finned fish have an organ known as a swim bladder or an air bladder. Here is an image from wikimedia of an air bladder:



This organ in a ray-finned fish is homologous to the lungs of higher vertebrates such as apes and horses. So, why bother posting about the swim bladder? Because it is an object used to spread misinformation. It showed up in a class I participated in recently. The swim bladder has been used in a teaching method known as the discrepant event. Here is the discrepant event I became aware of:

True or false?
Sink or Swim Scenario
When a largemouth bass (Micropteras salmoides) [sic] takes air into its swim bladder from the gills, the fish rises in the water. When it releases air from the swim bladder, it sinks.
Students will likely answer that this is true; however, it is actually false because the opposite occurs. When air is taken in, a largemouth bass sinks; when it releases air, it rises.
The appropriate equation for this question is: D = M/V
(D = density, M = mass, V = volume)
When the fish takes air into its swim bladder, the fish’s density, or specific gravity, increases to above 1. The air weighs more than the vacuum created when it is released. Since the specific gravity of fresh water is about 1, the fish sinks. Thus, the fish is able to sink, rise, or suspend itself by changing its density.
This is unphysical nonsense. Unfortunately, it is easily found with a google search. The author has abused Archimedes' principle to reach the wrong conclusion. The first alarm bell is set off by the misspelling. More to the point, we have the statement that "air weighs more than the vacuum created when it is released." Really? A bass has an internal vacuum pump? The author is telling us that a bass can increase it corporeal volume and density using the swim bladder, that this bladder does double duty as a vacuum tank. I doubt it. Physically, a swim bladder is like an extensible bag similar to a ballon.  The "air" (usually oxygen) in the swim bladder is created by a fascinating complex of arteries and veins known as the rete mirabile ("wonderful net") using countercurrent ion exchange. This is an excellent example of adaptation.  I believe it also protects fish from "the bends" when they rise from the depths.

So, when the swim bladder expands, gas molecules are brought out of solution in the blood of the fish, where they occupy essentialy zero volume, into the bladder, where they now constitute a volume with a density roughly 1000 times less than the density of water. The density d = M/V of the fish will decrease, since we have increased V with no corresponding change in M. The buoyant force on the fish will increase, causing it to rise. If the fish swims downward, where the external pressure on its body is increased, the rete mirabile can passively absorb gas molecules from the swim bladder back into the bloodstream to reduce the buoyant force.

Whoever wrote the nonsensical item I quoted above is not understanding the physiology of actinopterygii. Physiology fail, dude! I would question whether any living metazoan can create a significant vacuum within its body. Please comment on this if you are aware of an example.

I will close with one fascinating fact: swim bladders can also receive and generate sound. In many fishes, they can produce a sound like a grunt or a bark.