#---------------------------- # Problem 2ab #source('http://web.mit.edu/jorloff/www/18.05/r-code/ps3prob2data.r') source('ps3prob2data.r') years = getprob2data() mean(years) sqrt(var(years)) hist(years,freq=T,breaks=seq(0,5,.1), main= "Years of Survival", col="yellow") #Export plot as pdf from RStudio #----------------------------- # Problem 4bc. # PDF plot h1 = seq(0,30,.01) g1 = (40-h1)/750 G1 = 40*h1/750 - h1^2/1500 h = c(0,30) g = c(0,5/75) # type='n' means no plot. We just use it to establish dimensions plot(h,g,type='n', main="PDF: g(h) vs. h",axes=F) # Draw the axes. pos=0 means place where x=0 or y = 0 axis(1,pos=0,col='black') axis(2,pos=0,col='black') lines(h1,g1,lwd=2, col='blue') #Export plot from RStudio # CDF plot h = c(0,30) G = c(0,1) plot(h,G,type='n', main="CDF: G(h) vs h",axes=F) axis(1,pos=0,col='black') axis(2,pos=0,col='black') lines(h1,G1,lwd=2, col='blue') #Export plot from RStudio #------------------------ # Problem 6a # Plot Norm(280, 8.5^2) # We'll plot 3 standard deviations m = 280 s = 8.5 x1 = seq(250,305,.01) f1 = dnorm(x1,m,s) F1 = pnorm(x1,m,s) x = c(250,305) f = c(0,1.1*max(f1)) # type='n' means no plot. We just use it to establish dimensions # For some reason axes=F generates a warning, but plot does the right thing plot(x,f,type='n', main="PDF: f(x) vs. x",axes=F) # Draw the axes. pos=0 means place where x=0 or y = 0 axis(1,pos=0,col='black') axis(2,pos=250,col='black') lines(x1,f1,lwd=2, col='blue') #Export plot from RStudio # CDF plot F = c(0,1) # For some reason axes=F generates a warning, but plot does the right thing plot(x,F,type='n', main="CDF: F(x) vs x",axes=F) axis(1,pos=0,col='black') axis(2,pos=250,col='black') lines(x1,F1,lwd=2, col='blue') #Export plot from RStudio #------------------------