##################################################################################### ## ## Intro STATS : Normal Distributions ## JDRS ## http://www.reuningscherer.net/stat10x/r/ ## ##################################################################################### #NOTE - need the car package for some of the functions below library(car) #Get WB Data WB <- read.csv("http://reuningscherer.net/stat10x/data/WorldBank2013.csv") #see variables available names(WB) #draw a quick normal density curve plot(seq(-4,4,by=.01), dnorm(seq(-4,4,by=.01)), type="l", lwd=3, col='blue', ylab="Normal Density Height", main="Standard Normal Density Curve", xlab="z-score") ########################################################################################### ## Normal Density Probabilities (Prob of getting value less than or equal to specified value) ## See example on Page 82 of notes - mean=6.6, sd=1.4, what is prob of 8 or less? pnorm(8,6.6,1.4) #prob of 5 or less pnorm(5,6.6,1.4) ################################################################## ## Normal Quantile Plots ## ## NOTE - both plots below have data on VERTICAL axis (opposite of MINITAB) #Quantile plot for Life Expectancy qqnorm(WB$Fertility, pch=19, col='blue') qqline(WB$Fertility, col='red', lwd=2) #Quantile plot function with bounds - from car package qqPlot(WB$Fertility, dist="norm", pch=19, col='blue', ylab="Fertility Rate Data", main="Normal Quantile plot of Fertility Rates") #Quantile plot of Percent Urban qqPlot(WB$Rural, dist="norm", pch=19, col='blue', ylab="Rural Rate Data", main="Normal Quantile plot of Rural Pct") #Do random data for sample sizes, 5, 50, 500 qqPlot(rnorm(5), dist="norm", pch=19, col='blue', ylab="Rural Rate Data", main="Normal Quantile Plot, 5 Rand Normal Obs") qqPlot(rnorm(50), dist="norm", pch=19, col='blue', ylab="Rural Rate Data", main="Normal Quantile Plot, 50 Rand Normal Obs") qqPlot(rnorm(500), dist="norm", pch=19, col='blue', ylab="Rural Rate Data", main="Normal Quantile Plot, 500 Rand Normal Obs")