Showing posts with label contingency tables. Show all posts
Showing posts with label contingency tables. Show all posts
Tuesday, April 22, 2014
Notes for April 22 and April 24
Confidence interval for standard deviation of population
The confidence interval formula for sigmax is completely different than the formula for mux, and uses values from a new table, Table A-4, known as the chi squared table. Chi is pronounced like the chi in chiropractor, "kai", not "chee" or "chai".
Note that we don't have to test for normal distribution of the underlying data.
Let's give an example. If we have a set where n = 13 and sx = 3.21, we use n-1 as our degrees of freedom. Here is the line from Table A-4 for the row that corresponds to 12.
_____0.995___0.99___0.975___0.95___0.90___0.10____0.05___0.025____0.01___0.005
_12__3.074__3.571___4.404__5.226__6.304__18.549__21.026__23.337__26.217__28.299
The values of chi²Right and chi²Left are taken from the table as follows.
90% confidence: The right value is from the 0.05 column, the left value s from the 0.95 column. (Note that 0.95 - 0.05 = 0.90 or 90%)
95% confidence: The right value is from the 0.025 column, the left value s from the 0.975 column. (Note that 0.975 - 0.025 = 0.95 or 95%)
99% confidence: The right value is from the 0.005 column, the left value s from the 0.995 column. (Note that 0.995 - 0.005 = 0.99 or 99%)
In this instance, here are the confidence intervals for each of the standard percentages of confidence.
90% confidence: 3.21*sqrt(12/21.026) < sigmax < 3.21*sqrt(12/5.226)
2.425 < sigmax < 4.864
95% confidence: 3.21*sqrt(12/23.337) < sigmax < 3.21*sqrt(12/4.404)
2.302 < sigmax < 5.299
99% confidence: 3.21*sqrt(12/28.299) < sigmax < 3.21*sqrt(12/3.074)
2.090 < sigmax < 6.342
Like confidence intervals for other parameters like proportion and average, the 99% is the largest, the 95% is nested inside the 99% and the 90% is nested inside both the others. Unlike other confidence intervals, we get the endpoints by multiplying our statistic sx by two positive numbers, one less than 1 and the other greater than 1. The other thing that is unlike the early confidence intervals is that our statistic is not in the exact center. for example 3.21 - 2.425 = .785, while 5.226 - 3.21 = 2016, so there is a greater distance to the high end of the interval than there is to the low end.
Goodness of fit
If we want to know if a coin is fair we can do a two tailed z-score test of the proportion of heads to tails, where the null hypothesis is that both should be 50%. For example, if I flip a coin 100 times and get 52 heads and 48 tails, that isn't very far off from 50-50. The test statistic would be
z = (.52-.5)/sqrt(.5*.5/100) = .4
A z-score of .4 corresponds to a proportion of .6554. Because this is a two-tailed test, we use the higher number (either heads or tail percentage) and the percentage has to be fairly high.
Two-tailed 90% confidence: over .9500
Two-tailed 95% confidence: over .9750
Two-tailed 99% confidence: over .9950
If instead we got 60 heads and 40 tails, the z-score would produce a much higher proportion.
z = (.60-.5)/sqrt(.5*.5/100) =2.0
A z-score of 2.0 corresponds to a proportion of .9772. If we wanted proof to 90% confidence or 95% confidence, we would say this isn't a fair coin, rejecting the null hypothesis. If we want the proof to 99% confidence, the coin would have to be even more unfair, at least 62 to 38 in 100 flips.
We can't use this method to figure out if a six-sided die is fair, because we need to test that all six possibilities are coming up an equal number of times. For example, if we rolled the die 60 times, we would expect every number to show up exactly 10 times each. In the real world, that's not likely to happen, but we should expect something close. Here is the result of an experiment done with the random number generator in Excel.
number::: 1 2 3 4 5 6
expected: 10 10 10 10 10 10
observed: 14 9 10 10 7 10
Our test statistic will be the sum of (Observed - Expected)²/Expected. Here are the six values.
1st: (14-10)²/10 = 16/10 = 1.6
2nd: (9-10)²/10 = 1/10 = 0.1
3rd: (10-10)²/10 = 0/10 = 0.0
4th: (10-10)²/10 = 0/10 = 0.0
5th: (7-10)²/10 = 9/10 =0.9
6th: (10-10)²/10 = 0/10 = 0.0
The sum is 2.6. This is our test statistic. The degrees of freedom is the number of categories - 1, which in this case is 5. Look on the right side of chi square table for the thresholds in row d.f. = 5.
90% threshold: The 0.10 column, which has 9.236 in row 5
95% threshold: The 0.05 column, which has 11.071 in row 5
99% threshold: The 0.01 column, which has 15.086 in row 5
Our test statistic is much lower than even the 90% confidence level, so we fail to reject the null hypothesis. In other words, while this test wasn't perfect, it was much too close to what we expected to doubt the die was unfair.
Independence of contingency tables
You may remember the idea of dependent probability, where p(A, given B) would not be equal to p(A). It is possible to make a contingency table where p(A, given B) = p(A) for any A and B, where one is a row and the other is a column. Here is an example of a team whose road record and home record are exactly the same.
___H || A|| Total
W |16||16|| 32
L |10||10|| 20
|26||26|| 52 = grand total
We see that p(Wins) = p(Wins GIVEN Home) = p(Wins GIVEN Away). This hypothetical win-loss record is at the same proportion whether on the road or at home.
When we look at a contingency table, it most likely won't be exactly independent, but we have a new test using chi square table once again and using a test statistic that has the same formula as goodness of fit, the sum of (Observed - Expected)²/Expected. This time, the table we are given is the Observed and we must create the Expected using the formula
(row total) * (column total) = grand total.
Here is an example.
___H || A|| Total
W |22||18|| 40
L | 8||12|| 20
|30||30|| 60 = grand total
Now the home and road records aren't identical. We create the expected by keeping the row and column totals and blanking out the values inside.
___H || A|| Total
W |__||__|| 40
L |__||__|| 20
|30||30|| 60 = grand total
In the box for Home Wins, upper left hand corner we put
40 * 30/60 = 20. (Usually this is a decimal number, but I designed it to be a whole number to make this example easier.
___H || A|| Total
W |20||__|| 40
L |__||__|| 20
|30||30|| 60 = grand total
We could do the (row total) * (column total) = grand total method three more times to fill in the rest, but we don't have to. We can simply subtract the number in the box we just filled in to get the rest of the top row and the left column.
___H || A|| Total
W |20||20|| 40
L |10||__|| 20
|30||30|| 60 = grand total
Now it's easy to fill in the last box as well.
___H || A|| Total
W |20||20|| 40
L |10||10|| 20
|30||30|| 60 = grand total
Now we get the four values of (Observed - Expected)²/Expected. Here is the Observed contingency table once again.
___H || A|| Total
W |22||18|| 40
L | 8||12|| 20
|30||30|| 60 = grand total
Top left: (22-20)²/20 = 4/20 = 0.2
Top right: (18-20)²/20 = 4/20 = 0.2
Bottom left: (8-10)²/10 = 4/10 = 0.4
Bottom right: (12-10)²/10 = 4/10 = 0.4
Sum = 1.2
The degrees of freedom for a contingency table is (# of rows - 1) * (# of columns - 1), which in this case is (2-1)*(2-1) = 1*1 = 1. (Notice that we only had to fill in one box in the contingency table and the rest could be found by subtraction.) When degrees of freedom = 1, our thresholds are as follows.
90% confidence level (column 0.10): 2.706
95% confidence level (column 0.05): 3.841
99% confidence level (column 0.01): 6.635
Our test statistic of 1.2 does not let us reject the null hypothesis. This means that while the home and road records are different, we do not consider them to be statistically significantly different.
Restriction of range and correlation
If we take two matched sets of data, we can create a trendline, yp = ax + b, which is also know as the predictor line or the line of regression or the line of least squares. This is the illustration of a set of miles per gallon highway on the x axis and weight on the y axis. Not surprisingly, lighter cars get better gas mileage in general and heavier cars get less miles per gallon. Here is the set of 18 matched pairs, written as (mpg_highway, weight).
(24, 3930)
(24, 3985)
(26, 3995)
(26, 4020)
(27, 3515)
(27, 3175)
(27, 3225)
(28, 3220)
(29, 3115)
(29, 3450)
(30, 3525)
(30, 3245)
(30, 3115)
(31, 2795)
(32, 3235)
(34, 2500)
(37, 2440)
(37, 2290)
The correlation coefficient R² isn't as perfect 1.000, but according to the table we use to check how strong the correlation is, For 18 points the 95% confidence level threshold is 0.2190 and the 99% is 0.3841. So a value of R² = 0.7643 for these two variables shows they have very strong correlation and that isn't surprising. Strong negative correlation here (we can tell it's negative because the line slopes downward) means lighter cars generally get better gas mileage than heavier cars. That makes sense.
The statistical concept that is new here is restriction of range. This says that there is a tendency if you only look at data where the x values are limited, the R² value will go down. Let's say we only look at the first eight cars on the list, the ones that get under 30 mpg highway. We see that the trend is still downward and the slope is steeper. The thing our rule says is that
R² will be less usually, and it is less here. 0.60711 instead of 0.7643. For 8 points, this level of correlation surpasses the 95% threshold of 0.4998, but does not surpass the 99% threshold of 0.6956.
We see the same tendency come true when we look only at the cars getting 30 mpg highway or better. Here there are ten data points and the R² value is 0.61952. The thresholds for 10 pairs are 0.3994 and 0.5852 for 95% and 99% confidence, respectively. By our measure, this set has better correlation than the heavier cars do, but not as good as the set of all 18 cars.
The Monty Hall Problem (or for younger people, The Game Show Problem)
Way back in the day, there was a game show called Let's Make a Deal and the host was Monty Hall. (As a survey in class showed, only one student was aware of this, watching it in re-runs on the cable channel The Game Show Network.) There were many different games played in a half hour using many rules, but one of the famous ones is called The Monty Hall Problem. We can call it The Game Show Problem or more descriptively One Brand New Car and Two Goats.
The rules of the game are as follows. There are three closed doors and the contestant must choose one. Behind two of the doors there are bad prizes and behind the last door there is a great prize. Usually but not always, the bad prizes were goats. Usually but not always, the great prize was a brand new car.
(Note from a different perspective: If you have a place to raise them, goats are excellent producers of meat and milk. The most famous cheese of Greece, known as Feta Cheese, is almost always made from goat's milk. A new car, on the other hand, usually means higher insurance rate and even though it's a prize, the winner has to pay the sales tax.)
Back to the game. After the contestant chooses a door, not knowing if the prize is good or bad, the game show host (Monty Hall) shows that there's a goat behind some unchosen door and asks the contestant if he (or she) wants to switch to another door. (In the three door game, switching means over to the only other door available.)
The math question here is this. Does it make sense to stick with your original door or switch?
Explaining the simplest situation, the three door, one car, two goat version: Okay, on the contestant's first choice, there is a 1/3 chance of getting the car and 2/3 probability of getting a goat. If the contestant doesn't switch, the chance of winning is 1/3.
If the contestant switches, we have to look at two possible situations.
1. The contestant picked the car in the first place. There is a 1/3 chance of this and if the contestant switches, there are no other cars so the contest will lose.
2. The contest picked a goat in the first place. There was 2/3 chance this would happen. If your door has a goat and Monty shows you the second goat, the door you would switch to must have the car, so if the contestant switches, the chance of winning is 2/3.
Generalizing the problem. Let's call the number of doors D, the number of bad prizes B and the number of good prizes G, where G + B = D.
Change the rules so that there can be three doors or more with at least two bad prizes. (If you have a bad prize, the host still needs to show a bad prize.)
If you don't switch, the odds are G/D.
After doing some algebra, we see that the are G/D * (D-1)/(D-2). The second fraction is of the form big/little, so it must be more than 1. What this means is that no matter how many goats (at least two or the game doesn't work) and how many cars (at least one or you can only pick goats), it always makes sense to switch.
Thursday, February 20, 2014
Notes for February 18 and 20
A probability is a number between 0 and 1, inclusive, and is represent by p(event) if part of a sample or p-hat(event) if part of a population.
A probability space or event space is a list of what we call the simple events. The list follows two rules.
1. Every simple event is mutually exclusive from every other simple event, which means the cannot both happen simultaneously. For example, if I flip one coin, it cannot land "heads" and "tails" simultaneously.
2. When we add up the probabilities of all the simple events, the sum is 1. What this means is the simple events (sometimes called simple outcomes).
There are ways to create new probabilities from a set of simple events. The first methods we will discuss are AND, OR and NOT. Let's start with the most basic, NOT.
p(NOT x) is the probability that the event x will not happen. It is sometimes written as q(x) instead. It is always true that
p(x) + p(NOT x) = p(x) + q(x) = 1
Example #1: If we flip a coin, we have two possibilities, heads and tails. We usually assume that p(heads) = .5 and p(tails) = .5, but that doesn't have to be true. What is true in this cases with a categorical variable that has only two legitimate values is that p(NOT heads) = q(heads) = p(tails), and the sum is 1. This means if p(heads) = .51, then q(heads) = 1 - .51 = .49.
If we roll a six-sided die, we have six possible outcomes, a 1, a 2, a 3, a 4, a 5 or a 6. The probability for not rolling a 1 is
p(NOT 1) = p(2) + p(3) + p(4) + p(5) + p(6)
Because these are simple events, we don't have to worry about overlap. And again, instead of calling it p(NOT 1), we can call it q(1).
If two events A and B are mutually exclusive, then
p(A OR B) = p(A) + p(B)
If they are not mutually exclusive, that means p(A AND B) does not equal zero, and the rule for finding OR changes to
p(A OR B) = p(A) + p(B) - p(A AND B)
This is most easily explained with a contingency table. Let's say we have two variables for a game, one called Result (which is either a win or a loss) and Setting (which is either home or away). The easiest way to represent this situation is a contingency table, like the one below listing wins and losses for the Warriors so far this season, broken into home record and away record.
___H || A|| Total
W |16||15|| 31
L |10||12|| 22
|26||27|| 53 = grand total
p(Home) = 26/53, which rounded to the nearest thousandth is .491
p(Away) = 27/53, which rounded to the nearest thousandth is .509. Notice that p(Home) = q(Away) and vice versa.
p(Wins) = 31/53, which rounded to the nearest thousandth is .585
p(Losses) = 22/53, which rounded to the nearest thousandth is .415. Notice that p(Wins) = q(Losses) and vice versa.
p(Wins AND Home) = 16/53, which rounded to the nearest thousandth is .302. What this represents is the number of home wins divided by the total number of games.
p(Wins OR Home) is the probability that a game picked at random is either a home game or a win. We will get this by adding all the wins to all the home games, but we have to subtract the home wins, because they were counted twice.
p(Wins OR Home) = 31/53 + 26/53 - 16/53 = 41/53 or .774 rounded to the nearest thousandth.
Besides AND, OR and NOT, we have the qualifier GIVEN. In a contingency table, this means we only look at the number is a single row or column.
p(Wins GIVEN Home) = 16/26 or .615 rounded to the nearest thousandth.
p(Home GIVEN Wins) = 16/31 or .516 rounded to the nearest thousandth.
Notice that p(Wins) = .585 but p(Wins GIVEN Home) = .615. When these numbers are different, we say that the two categories Wins and Home are dependent. If they were the same, we would say the categories are independent. A contingency table that was independent might look like this
___H || A|| Total
W |16|| 8|| 24
L |10|| 5|| 15
|26||13|| 39 = grand total
Now, p(Wins) = p(Wins GIVEN Home) = p(Wins GIVEN Away). This hypothetical win-loss record is at the same proportion whether on the road or at home.
Binomial distribution of an independent variable
If I say someone is a 70% free throw shooter, is every free throw attempt independent of what happened before? Often, we set up such an experiment assuming independence just to make our work simpler, but the human factor is involved, so in reality it's very likely to be dependent. Some people get frustrated after a few misses and will do worse. Others will learn from the mistakes of a few misses and figure out what they are doing wrong and make improvements. A player might be having a bad day for some reason, or might instead have excellent concentration or just really good luck that day. But again, these kinds of experiments are often set up as though each free throw trial is independent of what came before.
Let's look at flipping coins. A list of all possible events is called the event space. Here are some examples of event spaces.
Event space for flipping one coin
Heads (H)
Tails (T)
ways to get one head = 1
ways to get no heads = 1
Event space for flipping two coins
HH
HT
TH
TT
ways to get two heads = 1
ways to get one head = 2
ways to get no heads = 1
Event space for flipping three coins
HHH
HHT
HTH
HTT
THH
THT
TTH
TTT
ways to get three heads = 1
ways to get two heads = 3
ways to get one head = 3
ways to get no heads = 1

The list of numbers of ways to get r successes in n trials is often written in the pattern of the picture shown here, and this pattern is called Pascal's Triangle, at least in most of the world. The Italians call it Tartaglia's Triangle and the Chinese call it Yanghui's Triangle. None of these people actually invented it or claimed to have invented it. It's been around since before the time of Christ, and it has been studied all around the world.
While it is very common to see it presented in the form here as an equilateral triangle, it can also be presented where the first numbers in each row are lined up straight as follows
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
... etc.
It is standard to start counting the top row as row 0, and the left most column as column 0. For example, the 6 we see in the middle of the last row I typed in is row 4, column 2. Instead of having a copy of Pascal's Triangle around, our calculators have these numbers available. On Texas Instruments calculators, the function is under the probability menu. On the TI-30XIIs, the way to get that 6 is to type
4 [prb][right arrow]2[enter]
The calculator will read
4 nCr 2
6
All scientific calculators should have this function available, but all of them are slightly different. The TI-89 writes it as nCr(4,2) and Casio calculators write it as 4 C 2. I will pronounce it "4 choose 2", and when I type on the blog, I will type C(4,2). When I write it on the board or on tests, I will put a 4 on top of a 2 and surround both numbers with a large parentheses. These numbers are called the binomial coefficients.
The formula for finding the probability for exactly r successes in n independent trials where the probability of success on any single trial is p is shown here. In some books, they don't use the letter q, instead replacing it with (1-p). Likewise, sometimes w is replaced with (n-r). I use the extra letters and include the relationships between them. The letters r and w stand for right and wrong. The letter p and q are standard in probability texts for the probability of a success or a failure.Let's do an example. You are given a four question multiple choice test, each question having five possible answers. The test is given in a language you do not read, so all you can do is guess. Each question is independent from the others, meaning that if C is the right answer to the first question, it's also possibly the answer to the second. The probability p of a correct guess is 1 chance in 5, or .2, The probability of failure q is 1-.2 = .8, and of course p + q = 1.
Probability of no correct answers = C(4,0)*.2^0*.8^4 = .4096
Probability of exactly one correct answer = C(4,1)*.2^1*.8^3 = .4096
Probability of exactly two correct answers = C(4,2)*.2^2*.8^2 = .1536
Probability of exactly three correct answers = C(4,3)*.2^3*.8^1 = .0256
Probability of four correct answers = C(4,4)*.2^4*.8^0 = .0016
The expected value of correct answers is n*p, so in this case it's 4*.2 = .8, which isn't possible. You can't get a fraction of correct answers on a multiple choice test. The expected value in this case says that over the long run, a test like this should average .8 right answers out of four. As we can see, the most likely thing to happen is actually a tie for first, where getting either no answers right or one answer right both have a probability of about 41%. If you need to get three answers right to pass the test, the odds are less than 3% to get either three or four right, and the odds of getting everything right by chance is a very slim 16 chances in 10,000.
If you have a TI-83 or TI-84, there is a function under the distribution menu called binompdf(n,p,r). All you have to is enter the function, then the three values in the order given, separated by commas.
The function for three right in four trials with probability .2 at each trial is binompdf(4, .2, 3), which as we see above is .0256.
Practice problem.
The test is changed. There are now five multiple choice questions and four choices for each, but it is still given in a language you do not read.
Round the probabilities to four places after the decimal.
1. What is the expected value?
2. What is the probability of no correct answers?
3. What is the probability of exactly one correct answer?
4. What is the probability of exactly two correct answers?
5. What is the probability of exactly three correct answers?
6. What is the probability of exactly four correct answers?
7. What is the probability of five correct answers?
Answers in the comments.
Saturday, July 4, 2009
Practice problems for homework due 7/6
Take the information of this incomplete contingency table with categories left and right in the columns and yes and no in the rows and fill in the rest of the table using the degrees of freedom.
____________left____right_____row totals
Yes___________25________________75
No____________________50_______
col. totals___90_____________________grand total
Use the information from the completed table to find the following probabilities, both as fractions and as percents rounded to the nearest tenth of a percent.
p-hat(Yes) =
p-hat(Left) =
p-hat(Left and Yes) =
p-hat(Left or Yes) =
p-hat(Left, given Yes) =
p-hat(Yes, given Left) =
State the following complementary sets without using the word NOT, using the categories from above.
NOT (Left) =
NOT (Left or Yes) =
NOT(Right and Yes) =
Answers in the comments.
____________left____right_____row totals
Yes___________25________________75
No____________________50_______
col. totals___90_____________________grand total
Use the information from the completed table to find the following probabilities, both as fractions and as percents rounded to the nearest tenth of a percent.
p-hat(Yes) =
p-hat(Left) =
p-hat(Left and Yes) =
p-hat(Left or Yes) =
p-hat(Left, given Yes) =
p-hat(Yes, given Left) =
State the following complementary sets without using the word NOT, using the categories from above.
NOT (Left) =
NOT (Left or Yes) =
NOT(Right and Yes) =
Answers in the comments.
Friday, February 13, 2009
Class notes for 2/11

Venn diagrams and contingency tables: In other classes you have taken, you may have seen Venn diagrams. The idea is to represent the ideas of sets and subsets and intersections of subsets pictorially. In this picture, the rectangle represents the whole set of things we are considering, known as the universe, while the two circles represent subsets A and B. This splits the rectangle into four parts, colored in the picture in white, yellow, gray and blue. Here are the color combinations that represent some of the sets we discuss in probability.
A = yellow and gray
not A = white and blue
B = gray and blue
not B = white and yellow
A and B = gray
A or B = yellow, gray and blue
not (A and B) = not A or not B = white, yellow and blue
not (A or B) = not A and not B = white
When a variable has only two values, like gender can be male or female or left-right handedness can be left or right, then "not male" is the same as "female", or "not left" is the same as "right". Many variables have more than two values, so "not 20-29" is easier to write than "19 & under or 30-39 or 40-49 or 50 & over". There are problems often associated with Venn diagrams and figuring out how many subjects are in certain subsets that are easier to solve using contingency tables than using Venn diagrams. Here is an example.
In both data sets combined, there are 80 subjects. There are a total of 6 left handed subjects, 30 males. 4 of the males are left handed. How many females are right handed?
How to solve it: Since the total is 80, 30 males means 50 females and 6 left handers means 74 righthanders. This means we know the row and column totals of a contingency table.
_____|__M_|__F_|_total
R____|____|____|_74
L____|____|____|__6
total|_30_|_50_|_80 grand total
Because we had the grand total and the total number of males, we get the total number of females by subtracting. We call this is degrees of freedom. Once we have the total, and we know that two numbers add up to that total, being given any single value means you can figure out the other value, so there is only one degree of freedom. If instead we were dealing with age groups, where we have five values, then we would have four degrees of freedom, meaning if you knew the frequencies of four values, you could add those up and subtract the total from the size of the whole set to find the fifth frequency that wasn't given.
Once we have all the row and column totals in a 2x2 contingency table, we only need one value inside the box to get all the other three, so once again, we have one degree of freedom. There are four left handed males, which means a 4 is put in row 2, column 1, as follows:
_____|__M_|__F_|_total
R____|____|____|_74
L____|__4_|____|__6
total|_30_|_50_|_80 grand total
Using subtraction, we can fill in the rest of the values.
_____|__M_|__F_|_total
R____|_26_|_48_|_74
L____|__4_|__2_|__6
total|_30_|_50_|_80 grand total
This means there are 48 right handed females, which is what we were asked. We also know there are 2 female lefties and 26 male righties, though those questions were not asked.
Conditional probability: Besides asking for p-hat(females), p-hat(male and right) or p-hat(left or female), we have the idea of p-hat(female, given left), which means if we count only the left handed subjects, how many of them are female. If you have the information in contingency table form, what changes in such a question is the denominator of the fraction, which is a row total or a column total instead of the grand total. Here are three examples.
p-hat(female and left) = 2/80 = .025 = 2.5%
p-hat(female, given left) = 2/6 = .333... ~ 33.3%
p-hat(left, given female) = 2/50 = .04 = 4.0%
[Note: I will use ~ to mean approximately equal when typing on the blog.]
There is a formula for conditional probability if you don't have the information in contingency table form.
p(A, given B) = p(A and B)/p(B)
Practice problems:
In a sample of 42 people, there are 4 left handed people. 19 people gave the answer of 3 on a scale from 1 to 5 for difficulty of the class. 2 of the left handed people gave the answer 3 to the difficulty question. Find the following probabilities, rounded to the nearest tenth of a percent.
p-hat(left and difficulty 3) =
p-hat(right or difficulty 3) =
p-hat(right, given difficulty 3) =
p-hat(difficulty 3, given right) =
Answer in the comments.
Tuesday, February 10, 2009
Class notes for 2/9
We are now dealing with proportions, and the formulas are as follows:
Population: p = F/N
Sample: p-hat = f/n
We often want to compare one proportion to another, either two from the same sample or comparable proportions from different samples, or the sample proportion to the population proportion. Because of this, it is better to write the numbers as decimals or in scales based on powers of 10.
Scales based on powers of 10: The most famous scale base on powers of ten in percentage, which really means "per 100". It is much more common to see "53% of the people agree with the president's plan" than ".53 of the people..." or "53 out of every 100 people...". Technically, all those phrases are saying the same thing, but percentage is the most popular.
One of the places where decimals are used for proportions is in the sports pages. A batting average in baseball (hits/at bats) is given as a percent to three decimal place, and likewise winning proportions (win/total games) are written as .xxx. If a batter has 27 hits in 92 at-bats, the batting average 27/92 = .293478261... is shortened to .293 and pronounced "two ninety three". Likewise, a team who has won 17 games and lost 5 will have a winning proportion of 17/22 = .77272727... = .773, and often stated as "team has a winning percentage of seven seventy three." Technically, this is a mistake, because "percentage" means out or 100. The correct word from the dictionary, which no one ever uses, is "permillage", which means out of 1,000. The team in question would have a winning percentage of 77, and a winning permillage of 773.
In both of the cases from the sports pages, the greater number of place after the decimal is used to break ties. For example, a team with 14 wins and 4 losses is at .778, which is better than 17 wins and 5 losses, while 20 wins and 6 losses is at .769, so is slightly worse.
To get a number based on a power of 10 scale, you take the proportion and multiply by the power of ten, so it is either p*scale or p-hat*scale, depending on population or sample. Besides greater precision for breaking ties, sometimes we need greater precision because the proportions are so small.
When I ask a class what is the legal limit for blood alcohol while driving, invariably someone will say "point oh eight" and most people will agree. But .08 is wrong. .08 = 8%, and the correct answer is .08% = .0008. I don't blame the students. The number is badly represented and it is an easy mistake to make. Let's take a look at the number on other scales of 10.
.08 out of 100 is the same as
.8 out of 1,000 0r
8 out of 10,000 or
80 out of 100,000
80 parts out of 100,000 is a tiny proportion. To give an idea, ounce of pure alcohol mixed into ten gallons of blood would give you 78 parts out of 100,000, and most people have between a half gallon and a gallon and a half of blood in their body, between 4 and 12 pints. The amount of alcohol in a person's blood stream that is over the legal limit is about the same amount of alcohol as found in a capful of mouthwash used after brushing your teeth.
We will be dealing with much smaller proportions later in the class, where there are things that can be hazardous to your health at ranges measure in parts per billion, but for now, we will look at the per 100,000 scale for another type of statistic, measurements of mortality rates.
Here are the number of homicides in some local cities in 2007.
Oakland: 124 homicides
Richmond: 28 homicides
San Francisco: 98 homicides
Clearly, comparing these numbers is misleading, because we know these cities have very different numbers of citizens, so the standard way to measure these statistics is the per 100,000 population scale, which we find by the formula
f/n* scale
which in this case is
(# of homicides)/(city population) * 100,000
Oakland's population in 2007 is estimated at 415,000, Richmond at 106,000 and San Francisco at 825,000, so the murder rates on this standard scale are as follows
Oakland: 124/415000 * 100000 = 29.9
Richmond: 28/106000 * 100000 = 26.4
San Francisco: 98/825000 * 100000 = 11.9
So even though more people were murdered in San Francisco than in Richmond in 2007, the murder rate in Richmond was over twice as high, because Richmond has barely 1/8 of the population of San Francisco. (note: The trends for the three cities this decade are going in different directions. Oakland's murder rate is on the rise, while Richmond's is falling and San Francisco's has stayed about the same.)
Calculating proportions (probabilities): There are times when we will need to find new proportions from information previously calculated, either adding and subtracting old numbers or multiplying or dividing. It's best to use the fractional forms of the data when available, then round the answers after using the exact numbers instead of using answers that might have been rounded. Every time you use a rounded answer in a calculation, there is a change to increase the rounding error even more.
The words "proportions" and "probabilities" will be used interchangeably in the rest of this post.
Contingency tables and compound probabilities: Let's take the data from data set #2 regarding gender and left/right handedness and turn it into a contingency table.
___R__L_
M__9__3_
F_29__1_
What these numbers represent is there are 9 right-handed males, 3 left-handed males, 29 right-handed females and 1 left-handed females. We will now add the row totals, the column totals and the grand total, which will be marked in red.
___R__L_
M__9__3_ 12
F_29__1_ 30
__38__4_ 42=grand total
This gives us the following probabilities. We assume this is a sample so these values are p-hat.
p-hat(female) = 30/42
p-hat(male) = 12/42
p-hat(left) = 4/42
p-hat(right) = 38/42
We can also combine values from different variables as follows.
p-hat(female and left) = 1/42
p-hat(female and right) = 29/42
p-hat(male and left) = 3/42
p-hat(male and right) = 9/42
When we use the conjunction "and", we take the number of subjects that would answer yes to being both female and left handed, for example, and divide by the size of the data set. This means a single entry from the contingency table divided by the grand total.
The conjunction "or" means we want all the subjects that are in the combination or a row and a column together, but being careful that we did not count anyone twice. We use the principle of inclusion and exclusion when calculating this, which is as follows.
p(A or B) = p(A) + p(B) - p(A and B)
The rule is the same whether we are dealing with p or p-hat.
The reason we subtract is as follows. If I count all the women in the set, and then all the left handed people in the set and add those together, any left handed women were counted twice, so we subtract the total of left handed women to get count correct.
p-hat(female) = 30/42
p-hat(left) = 4/42
p-hat(female and left) = 1/42
p-hat(female or left) = 30/42 + 4/42 - 1/42 = 33/42
Another way to combine proportions is the conjunction "given". The idea of p(female, given left) means how many females are there in the subset of left handed people while p(left, given female) means how many left-handers are there among the women. The formula for this is
p-hat(A, given B) = p(A and B)/p(B)
In a contingency table, the easiest way to calculate this is to find the place in the table that tells us how many people are in the row and column that correspond to A and B, then divide by the row or column total that corresponds to B. Here are the eight different values we have for the given probabilities.
p-hat(female, given left) = 1/4
p-hat(female, given right) = 29/38
p-hat(male, given left) = 3/4
p-hat(male, given right) = 9/38
p-hat(left, given female) = 1/30
p-hat(right given, female) = 29/30
p-hat(left given, male) = 3/12 = 1/4
p-hat(right given, male) = 9/12 = 3/4
Complementary events and their probabilities: The complement of a subset is all the elements that are in the whole set but not in the subset. In a variable with two values, the complement of one value is simply the other value, so the complement of lefthanders is righthanders, and the complement of men is women. In a variable with more than one value, the complement of a value is all the other values. The complement of the 20-29 value in age group would be the subjects 19 and under combined with the subjects 30 and over. Since we are using the words "and", "or" and "given" as our conjunctions, the word used for complement in such a setting is "not".
If we know p(A), the easiest way to calculate the probability of the complement is
p(not A) = 1 - p(A).
In some books and in my notes, the probability of the complementary event will be denoted by the letter q, defined by the equation p + q = 1, or q = 1 - p.
Again, the rules for p and q are the same for p-hat and q-hat.
Here are some complements of the some of ideas we have defined using the conjunctions.
female complement = male
male complement = female
left complement = right
right complement = left
female and left complement = male or right
male and left complement = female or right
female, given left complement = male, given left
male, given left complement = female, given left
female, given right complement = male, given right
male, given right complement = female, given right
Practice problems: (answers given in comments)
1) Here are the homicide numbers for Oakland, Richmond and San Francisco from earlier in this century.
Oakland: 96 homicides, 399,000 population
Richmond: 40 homicides, 99,000 population
San Francisco: 96 homicides, 775,000 population
Find the murder rates from these years, rounded to the nearest tenth per 100,000 population and rank them from lowest (1st) to highest (3rd).
2) Find the complements of the following sets and the probabilities for the set and the complement rounded to the nearest tenth of a percent. (If it rounds exactly to a percent, you can write the answer as 42% instead of 42.0%, to give an example.)
a) left, given female
b) left and female
c) left or female
d) female, given left
Population: p = F/N
Sample: p-hat = f/n
We often want to compare one proportion to another, either two from the same sample or comparable proportions from different samples, or the sample proportion to the population proportion. Because of this, it is better to write the numbers as decimals or in scales based on powers of 10.
Scales based on powers of 10: The most famous scale base on powers of ten in percentage, which really means "per 100". It is much more common to see "53% of the people agree with the president's plan" than ".53 of the people..." or "53 out of every 100 people...". Technically, all those phrases are saying the same thing, but percentage is the most popular.
One of the places where decimals are used for proportions is in the sports pages. A batting average in baseball (hits/at bats) is given as a percent to three decimal place, and likewise winning proportions (win/total games) are written as .xxx. If a batter has 27 hits in 92 at-bats, the batting average 27/92 = .293478261... is shortened to .293 and pronounced "two ninety three". Likewise, a team who has won 17 games and lost 5 will have a winning proportion of 17/22 = .77272727... = .773, and often stated as "team has a winning percentage of seven seventy three." Technically, this is a mistake, because "percentage" means out or 100. The correct word from the dictionary, which no one ever uses, is "permillage", which means out of 1,000. The team in question would have a winning percentage of 77, and a winning permillage of 773.
In both of the cases from the sports pages, the greater number of place after the decimal is used to break ties. For example, a team with 14 wins and 4 losses is at .778, which is better than 17 wins and 5 losses, while 20 wins and 6 losses is at .769, so is slightly worse.
To get a number based on a power of 10 scale, you take the proportion and multiply by the power of ten, so it is either p*scale or p-hat*scale, depending on population or sample. Besides greater precision for breaking ties, sometimes we need greater precision because the proportions are so small.
When I ask a class what is the legal limit for blood alcohol while driving, invariably someone will say "point oh eight" and most people will agree. But .08 is wrong. .08 = 8%, and the correct answer is .08% = .0008. I don't blame the students. The number is badly represented and it is an easy mistake to make. Let's take a look at the number on other scales of 10.
.08 out of 100 is the same as
.8 out of 1,000 0r
8 out of 10,000 or
80 out of 100,000
80 parts out of 100,000 is a tiny proportion. To give an idea, ounce of pure alcohol mixed into ten gallons of blood would give you 78 parts out of 100,000, and most people have between a half gallon and a gallon and a half of blood in their body, between 4 and 12 pints. The amount of alcohol in a person's blood stream that is over the legal limit is about the same amount of alcohol as found in a capful of mouthwash used after brushing your teeth.
We will be dealing with much smaller proportions later in the class, where there are things that can be hazardous to your health at ranges measure in parts per billion, but for now, we will look at the per 100,000 scale for another type of statistic, measurements of mortality rates.
Here are the number of homicides in some local cities in 2007.
Oakland: 124 homicides
Richmond: 28 homicides
San Francisco: 98 homicides
Clearly, comparing these numbers is misleading, because we know these cities have very different numbers of citizens, so the standard way to measure these statistics is the per 100,000 population scale, which we find by the formula
f/n* scale
which in this case is
(# of homicides)/(city population) * 100,000
Oakland's population in 2007 is estimated at 415,000, Richmond at 106,000 and San Francisco at 825,000, so the murder rates on this standard scale are as follows
Oakland: 124/415000 * 100000 = 29.9
Richmond: 28/106000 * 100000 = 26.4
San Francisco: 98/825000 * 100000 = 11.9
So even though more people were murdered in San Francisco than in Richmond in 2007, the murder rate in Richmond was over twice as high, because Richmond has barely 1/8 of the population of San Francisco. (note: The trends for the three cities this decade are going in different directions. Oakland's murder rate is on the rise, while Richmond's is falling and San Francisco's has stayed about the same.)
Calculating proportions (probabilities): There are times when we will need to find new proportions from information previously calculated, either adding and subtracting old numbers or multiplying or dividing. It's best to use the fractional forms of the data when available, then round the answers after using the exact numbers instead of using answers that might have been rounded. Every time you use a rounded answer in a calculation, there is a change to increase the rounding error even more.
The words "proportions" and "probabilities" will be used interchangeably in the rest of this post.
Contingency tables and compound probabilities: Let's take the data from data set #2 regarding gender and left/right handedness and turn it into a contingency table.
___R__L_
M__9__3_
F_29__1_
What these numbers represent is there are 9 right-handed males, 3 left-handed males, 29 right-handed females and 1 left-handed females. We will now add the row totals, the column totals and the grand total, which will be marked in red.
___R__L_
M__9__3_ 12
F_29__1_ 30
__38__4_ 42=grand total
This gives us the following probabilities. We assume this is a sample so these values are p-hat.
p-hat(female) = 30/42
p-hat(male) = 12/42
p-hat(left) = 4/42
p-hat(right) = 38/42
We can also combine values from different variables as follows.
p-hat(female and left) = 1/42
p-hat(female and right) = 29/42
p-hat(male and left) = 3/42
p-hat(male and right) = 9/42
When we use the conjunction "and", we take the number of subjects that would answer yes to being both female and left handed, for example, and divide by the size of the data set. This means a single entry from the contingency table divided by the grand total.
The conjunction "or" means we want all the subjects that are in the combination or a row and a column together, but being careful that we did not count anyone twice. We use the principle of inclusion and exclusion when calculating this, which is as follows.
p(A or B) = p(A) + p(B) - p(A and B)
The rule is the same whether we are dealing with p or p-hat.
The reason we subtract is as follows. If I count all the women in the set, and then all the left handed people in the set and add those together, any left handed women were counted twice, so we subtract the total of left handed women to get count correct.
p-hat(female) = 30/42
p-hat(left) = 4/42
p-hat(female and left) = 1/42
p-hat(female or left) = 30/42 + 4/42 - 1/42 = 33/42
Another way to combine proportions is the conjunction "given". The idea of p(female, given left) means how many females are there in the subset of left handed people while p(left, given female) means how many left-handers are there among the women. The formula for this is
p-hat(A, given B) = p(A and B)/p(B)
In a contingency table, the easiest way to calculate this is to find the place in the table that tells us how many people are in the row and column that correspond to A and B, then divide by the row or column total that corresponds to B. Here are the eight different values we have for the given probabilities.
p-hat(female, given left) = 1/4
p-hat(female, given right) = 29/38
p-hat(male, given left) = 3/4
p-hat(male, given right) = 9/38
p-hat(left, given female) = 1/30
p-hat(right given, female) = 29/30
p-hat(left given, male) = 3/12 = 1/4
p-hat(right given, male) = 9/12 = 3/4
Complementary events and their probabilities: The complement of a subset is all the elements that are in the whole set but not in the subset. In a variable with two values, the complement of one value is simply the other value, so the complement of lefthanders is righthanders, and the complement of men is women. In a variable with more than one value, the complement of a value is all the other values. The complement of the 20-29 value in age group would be the subjects 19 and under combined with the subjects 30 and over. Since we are using the words "and", "or" and "given" as our conjunctions, the word used for complement in such a setting is "not".
If we know p(A), the easiest way to calculate the probability of the complement is
p(not A) = 1 - p(A).
In some books and in my notes, the probability of the complementary event will be denoted by the letter q, defined by the equation p + q = 1, or q = 1 - p.
Again, the rules for p and q are the same for p-hat and q-hat.
Here are some complements of the some of ideas we have defined using the conjunctions.
female complement = male
male complement = female
left complement = right
right complement = left
female and left complement = male or right
male and left complement = female or right
female, given left complement = male, given left
male, given left complement = female, given left
female, given right complement = male, given right
male, given right complement = female, given right
Practice problems: (answers given in comments)
1) Here are the homicide numbers for Oakland, Richmond and San Francisco from earlier in this century.
Oakland: 96 homicides, 399,000 population
Richmond: 40 homicides, 99,000 population
San Francisco: 96 homicides, 775,000 population
Find the murder rates from these years, rounded to the nearest tenth per 100,000 population and rank them from lowest (1st) to highest (3rd).
2) Find the complements of the following sets and the probabilities for the set and the complement rounded to the nearest tenth of a percent. (If it rounds exactly to a percent, you can write the answer as 42% instead of 42.0%, to give an example.)
a) left, given female
b) left and female
c) left or female
d) female, given left
Subscribe to:
Posts (Atom)





