Lab 3 Skills

advertisement

Q Sci 381

Lab 3 Skills

15 October 2014

The excel worksheet Questionnaire_results_2014.xlsx contains the data required for lab. The data come from the questionnaires that were filled out by the class at the beginning of the quarter.

1.

We will be creating conditional probability tables in today’s lab. To build a conditional probability table, we need to calculate the frequencies of each condition. For our first example, we will be using Sex (M,F), and Age (<21, 21+). Here is what our empty table looks like:

Female

Male

<21 21+

2.

Now, we could manually go through and calculate the frequencies of each condition, but that would take some time and the calculation would be subject to human error. Instead, we will be using the =IF() function to help us fill out our table.

3.

The IF function checks to see if a condition you specify is true or false. If true, one thing happens; if false, something else happens. Here, our condition will be F, females. If our condition is True, then we will tell excel to inset the number 1, if False, then 0. Once we do this for every row, we can SUM the 1 values to get the total number of females in the class. a.

Right click on the E column, and click insert. This will give you a blank column next to the Sex column. b.

In cell E3, type in =IF(D3="F",1,0) This function is saying that if the value in cell D3 is equal to F, the assign the value 1, if it does not equal F, then assign a zero. c.

To apply this function down the entire column, first click cell E3. This should outline the cell in green. On the bottom right corner of the cell, there should be a small green square. Double click that, and it will apply that same formula to all of the cells down the column. d.

Now we have a column that has a 1 for each female in the class. All we have to do is sum this column to get the total number of females in the class. Select cell E40 and sum the column. There are 19 females who filled out the questionnaire in our class. e.

Now, we can figure out the total number of males by going back up to cell E3, and slightly modifying by substituting an “M” for the “F” and pressing enter. Once again,

you have to double click the little green square so the formula is applied to the entire column. The sum for males should be 18. f.

To get the total number people in the class add M and F: 18+19= 37.

4.

Now our table has the total number of students, along with the total number of males and females:

Female

Male

<21 21+

19

18

37

5.

Now we need to do the same thing for people <21 and 21+. We will follow the sam exact steps as above, except this time, right click on the G column (The column next to age) and insert a new row. Then, in cell G3, type in the formula =IF(F3<21,1,0) This formula is slightly different. We are dealing with numbers here, so we do not have to put quotes around the values. Also, we need to use the inequality expression “less than”, which in excel is “<”. The function now gives us 1s for all values that are below 21.

6.

Sum the column and fill out contingency table:

Female

Male

<21 21+

19

18

24 13 37

7.

Now we need to fill out the interior of the table. This is when excel really comes in handy. We need to enter in a formula that will meet two conditions. To start off, we will look for individuals that meet the Female and <21 conditions.

8.

To do this, we will use the =IF(AND()) function. This function allows us to enter in multiple conditions. Here is how it works:

=IF(AND(first condition, second condition),value if meets both conditions, value if does not meet both conditions)

9.

We need to create another column to do our calculations. Add another column next column G.

In cell H3, type =IF(AND(D3="F",F3<21),1,0) The first condition is choosing females, and the second condition is choosing only people who were less that 21 years old. If the person meets both conditions, excel puts a 1 in the new cell. If we follow the same steps as before, we get the number of people who are female and are below 21. We get the number 12. This will now

allow us to fill out the rest of our contingency table by using addition/subtraction. Here is our final table:

Female

Male

<21

12

12

21+

7

6

24 13

10.

We can now calculate probabilities based on this table.

19

18

37

Probabilities

Lets go through some probabilities using our conditional probability table

1.

What is the probability of being female? Of being female and 21+? Of being female OR 21+? a.

P(F) = 19/37 = .51 b.

P( F and 21+) = (19/37) * (13/37) = .18 c.

P ( F OR 21+) = (19+13-7)/37) = .68

2.

What is the probability of being male given one is 21+? Of being male given one is not 21+?

Why do these two probabilities not sum to one? a.

P(M|21+) = 6/13 = .462 b.

P(M|not 21+) = 12/24 = .5

P(A|B)+P(not A|B)=1 not P(A|B)+P(A|not B)

Download