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

Info iconThis 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
Background image of page 1

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

View Full DocumentRight 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")
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 05/19/2010.

Page1 / 5

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

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online