#! /usr/bin/R n <- as.numeric(formData$n)[1] sig <- as.numeric(formData$sd)[1] mu <- as.numeric(formData$mean)[1] tag(HTML) tag(HEAD) tag(TITLE) cat("Sample of",n," random normal points.") untag(TITLE) untag(HEAD) lf(2) tag(BODY) lf(2) tag(h1) cat("Graph of normal curve with",n,"points") untag(h1) lf(2) #cat(mu,sig); lf(1) lb <- floor(mu - 3.5*sig) ub <- ceiling(mu + 3.5*sig) #cat(lb,ub); lf(1) XX <- rnorm(n,mu,sig) vlines <- (-2:2)*sig + mu ##Points at which we will draw lines. #cat(vlines); lf(1) webPNG("normEst.png") curve(dnorm(x,mu,sig),xlim=c(lb,ub),ylab="density", xlab="Data value", sub=paste("Mean =",mu,"; Standard Deviation =",sig), col=formData$col,lty=as.numeric(formData$lty)) abline(h=0) segments(vlines,rep(0,5),vlines,dnorm(vlines,mu,sig)) text(vlines[1]+.25*sig,0.015,expression(mu-2*sigma)) text(vlines[2]+.25*sig,0.015,expression(mu-sigma)) text(vlines[3]+.2*sig,0.015,expression(mu)) text(vlines[4]+.25*sig,0.015,expression(mu+sigma)) text(vlines[5]+.25*sig,0.015,expression(mu+2*sigma)) for (i in 1:n) { X <- XX[i] Z <- (X-mu)/sig pch <- floor(abs(Z))+1 # This will give different plotting symbols # depending on Z score pch <- ifelse(pch>2,5,pch) points(X,0,pch=pch) } legend("topleft",c("Within 1 SD","Between 1 and 2 SDs","Two or more SDs"), pch=c(1,2,5)) img(src = "normEst.png") ; br(2) lf(2) cat("About 68% of the points should be within 1 SD. About 5% of the points should be greater than 5%") lf(2) cat("You can copy and paste the histogram picture to use in other reports.") lf(2) cat("To try other data, or other values for the parameters," cat("hit the back button on your browser.") lf() cat("The author is ") mailto("Russell Almond", "ralmond@admin.fsu.edu") lf() tag(p) cat("Output produced at ", date()) untag(p) lf() untag(BODY) lf() untag(HTML) lf()