lab2 - In this lab we will look at three of the...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
# In this lab, we will look at three of the distributions we've been talking # about in class; binomial, poisson, normal. But before that we'll also # learn how to make *density scale* histogram. ########################################################################## # 1) Relative frequency histogram: dat = read.table("http://www.stat.washington.edu/marzban/390/hist_dat.txt", header=F) x = dat[,1] # Recall that a density scale histogram is a relative frequency histogram where # the y-axis is also divided by the bin size. R does it like this: par(mfrow=c(1,2)) hist(x) hist(x,freq=FALSE) # You can see that the shape is the same, but the advantage of the density # is that the area under it is 1. # By the way, since by default R takes the binsizes to be constant, the # above density histogram is also a relative frequency histogram. ########################################################################## # 2) Binomial: The mass function itself. # First let's compute the binomial proportions in lecture 4 (example 1.22). # In R's convention, putting a "d" before the name of a distribution # returns the value of the distribution itself. E.g., dbinom(0, 100, 0.005) # The format is dbinom(x, n, pi), where in the lecture's notation, # x = number of heads out of n tosses of a coin, and pi= prob of head. # R allows you to run dbinom() for *multiple* values of x, using ":": dbinom(0:3, 100, 0.005) sum( dbinom( 0:3, 100, 0.005) ) # sum of the above probs. # Compare the above with what we got in lecture 4. # Replacing the "sum" with "plot" will plot the numbers: plot( dbinom( 0:3, 100, 0.005) ) # Note no need to specify x explicitly. # So, now we can also plot the mass function for different values # of n and pi. Note the n and pi values that produce normal-looking # distributions, and those that produce poisson-looking distributions. par(mfrow=c(3,4)) plot(dbinom(0:20,5,0.01),type="b") #n=5, pi=0.01 No need to specify x plot(dbinom(0:20,5,0.1),type="b") #n=5, pi=0.1 USE UP-ARROW plot(dbinom(0:20,5,0.5),type="b") #n=5, pi=0.5 USE UP-ARROW
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
plot(dbinom(0:20,5,0.9),type="b") #n=5, pi=0.9 Etc. plot(dbinom(0:20,10,0.01),type="b") #n=10, pi=0.01 USE UP-ARROW plot(dbinom(0:20,10,0.1),type="b") #n=10, pi=0.1 plot(dbinom(0:20,10,0.5),type="b") #n=10, pi=0.5 plot(dbinom(0:20,10,0.9),type="b") #n=10, pi=0.9 plot(dbinom(0:20,20,0.01),type="b") #n=20, pi=0.01 plot(dbinom(0:20,20,0.1),type="b") #n=20, pi=0.1 plot(dbinom(0:20,20,0.5),type="b") #n=20, pi=0.5 plot(dbinom(0:20,20,0.9),type="b") #n=20, pi=0.9 # Can you identify the poisson-lossking one?
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern