# ISC4244c - Hypothesis testing # Dennis E. Slice (c) 2012 # Clean house rm(list=ls()) # q-q plots # Define a function for repeated use of same code. plot.cdf <- function(nSamples=0, nObs=100) { # For several samples # Set up the plot x = seq(-4,4,0.1) y = dnorm(x) title = "N(0,1) cdf" subtitle="" if (nSamples) subtitle = paste("nSamples=",nSamples," nObservation=",nObs,sep="") # The pdf with dotted lines plot(x,y,main=title,sub=subtitle, type="l",lwd=3,lty=3,ylim=c(0,1)) # Now, the cdf with thick line. lines(x,cumsum(y/sum(y)),lwd=3,col="red") # Now, as many empirical cdfs as requested. Default = 0. if (nSamples) { for (i in 1:nSamples) { # Compute the cumulative values for a sample of n y1 = rep(1/nObs,nObs) y1 = cumsum(y1) # Now some sorted, matching random values. x1 = sort(rnorm(nObs)) lines(x1,y1,lwd=1) } } } par(ask=TRUE) # N(0,1) pdf x = seq(-4,4,0.1) y = dnorm(x) plot(x,y,main="N(0,1) pdf",type="l",lwd=3,ylim=c(0,1)) plot.cdf() cat("Use 'plot.cdf(nSamples=0, nObs=100)' to plot empirical cdfs.")