Showing posts with label probability. Show all posts
Showing posts with label probability. Show all posts

Wednesday, March 4, 2009

Confidence Intervals or Margins of Error

Confidence intervals let us express information with a degree of probability.
For example, assume we took a sample survey and found that 80% of the population preferred cheese to wine. We can make a more accurate statement if we say that there is a 95% chance that between 77% and 83% of the population prefers cheese to wine.
This can also be reported as 80% of people prefer cheese to wine with a 3% margin of error.

How do we calculate this?

Well we need three things, the mean(u) the standard error (H) and the Z-statistic from the normal curve (Z)

What is the Z statistic? Well consider the graph below:

Normal curve used for confidence intervals

Suppose we wanted to find the point on the curve that would include 95% of the area. As this happens it is at the point (2 sigma) and the value of the x axis at this point is 1.96 That is to say when x equals 1.96 we capture 95% of the population under the curve. So the Z statistic equals that point on the x-axis or 1.96

Some other common levels of confidence and Z stats are
90% z=1.645
95% z=1.96
98% z=2.33
99% z=2.58

As you see, the Z statistic gets larger and larger as confidence increases. In other words we can be
95% sure that between 77-83% of people prefer wine to cheese
99% sure that between 76-84% of people prefer wine to cheese
and
100% sure that between 0-100% of people prefer wine to cheese (which isn't really saying anything at all)


Now for our example, the mean is 80% and assume the standard error is 1.5% (pretty small really)

to get our confidence interval we take the mean and add the Z stat times the standard error:

u + Z(H) upper limit
u - Z(H) lower limit

80 + 1.96(1.5) upper limit = 80 + 2.94 = 82.94 or rounded to 83%
80 - 1.96(1.5) lower limit = 80 - 2.94 = 77.06 or rounded to 77%

Thus we say with 95% confidence that the mean(u) is

77% < = u < = 83%

Because the mean is 80% we can find the margin of error by subtracting from the top interval.

83%-80% = 3 percent margin of error. Thus we make the statement 80% of people prefer wine to cheese with a 3% margin of error.

Tuesday, March 3, 2009

The Central Limit Theorem

The central limit theorem states that if a large enough random sample is drawn from a population then the sampling distribution will be normal.

This could be paraphrased as "All sampling distributions become normal distributions when the sample is large enough" and large enough is generally considered to be 20-30 units.

Sketch of the Normal Distribution

The normal distribution is everywhere in nature.

Monday, March 2, 2009

The Law of Large Numbers

In statistics the law of large numbers states that as sample size increases the accuracy of population estimates increases. This is true for all distributions.

Example:
Suppose we had a bag of 100 marbles and wanted to know how many marbles were solid red.
We could start by drawing 10 marbles from the bag and finding that 2 are red. Thus we estimate that 20% are red.

Then we draw 50 marbles and find that 9 are red, thus we now estimate that 18% are red.

Finally, we draw all 100 marbles (census) and find that there are 17 red marbles. Or that 17% of the marbles are red.

In either case, as we drew more and more marbles our estimate got better and better. This is the law of large numbers.

Sunday, March 1, 2009

Sample Means and Deviations

For any random sample (of size n) taken from a population with mean u and standard deviation H

we can say that the mean is equal to X and that the standard deviation is equal to H/sqrt(n)

That is to say, that as the sample (n) gets larger the estimate of the standard deviation will become smaller and more accurate.

Distributions of sample populations are represented by the "t-distribution" that varies in shape by sample size, and looks much like the normal curve covered earlier. As the sample size approaches the population size the t-distribution looks more and more like the normal curve, but that is tomorrow's lesson.

Friday, February 27, 2009

The Normal Distribution (also Gaussian distribution and bell curve)

The Normal distribution is a curve that is symmetric on both sides and centered around the mean of a population. Like all density functions its area under the curve is between 0 and 1.

Sketch of the Gaussian curve with probability density function and area formulas

Here the mean is represented by mu, which looks like u and the standard deviation is measured by sigma, which looks like a flat 6.

The chances of being 1 deviation away from the mean are around 30%, 2 deviations is 5%, and 3 deviations is 1%

Like we covered yesterday the probability of values being between any point a and b can be found by taking the area under the curve at those points. The functions are there in the image, and as you can see, they are not fun to evaluate. Thus tables or computers are typically used to help obtain values as opposed to direct calculation.

The curve is also called the Gaussian curve in honor of Carl Friedrich Gauss, the German mathematician who found it. Another name is "Bell curve" since its shape represents a bell.

Thursday, February 26, 2009

Continuous Probability Distributions

So far we have looked at discrete probability distributions where values can be assigned to every outcome in the sample space.

For continuous distributions, probability is represented as a function called the probability density function, or density function. These functions must be greater than zero, and must not have an area greater than 1 under their curves. The functions are called "density functions" because they will graph a smooth curve showing values that are most likely or "dense".

Look at the example below which shows a normal curve:
Sketch of a normal curve

We can see very quickly that observations are most "dense" between 40 and 50. To find out the exact probability of a value being between 40 and 50, we must calculate the area of the region between 40 and 50. The same is true to find the probability of a value being less than 40. We must calculate the area under the curve that is less than 40. Thus we calculate the area under the curve for any probabilities we want to find.

Wednesday, February 25, 2009

Geometric Distribution

Suppose we wanted to know the chances of flipping a coin and only seeing a head by the fourth flip, how can we find this?

We can use the geometric distribution which calculates the probability of the number of failures before a success in a Bernouli trail.

The formula is

p(x) = (1-p)xp, where x = 0,1,2,...

Where p(x) is the number of failures, or for our example, the number of tails.

So to apply the formula, what are the chances of flipping a head for the first time on the 4th toss? (This means flipping 3 tails first)

p(x) = number of failures before flipping a head (3)

p(3) = (1 - 0.5)3(0.5) = 0.0625 or around 6%

Pretty low odds!

Monday, February 23, 2009

Binomial Distribution

The binomial distribution is used for multiple Bernouli Trials.

Its formula is written as follows:

p(x) = (n choose x) px * (1-p)n-x , x=0,1,2,....,n

The n choose x part is combinatorial.

n choose x = n! / x!(n-x)! where n is the number of outcomes, and x is the number of outcomes desired.

Example:
Suppose you take a true or false test with 10 questions, what are the chances you get 7 questions right if you just take random guesses? This is a true false so p=50% or .5

p(x) = (10 choose 7) (.5)7*(.5)3

= 10! / 7!*3! *.0078 * 0.125 = 30 * .0078 * 0.125 = 0.029

So you would only have about a 3% chance! Quite amazing. Of course, this means you would have a 97% chance of getting at least 3 wrong, which is not so amazing when you think about it.

Bernoulli Trial

A Bernoulli trial is any experiment in which there can be only two outcomes, usually thought of as a success or failure.

Examples of this can be a coin flip, whether or not you pass a test, or the chances of catching the bus to school.

Assign a 1 to the chance of the event happening, and a 0 to it not happening.

Because discrete distributions have probabilities between 0 and 1, and cannot sum to more than one, a success is defined as p and a failure as 1-p

So the distribution of a Bernoulli trial is seen as

p(x)
0 = 1-p
1 = p

Sunday, February 22, 2009

Discrete Random Variables

It should be known that discrete numbers in mathematics and statistics are not ones that know how to sneak around. Instead, they are countable numbers, even countably infinite numbers. If numbers are not discrete then they are said to be continuous, or uncountable.

In the situation of a coin flip, we can assign a 1 to the outcome of a head, and a 0 to the outcome of a tail. Thus we have transformed the outcome of a coin flip to a discrete random variable, or something that is countable and random.

Discrete distributions must always have probabilities between 0 and 1 and all probabilities must sum to 1.

In math this is

0 < = p(x) < = 1
and Sum(p(x)) = 1

Saturday, February 21, 2009

Bayes Theorem

Bayes theorem is an extension of the theorem of total probability.

Again, we are in a situation where all events in a sample space are mutually exclusive and exhaustive, but this time we want to find conditional probability as opposed to just probability.

We can do this with Bayes theorem which states that the conditional probability of any event (Ei) is

P(Ei,F) = (P(F,Ei)*P(Ei))/(The theorem of total probability)

Recall the theorem of total probability is:
P(F) = P(F and E1) + (F and E2) + (F and E3) + ...(as many as it takes to get "total" probability. "and" in the formula can me taken to mean multiplication or times.)

So in other words we are taking the product of the conditional probability of the outcome, with the probability of the outcome and dividing it by the total probability.

Consider the same example with the factories:
Let us say a company buys parts from 3 other companies.

It gets
60% from company A
40% from company B
20% from company C


Company A ships defective parts 1% of the time (0.01)
Company B ships defective parts 5% of the time (0.05)
Company C ships defective parts 10% of the time (0.10)

Bayes theorem can help us answer the question, what are the chances that a defective part in our company came from company A?

Here the conditional probability of the outcome (defective if from A) is 0.01
The chance of the outcome (bought from A) is 0.60

The probability of any part that is being bought can be found using the total probability theorem. We did that yesterday and found the probability to be 0.046(4.6%)

Bayes theorem says the chances the defective part is from company A is

(0.01*0.60) / 0.046 = 0.13 or 13%

Surprisingly higher than the chance of getting any defective product, but it is because such a large portion of purchases are from that company.

Friday, February 20, 2009

Theorem of Total Probability

Suppose we are in a situation where all events in a sample space are mutually exclusive and exhaustive.

Mutually exclusive means the outcomes are separate from each other, like each time you roll a die.

Exhaustive means all outcomes are accounted for. (You will see in the example)


Example.

Let us say a company buys parts from 3 other companies.

It gets
60% from company A
40% from company B
20% from company C


Company A ships defective parts 1% of the time (0.01)
Company B ships defective parts 5% of the time (0.05)
Company C ships defective parts 10% of the time (0.10)

What are the odds of the company buying a defective part?

Now we have a situation that is exhaustive since all 3 companies comprise 100% of the outcomes. It is also mutually exclusive since one company doesn't affect the other and is "separate".

The theorem of total probability states that when we have an event that is mutually exclusive and exhaustive it can be found by adding the combination of disjoint outcomes. That is to say looking at each company separately and adding them together.
The way to write this is

P(defective part is bought) = P(defective shipped from A) + P(defective shipped from B) + P(defective shipped from C). This represents a "total" account of all outcomes.

The math formula looks like
P(F) = P(F and E1) + (F and E2) + (F and E3) + ...(as many as it takes to get "total" probability. "and" in the formula can me taken to mean multiplication or times.)

The P(defective from a company) is the portion bought from any company times(x) the chance the chance sends something defective.

P(A defective) = 0.6*0.01 = 0.006
P(B defective) = 0.4*0.05 = 0.02
P(C defective) = 0.2*0.10 = 0.02

So
P(defective part is bought) = 0.006 + 0.02 + 0.02 = 0.046 = 4.6%

Thursday, February 19, 2009

Conditional Probability

Conditional probability is used to calculate probability when we have information that can make an event more likely.

For example:

What are the chances of guessing the number rolled on an even 6 sided die?

Since the sample space is {1,2,3,4,5,6} the chances are 1/6

But suppose the person rolling it gave you a hint and told you the number was odd, now what are your chances?

The sample space of odd numbers is {1,3,5} so your chances are 1/3

This is evident in such a small sample space, but we can use a formula for larger sample spaces.

P(E|F) = P(E and F)/P(F)

P(E|F) is read as probability of E given F. In this case E is the chance of guessing the number and F is the chance of the number being odd.

The probability of getting a number that is odd is 1/2 since half the numbers on a six sided die are odd. So P(F)=1/2

The probability of the number being odd and of you guessing the number is still (1/6)
so P(E and F) is 1/6

using the formula, the conditional probability P(E|F) that you can guess the number (E) given that you know it is odd(F) is

P(E|F) = (1/6) / (1/2) = (1/3)

So the formula gives us the same answer we previously saw.

Wednesday, February 18, 2009

P(G or C) = P(G) + P(C) - P(G and C)

P(G or C) = P(G) + P(C) - P(G and C)

When we look for the probability of one event or the other happening we need to add the chance of the first happening with the chance of the second happening, then we need to subtract the probability of both of them happening in order not to over-estimate the chances.

Example:
We are in a store where detailed tracking can tell us the chances of...
a person buying gum P(G) is 0.4
a person buying chocolate P(C) is 0.7
and a person buying both P(G and C) is 0.2

What is the probability that a person buys gum or chocolate?
P(G or C) = P(G) + P(C) - P(G and C)

P(G or C) = 0.4 + 0.7 - 0.2 = 0.9

There is a 90% chance of a customer buying either of those products.
------------------------------

The chances that a customer does not buy gum or chocolate is the complement.

P(not G and not C) = 1 - P(G or C)

or 1 - 0.9 = 0.1 so there is a 10% chance the customer will not buy either...

Tuesday, February 17, 2009

P(E) + P(not E) = 1

P(E) + P(not E) = 1

This is because the probability of any event in the sample space must equal 1. Therefore if we know the probability of E we can also find the probability of not E.


Thus if we want to know the probability of not rolling a 2 on an even die we can say

P(rolling a 2) = 1/6

1/6 + P(not rolling a 2) = 1

P(not rolling a 2) = 1 - (1/6) = (5/6)

Monday, February 16, 2009

Every probability must be greater than or equal to 0 and less than or equal to 1

Every probability must be greater than or equal to 0 and less than or equal to 1

That is to say

0 < = p < = 1

This is because the denominator of any probability is the entire sample space of any outcome.

No outcome, or the null event, would lead to a probability of 0.

Sunday, February 15, 2009

Defining and Calculating Probability

Yesterday we looked at sample spaces, outcomes, and events. Today we will look at ways to determine probability.

Again, consider the die. Imagine we wanted to know the probability of rolling an odd number. The sample space for a die is [1,2,3,4,5,6] and the outcomes of rolling an odd number are [1,3,5] so to calculate this probability we take the number of odd outcomes and divide it by the total number of outcomes.

In this case it is 3/6 or 1/2 or 50%. This is only true if the die is not slanted, that is to say, all outcomes are equally likely.

The second way of calculating probability can be used to test if the die is honest. This is found by rolling the die many times, around 100 and seeing how many times an odd number comes up. So in this case we calculate the probability by counting the number of times an odd number occurs over the number of times we roll the die.

Suppose we do this 100 times and find we rolled 55 odd numbers. Then we see that 55/100 times we rolled an odd, or 55% of the time. This is close enough to 50% to say that the die is honest. After rolling the die 1000 times or even 10,000 times we would expect the number to get closer and closer to 50%.

This second method of probability can also be used in times we we do not know the sample space. Let us say we want to know the probability of making a sale when a customer walks into our shop. There is no way to calculate this theoretically(the first method) and we must do it by counting. Assume that 100 people walk into the shop, and only 20 people end up making a purchase, then we conclude that the probability of making a sale is 20/100 or 20%.

Saturday, February 14, 2009

Probability: Events, Outcomes, and Sample Spaces

Probability is one of the least intuitive aspects of statistics. If it wasn't, Casinos wouldn't net the billions of dollars they do each year.

What do we need to know to get a grounding in probability?

The first thing is the sample space, this is the set of all possible outcomes. For a coin it is heads or tails, for a die it is [1,2,3,4,5,6] and for the height of a person it is [x:x>0]

Outcomes are the result of any random event that we want to predict, i.e. we roll a die and a 2 comes up.

An Event is a desired outcome and is often denoted with a capital letter. For the dice we can define the event, A, as A=2.

Imagine we roll the die again and a 5 is the outcome. Then our desired event did not happen.

Tuesday, December 16, 2008

Combinations

Combinations can be thought of as a layer on top of permutations. They are employed to solve problems of counting how many selections can be made from a particular group. For example, say I wanted to draw 5 marbles from a bag of 15, how many combinations of marbles could I draw?

To answer this question we have to count how many ways we can draw all 15 marbles and then divide that by the number of ways we can draw 10 marbles. This can be written mathematically as:

n!/(n-r)!

so that is

15! / (15-5)!

=

15! / 10!

=

15*14*13*12*11

= 360,360 ways to draw 5 marbles from the bag of 15.

Monday, December 15, 2008

Permutations

We are going to take a break from proofs today to look at some methods of counting in math. Today we will cover Permutations.

A permutation is simply how many possible arrangements there are of any elements in a set. For example, let say we have a set with A,B,C,D in it. How many ways can we order ABCD?

ABCD, ADCB, ACDB, BADB,...and so on. Well, instead of listing every combination out we can use a permutation to count them. A permutation is defined by n factorial (n!)

n! = n(n-1)!
so for example 5!= 5 * 4 * 3 * 2 * 1

And for the ABCD problem we need to take 4! which is 4*3*2*1 = 24

So there are 24 possible permutations.

An interesting facet with permutations is that the numbers tend to rise quite quickly:
5!=120
6!=720
7!=5040
8!=40,320
9!=362,880
10!= 3,362,800

So if we tried to order ABCDEFGHIJ we would get over 3 million permutations!