Sunday, November 21, 2010

Is -x^2 positive or negative?

So, is -x2 a positive, negative, or undefined quantity for real-valued x?  Ask any physicist or mathematician and they will say that it is a negative number for real valued x making things like: exp(-x2) between 0 and 1.  That is why it came as a BIG surprise to me that computer scientists don't think that, and a program like Excel will interpret:

=-5^2

as positive 25!  After taking quite a while debugging a student problem calculating the normal distribution in Excel, it got me on a quest (and an argument with a colleague) to figure out who else thought this way.  I checked Matlab, Mathematica, Python, and Google as well as a calculator on the computer.  All interpreted -5^2 (properly) as -25.  To do otherwise, I believe, is perverse for any application that is doing mathematical applications.  I was directed to this page, which outlines many languages.  Pretty much just Excel, COBOL, Chipmunk BASIC and a few small scripting languages take the "unary minus" approach, which makes "unary minus" have precedence over exponentiation.

I am not sure why anyone would consider this a good idea, for working with actual math equations.  Of course one could add parentheses, but which is clearer:

y=exp(-x^2)

or

y=exp(-(x^2))

The second is obviously not ambiguous, but less clear.  Anyway, that is the entire reason why we have order of operations, so we don't have to do:

5+(3*4)-(2*3)+(2*(3^3))

So, Excel, come into at least the 20th century and figure out that exponentiation trumps "minus", whatever you want to call it.

 

Glenn Beck on Science

The following audio from a Glenn Beck show is illustrative of many things. Although he demonstrates incredible ignonance of evolution in this clip, he makes some good points...they just aren't the points he thinks he's making.

His main points are the following:

  1. "I don't know why it is unreasonable to say this...I'm not God, so I don't know how God creates...I don't think we came from monkeys...I think that's ridiculous...I haven't seen a half-monkey-half-person yet...did evolution just stop?"
  2. "They have to force [the idea of evolution] down your throat...when anybody has to force it, it's a problem...you didn't have to force that the world is round...[...]...you don't have to force the truth..you just keep adding evidence and evidence until it becomes self-evident."

Now, point (1) demonstrates a profound ignorance, willful or otherwise, of the claims of evolution.  First, no biologist says we came from monkeys...monkeys and people are just as "evolved" as each other, and that they share a common ancestor which would have both features of monkey and human.  We have many of these transitional fossils (for a very nice summary see the Transitional Fossil FAQ).  It's really such an elementary error, that he should be thrown off the air just for spreading such ignorance.

However, I would like to focus on point (2) which perhaps seems reasonable: that truth should be self evident, and not have to be forced.  In a way, one might think that science works this way because everything should be repeatable, and we don't take arguments from authority.  However, there is a problem.  Although it is true that the fact that the world is round did not have to be forced (in contrast to the bogus propaganda story about Columbus demonstrating it), one does need to actually look at the facts in order to be able to judge...truth can be self evident but it requires one to actually look at the evidence.  Take evolution, for example.  If you look at the genetic data showing the differences in base-pair counts between animals, this single number mapped out for all animals demonstrates a tree structure (http://en.wikipedia.org/wiki/Common_descent and http://www.talkorigins.org/faqs/comdesc/section1.html).  Now recall that Darwin did not know anything about genetics, so this is a prediction made 50+ years before the measurements.  When you actually look at the evidence for evolution it is absolutely self evident.  The problem is several-fold:

  1. people refuse to even look at the evidence, choosing instead to willfully remain ignorant thinking they understand it.
  2. There is a certain amount of technical information necessary to understand any science, and that takes work.  If you don't want to do that work then you'll remain ignorant of it.  As an extreme example, quantum mechanics is definitely true, but it neither self evident nor intuitive (and I don't see conservative talking heads railing against it)

What's the solution?  I'm not sure, but challenging people to learn is a start.

 

Saturday, October 16, 2010

A walk down memory lane

I just found a page on "How to Find a Formula for a Set of Numbers".  It's a cool little procedure for taking a series, like:

2, 8, 9, 11, 20

and producing a polynomial to give you the next ones in the series, like:

n3- 17/2 n2+ 49/2 n - 15

where n is the term number, starting from n=1.  Try it out!  Anyway, it was a method I learned in high school math league, and thought it was so cool I wrote a BASIC program on the old TRS-80 computers to do it.  I had forgotten how to do it, and it was fun to see it again.  I particularly liked the comment on the page:

"""If someone gives you the sequence, say, "1, 4, 9, 16", you could run them through the above process and get the answer that the person is probably looking for: the rule is n2 so the next value is 25. But you could also invent any number as the next number in the sequence, say 42, and come up with a rule for "1, 4, 9, 16, 42". Feel free to work it out. It comes out to:

 

17/24 n4 - 85/12 n3 + 619/24 n2 - 425/12 n + 17
and the next term is then 121.

So if you want to be obnoxious, the next time you are given a quiz of "find the next number in the series" problems, just pick any number you like and fill it in, and you'll be completely correct. You'll probably get a failing grade on the test, but you can enjoy the smug satisfaction of knowing you were right."""

I knew a kid who, because of a ridiculous fluke, had to redo some of his middle-school competency tests in high school.  So, when presented with a series like 2,4,6,8,... he did this on a test (and yes he did fail the test and have to redo it).  He was also shown a number of clocks, and asked what time does this show, and for all of the answers put "analog time".

Friday, October 8, 2010

Power UnBalance

I love watching infomercials, but always wonder how much the sellers are exaggerating.  Take this infomercial for the "Power Balance" bracelet, which is claimed to increase balance and coordination:

http://www.youtube.com/watch?v=A_Ow-ZGMy5o

Now, go to this link which shows you how it actually works:

http://www.youtube.com/watch?v=Piu75P8sxTo

Make sure to watch the whole thing, because they give away the "trick" near the middle.  It is useful to go back afterward and watch the first one, now that you know the trick.

The real question, then, is: what should you do if you know a friend is considering buying this, or worse, has already bought it?  When I showed these videos in my class, I was told that the football team had purchased them already.  When some of my students presented them with the evidence, their response was that they didn't care whether it worked or not.

Astounding!

Saturday, September 25, 2010

Multiple Model Comparisons Revisited

Introduction

In a previous post, I hinted at how to do multiple hypotheses testing, using the ψ-measure. It turns out to be much clearer just using the posterior probabilities. The ψ-measure has a nice intuitive feel for the two-hypothesis case, but becomes convoluted in the multiple hyptheses case. Further, when introducing the application of Bayes theorem for students, I have found it to be clearer to follow the following procedure. We first look at Bayes theorem directly, for N hypotheses:

NewImage.jpg

We then calculate the numerator only, for every possible hypothesis:

 

NewImage.jpg

 

calculate the sum of all of these values,

NewImage.jpg

and then normalize

NewImage.jpg

The Octopus, Again

 

From the Wikipedia article, we have the following data:, which gave us correct=12 out of N=14:

  NewImage.jpg

NewImage.jpg

NewImage.jpg

The hypotheses that we consider are the following:

H = “Octopus is psychic, and can predict future (sports) events with 90% accuracy” R = “Octopus makes random choices” Y = “chooses flags with big yellow stripes 90% of the time” G = “chooses Germany 90% of the time”

Notice that both models Y and G, give us correct=12 for N=14 (if the “choosing Germany” chooses Spain in the Netherlands match, because of the similarity). The prior for the psychic octopus is, again, the very generous p(H) = 1/100. The two other non-random models should be more likely, before any data, so I take them to be p(Y)=p(G)=1/20. The random model, being the most likely, has the rest of the prior probability, p(R)=0.89.

Now we calculate the numerators:

NewImage.jpg

Sum the values,

NewImage.jpg

and divide. achieving

NewImage.jpg

Thus, the two flag models went from being rare compared to random to being much more likely than random, and certainly much more likely than psychic. Bayes theorem, properly applied, is a quantitative embodiment of Carl Sagan’s famous quote “extraordinary claims require extraordinary evidence”. It is not just that the evidence must be extraordinary (like 999 correct out of 1000), but the evidence must be extraordinary to address all of the, somewhat rare but possible, hypotheses that would come up as much more likely given the initial result. The process of science is to perform experiments to address these alternative hypotheses.

Sunday, September 12, 2010

God and Hawking

From the book “The Grand Design” By STEPHEN HAWKING And LEONARD MLODINOW

....
Newton believed that our strangely habitable solar system did not "arise out of chaos by the mere laws of nature." Instead, he maintained that the order in the universe was "created by God at first and conserved by him to this Day in the same state and condition."

....

The press is pitching this book as a denial of God, claiming that Hawking has said that God does not exist. The media never seem to get the nuances of logical thinking, and its consequences.

What Hawking and Mlodinow are doing is a modernization of an approach used by Laplace (1749-1827) (http://en.wikipedia.org/wiki/Pierre-Simon_Laplace).  He worked on many things, including the dynamics of the solar system.  When Newton (http://en.wikipedia.org/wiki/Isaac_Newton) published his laws of dynamics 100 years earlier, he demonstrated that the speeds of the planets could be derived from a simple law of gravity.  In this way, Newton connected the Earthly things with the "Heavenly" things.  However, it was unclear to Newton whether the orbits of the planets would remain constant (as his religious philosophy would state), or if they would be unstable, change, and possibly fly apart given enough time.  He posited that one of the roles of God would be to nudge the planets, here and there, to keep their orbits stable.

Laplace, performing his calculations more precisely than his predecessors, was able to determine that the orbits would in fact be stable, without any extra tinkering.  Napoleon, when presented with the work of Laplace, asked him: "M. Laplace, they tell me you have written this large book on the system of the universe, and have never even mentioned its Creator."  Laplace replied, "I had no need of that hypothesis."

He did not say that there was no God (although that is what he believed), but that the concept of God was not necessary to explain the things that he was explaining using physics.  This included the formation of the solar system from a compressing ball of gas (due to gravity), which then forms the Sun in the center and the planets orbiting around.  This is essentially the model still in use today!

What Hawking is doing is basically the same thing, but with the origin of the universe.  Essentially the current model allows for the possibility of many universes to simultaneously exist and that, like a lottery winner, our universe supports life.  It may seem that the universe is "fine-tuned" to support human life, and that this would support the notion of an intelligent designer, Hawking is making the argument that a designer is not needed with our current understanding.  Like a lottery winner stating that the odds of winning are astronomical, and yet they won, and then reasoning that there was some design in this choice even when there wasn't.  As long as you have enough people playing (or enough universes) you'll eventually observe the unlikely, and that unlikely winner will feel singled out.  Hawking argues that the lottery winner (the life on Earth), is arguing the same way when it invokes a designer when it doesn't need to.  Hawking doesn't state "God doesn't exist", because that statement cannot be proven, but he simply states that it is an unnecessary hypothesis for the understanding of the origin of the universe.

Of course, *specific* Gods can be disproven.  For example, it is clear from many lines of evidence that the Earth is more the 6000 years old and that there never was a global flood.  However, you cannot disprove the notion of a God that creates the universe and is then hands-off, like deists commonly believe.  It is completely untestable.  It is also unnecessary, according to Hawking.  This doesn't make it wrong, it is just unnecessary in the same way that we don't need to invoke the divine when understanding how an apple falls from a tree.

Wednesday, September 1, 2010

Why pseudoscientists like the chi-square test (and why it shouldn't be taught)

In a prior post I outlined how orthodox statistics can lead to the either-or logical fallacies common in pseudoscience, like astrology and ufo-ology.

In this post I focus on the &chi2 test, it's pathologies, and why it is so useful for a pseudoscientist. The example is lifted from E. T. Jaynes' book "Probability Theory"

The two problems with &chi2 are:

  1. it violates your strong intuition in some simple cases
  2. it can lead to different results with the exact same data, binned in a different way


Both of these properties are useful to the pseudoscientist.

Intuition and Chi-square: The Three-sided coin



In each of this case we will have some data, and two models to compare which try to explain the data. Intuition strongly favors one, and &chi2 favors the other. One of my favorite problems is the three-sided coin: where the coin can fall heads, tails, or on the edge. Imagine we have two models for a relatively thick coin:


  • Model A: pheads=ptails=0.499, pedge=0.002
  • Model B: pheads=ptails=pedge=1/3


And we have the following data:


  • N=29: nheads=14, ntails=14, nedge=1


Which model are you more confident in? Model A of course! If we use the &psi-measure for goodness of fit with these two models, as defined in my prior post, then we have (remember: smaller &psi means more confident in the fit, just like smaller &chi2):


E7E94805-9E10-451E-9B95-C8EB2BA875C7.jpg




7AFD29D5-C801-416E-82AC-F9B363147B22.jpg



with &psiB-&psiA=26.85 which makes model A more then 100 times more likely than model B (a &psi difference of 20 would be exactly 100 times). Perfectly reasonable. What about &chi2?


31844A12-1F3E-4D51-B2D0-EFAE00BE66A7.jpg



which makes model B slightly preferable to model A! Amazing! Where is this coming from? Apparently it is coming from the somewhat rare event of an edge-landing. If our data had been instead

  • N=29: nheads=15, ntails=14, nedge=0

then we'd have


  • &psiA=0.3
  • &psiB=51.2

and

  • &chi2A=0.093
  • &chi2B=14.55

where now both measures agree that model A is superior.




Why do pseudoscientists love the &chi2 test?
Answer 1: Because all they need to do is wait for that inevitable, somewhat rare but still possible, data point and &chi2 yields a pathologically high value


The &psi-measure and log-likelihood



To understand the other problem with the &chi2 test we need to understand what the &psi-measure is doing. As above, imagine we have a set of observations Oi. We define the total number of observed points and the relative frequency of each observation,


23229268-8820-42F8-BF8C-C984679DCB51.jpg



The maximum likelihood solution for the probabilities of observing Oi for each class, i, is just the relative frequency of each observation. This is the "just-so" solution, where we estimate the probability of seeing 14 heads in 29 flips as p=14/29. This "just-so" solution will have the closest match, and the highest likelihood (by definition). If we have a model which specifies a different set of probabilities for each class, then it's likelihood is simply


71272C22-E8B6-4497-82DF-FBDD89729630.jpg


The &psi measure can be rewritten as


B363F3D7-1964-421A-A8E2-B19020D0117A.jpg



So you can think of the &psi-measure as comparing a model with the "just-so" solution (which has maximum likelihood). Further, subtracting one value of &psi with another (for different models) performs the log-likelihood ratio between the models. A proper analysis should include prior information, which can be done almost as easily.

An almost equivalent problem



Imagine that we have a coin with 6 faces, and we are comparing the following models:


  • Model A: p = [0.499/2, 0.499/2, 0.499/2, 0.499/2, 0.002/2,0.002/2]
  • Model B: p = [1/6,1/6,1/6,1/6,1/6,1/6]


And we have the following data:


  • N=29: O=[7,7,7,7,0,1]


where I have listed the probabilities and the outcomes for each face. Notice that, grouping them together in pairs we retrieve the same as the first example. Thus when comparing the two models, with this equivalent problem, we should get the same value. Because the size of the problem changed, the individual &psi values will be different (larger) because there are more terms in the "just-so" solution. However, the difference between the models should be the same. The results are:


  • &psiA=11.35 (old value 8.34)
  • &psiB=38.2 (old value 35.19)

with &psiB-&psiA=26.85 (old value 26.85...the same!), and

  • &chi2A=32.6 (old value 15.33)
  • &chi2B=11.76 (old value 11.66)


The &chi2 for one of the models (Model A) has been inflated quite a lot relative to the other model. This means that, depending on how you bin the data, you can make whichever model that you are looking at more or less significantly different, without changing the data at all.




Why do pseudoscientists love the &chi2 test?
Answer 2: Because all they need to do is bin their data in different ways to affect the level of significance of their model over the model to which they are comparing


Still taught?



So, why is the &chi2 test still taught? I don't know. It has pathological behavior in simple systems, where somewhat rare events artificially inflate its value, and it can be easily used to prop up an unreasonable model simply by rearranging the data. Why not teach something, like the &psi-measure, which is grounded theoretically in the likelihood principle and does not have such pathological behavior? If you prefer to use the log-likelihood instead, then that would be fine (and equivalent).

I think it is about time to purge the &chi2 test from our textbooks, and replace it with something correct.