In: Statistics and Probability
Homework # 3: Note: Please circle your answers when appropriate! 1) You have a sample of 11 flowers from pea plants. (a) Suppose 7 of them are white, and 4 of them are purple. If you line them up in a row, how many different arrangements can you get? Note: WWWWWWWPPPP is one arrangement, WPWPWPWPWWW is another arrangement, and so on. You do NOT want to actually list all possible arrangements - instead, use what you learned in class to calculate this. (b) Now suppose 4 of them are white and 7 of them are purple. How many different arrangements can you get? (c) How many arrangements do you have for 1 white and 10 purple? (d) How many arrangements do you have for 0 white and 11 purple? 2) In the U.S., about 8.5% of people are B+ for blood type. You take a sample of size 9. You're interested in people who are B+. Figure out the following probabilities: a) Pr{Y = 3} b) Pr{Y = 1} c) Pr{Y < 1} d) Pr{Y > 0} (hint - use (c) to answer this and make sure you know why this works) 3) Mendelian genetics predict that in Labrador retrievers (a type of dog), 75% should have black coat color if both parents are heterozygous (the rest are brown). You mate two parents and get a litter of 6 puppies. Calculate the following: a) The probability of 4 black puppies. b) The probability of 4 brown puppies. c) The probability that 50% of the puppies will be brown. (Comment: You do not need to know anything about genetics to solve this problem. If you're trying to do things like use punnet squares, you're doing things wrong) 4) Refer to problem 3. Calculate the probability of every possible outcome (hint: you need to make seven calculations (you already made three of them in problem 3)). 5) Let's do some R.... Suppose you have the following situation: You have a large jar of beans, 29% black, 71% white. You take a sample of 11 beans. a) Use R to figure out the probability for every single possible outcome. In other words, you need to calculate: Pr{0 black beans in 11 trials} Pr{1 black bean in 11 trials} . . etc. . Pr{11 black beans in 11 trials} b) Once you have this information, you need to plot a barplot that shows you what this distribution looks like. As you might guess, you'll need to use the binomial (in R - see below) to solve this problem. Make sure you present all your results (you should have a list of probabilities and the barplot). _________________________________________________________________________________________ Some R instructions to help you are on the next page. Instructions for copying graphs in/from R are also included at the end. For R problems: be prepared to sketch or list your results. You may be asked to show graphs to the class using the document camera at the front of the room (your recitation instructor will set this up for you). Note the following: NEVER, NEVER, hand in just an R printout: Clean it up and clearly label your answers. Make it obvious where everything is and what/where your conclusions/answers are. You will not do well if all you do is hand in a printout. Due in recitation the week of February 17th . R commands: Caution: Be careful copying and pasting commands into R. Some characters may not copy correctly and give you error messages. This is particularly true for quotes. R does not recognize quotes that look like “, only quotes that are straight like this: " . I tried to fix this below, but can’t guarantee I caught everything. Bean problem: Here's an example using a sample of 8 beans from a jar with 32% black beans. You should be able to modify the following as needed to answer question 6: For probabilities: You want probabilities for 0 through 8 beans. First we need to create y with 8 numbers: y <- c(0:8) This command says to give “y” the numbers 0 - 8 in sequence; technically “0:8” tells R it's a sequence of numbers, and the “c” out front means to combine all the numbers. The “c” isn't really needed (try it!) this time, but it is required in many similar situations so it's a good habit to get into to. Now we just “feed” our y into the binomial function to get our answers: p <- dbinom( y, size = 8, prob = .32) This should give you “p” with all the binomial probabilities (they'll be in order from 0 to 8; type “p” to get/see the probabilities) If you want to make it look nice, you can do: pr <- data.frame(y,p) pr to make it look even better, follow this with: print(pr,row.names = FALSE) The data.frame command combines the variables you list (in this case, y and p) into a single data set. Unfortunately if you then type “pr” R will insist on printing row names as well. If you want to get rid of the row names (they’re not needed), you need to use the print statement as given above. To get a barplot: To get a barplot, you simply do (see also the homework instructions from last week): barplot(p) This won't look very nice, so you should try to improve it: barplot(p,names.arg = y) Here “names.arg” is the variable that holds the labels you want to put on the x axis (remember we put the numbers 0 - 8 into y). Just try it - you'll see how it works. If you want to improve your graph even more, you can do (review the caution statement above if you have trouble copying and pasting this): barplot(p,names.arg = y, ylab = "frequency", xlab = "number of dark beans") Or even fancier: barplot(p,names.arg = y, ylab = "frequency", xlab = "number of dark beans", col = "blue") To copy/save graphs generated in R or RStudio: You're going to want to save your graphs or copy them into a word processor so that you can hand them in or refer to them during presentations. If you are using RStudio: (If you're given a choice of format to use as you follow these instructions (usually under Windows), choose “metafile”) Make sure the graph you want is visible in the graphics window. Click on “export” near the top of the plot window. Select “Copy Plot to Clipboard” The click on “Copy Plot” Open your favorite word processor and paste the graph into your document. Comment: copying graphs this way doesn't always give you the best looking graphs (particularly if you're using Linux). Saving the plot as a high resolution image and then inserting this into your document often gives better results. The details on how to do this are provided below - the following instructions work both with and without Rstudio. If for some strange reason you're not using RStudio or you want to do this just from the command line: Windows: In R, right click the graph, select “copy as metafile” (don't use bitmap), then open your favorite word processor and paste the graph. Mac OS: You should be able to copy the graph (make sure the graph window is active) from the menu, and then simply paste the graph into Word (or whatever word processor you use). If this doesn't work for some reason, the Linux instructions will work (they'll work with Windows as well). Linux: This is a bit complicated. A simple way to do it is to use the print screen key, but it'll look horrible. Here’s one example of getting good looking graphs: 1) generate the graph on-screen (just as usual) to make sure it looks right. 2) type “jpeg()” in the command line. There are actually several formats you can pick but jpeg is probably the easiest. 3) generate the graph again (make the graph again). You'll notice that nothing seems to happen. That's okay. It's writing the graph to a jpeg file. 4) now type “dev.off()” on the command line. 5) the graphics file should now be in your home directory. It'll have a name like “Rplotxxx.jpeg”, where xxx is some number. You can always sort by modification date in your file browser to find it quickly. 6) You should now be able to insert or copy the file into your text document (e.g. Word, LibreOffice, or whatever you're using). 7) The jpeg may not look terrific (it'll look a lot better than “print-screen”. You can increase the resolution by doing (in step 2 above)): jpeg(width = 1000,height = 1000) The jpeg command defaults 480 x 480, which isn't that great. You can also use the jpeg command to give it a filename that makes sense, if you want: jpeg(filename = "your-file-name",width = xxx, height = xxx)
1)
You have a sample of 11 flowers from pea plants.
(a) Suppose 7 of them are white, and 4 of them are purple
If you line them up in a row, The number of different arrangements can you get will be given by-
Here in a sample of 11 flowers there are 7 white(W) and 4 are purple(P)
Total Number of ways 7 white(W) flowers can be arrange - 11P7 = 11! / (11-7 )! = 39916800 / 24 =1663200
Total Number of ways 7 purple(P) flowers can be arrange - 11P4 = 11! / (11-4 )! = 39916800 / 5040 = 7920
Hence number of different arrangements can you get will be given by -11P7 * 11P4 = 1663200*7920 = 13172544000
(b) Now suppose 4 of them are white and 7 of them are purple. How many different arrangements can you get.
Here Number of possible ways will be same to that of case where 7 of them are white and 4 of them are purple.
Different arrangements can you get. - 13172544000
(c) How many arrangements do you have for 1 white and 10 purple
Total Number of ways 1 white(W) flowers can be arrange - 11P1 = 11! / (11-1 )! = 39916800 / 3628800 = 11
Total Number of ways 10 purple(P) flowers can be arrange - 11P10 = 11! / (11-10 )! = 39916800 / 1 = 39916800
Hence number of different arrangements can you get will be -11P1 * 11P10 = 11*39916800 = 439084800
(d) How many arrangements do you have for 0 white and 11 purple
Total Number of ways 0 white(W) flowers can be arrange - 11P0 = 11! / (11-0)! = 39916800 / 39916800 = 1
Total Number of ways 11 purple(P) flowers can be arrange - 11P11 = 11! / (11-11 )! = 39916800 / 1 = 39916800
Hence number of different arrangements can you get will be -11P0 * 11P11 = 1*39916800 = 39916800
But if we assume every 11 purple flowers to be same then there will be only 1 possible arrangements
- PPPPPPPPPPP
2) In the U.S., about 8.5% of people are B+ for blood type. You take a sample of size 9.
Thus p = 0.085 , n = 9
You're interested in people who are B+.
It will be binomial process with probability of success p = 0.085
P(Y = y ) =
Figure out the following probabilities:
a) Pr{Y = 3}
Substituting n = 9 , p = 0.085 , y =3 we get
Required probability -
- 0.0302735
b) Pr{Y = 1}
Substituting n = 9 , p = 0.085 , y =1 we get
Required probability -
- 0.3758635
c) Pr{Y < 1}
Pr(Y < 1) = P ( Y = 0 )
{ Note - Since we are not given Y , we cant take P ( Y = 1 ) }
Required probability - 0.4495623
d) Pr(Y > 0)
Pr(Y > 0) = 1 - P ( Y 0 ) = 1 - 0.4495623 = 0.5504377
3) Mendelian genetics predict that in Labrador retrievers (a type of dog),
75% should have black coat color if both parents are heterozygous (the rest are brown).
Let p be probability of success ; here success will be represent as getting black puppies
Hence p = 0.75
1 - p = 0.25
You mate two parents and get a litter of 6 puppies. hence n = 6
P(Y = y ) = ; where p =0.75 and x represent number of black puppies.
Calculate the following:
a) The probability of 4 black puppies. ( y= 4 )
Substituting n = 6 , p = 0.75 , y =4 we get
Required probability -
- 0.2966309
b) The probability of 4 brown puppies.
then number of black puppies = 6 -4 = 2
hence y =2
Required probability -
- 0.03295898
c) The probability that 50% of the puppies will be brown
You mate two parents and get a litter of 6 puppies , Thus 50 % of 6 is 3
50% of the puppies will be brown mean 3 puppies will be brown
then number of black puppies = 6 -3 = 3
hence y =3
Required probability - ; p = 0.75
- 0.1318359
3. Calculate the probability of every possible outcome (hint: you need to make seven calculations (you already made three of them in problem
i.e y= 0,1,2,3,4,5,6, , where y represent number of black puppies
Required Probabilities
for P(Y = 0) = 0.0002441406
for P(Y = 1) = 0.0043945312
for P(Y = 2) = 0.0329589844
for P(Y = 3) = 0.1318359375
for P(Y = 4) = 0.2966308594
for P(Y = 5) = 0.3559570313
for P(Y = 6) = 0.1779785156
We will draw bar-plot using R
R-Code
p=0.75
n=6
x=0:6
P=1.0
for(i in 1:7)
{P[i]=dbinom(x[i],n,p)}
data.frame(P)
data.frame(P)
P
1 0.0002441406
2 0.0043945312
3 0.0329589844
4 0.1318359375
5 0.2966308594
6 0.3559570313
7 0.1779785156
barplot(P,names.arg = c(0:6),col=5)
You have a large jar of beans, 29% black, 71% white.
You take a sample of 11 beans. Hence n = 11
Let p be probability of success ; here success will be represent as getting black beans
Hence p = 0.29
q =1 - p = 0.71 { Prob of getting white beans }
a) Use R to figure out the probability for every single possible outcome. In other words, you need to calculate:
Pr{0 black beans in 11 trials} Pr{1 black bean in 11 trials} . . etc. . Pr{11 black beans in 11 trials}
We will write R -Code for getting Probability .It is binomial process with n = 11 and p = 0.29
We need to calculate Probability for every y = 0,1,2,3,...,10,11
R - Code
p=0.29
# probability of success
n=11
# total number of trails
y=0:11
# creating variable for y = 0 ,1,2,3,....,10,11
P=1.0
for(i in
1:12)
# Loop
{P[i]=dbinom(y[i],n,p)}
>
data.frame(P)
#Requires Probabilities
y
P
1 0 2.311223e-02
2 1 1.038423e-01
3 2 2.120722e-01
4 3 2.598632e-01
5 4 2.122826e-01
6 5 1.213898e-01
7 6 4.958173e-02
8 7 1.446550e-02
9 8 2.954221e-03
10 9 4.022179e-04
11 10 3.285723e-05
12 11 1.220051e-06
Sr no. |
y |
Probabilities |
1 |
0 |
2.311223e-02 |
2 |
1 |
1.038423e-01 |
3 |
2 |
2.120722e-01 |
4 |
3 |
2.598632e-01 |
5 |
4 |
2.122826e-01 |
6 |
5 |
1.213898e-01 |
7 |
6 |
4.958173e-02 |
8 |
7 |
1.446550e-02 |
9 |
8 |
2.954221e-03 |
10 |
9 |
4.022179e-04 |
11 |
10 |
3.285723e-05 |
12 |
11 |
1.220051e-06 |
b) Once you have this information, you need to plot a barplot that shows you what this distribution looks like
R-Code: -
barplot(P,names.arg =c(0:11),col=5,
main ="BarPlot", xlab="y" )