#dnorm(x) returns the height of the probability distribution at each point x. dnorm(0) #1/sqrt(2*pi) dnorm(0)*sqrt(2*pi) dnorm(0,mean=4,sd=10) x <- seq(-5,5,by=.01) y <- dnorm(x) plot(x,y) plot(x,y,type="l") y <- dnorm(x,mean=2.5,sd=.5) plot(x,y,type="l") #pnorm(x) returns the P(X<=x) for a Normal RV - the Cumulative Distribution Function (CDF) pnorm(0) pnorm(1.96) #qnorm(x) returns the xth quantile for a Normal distribution (the inverse of pnorm) qnorm(.025) qnorm(.975) #rnorm(n) returns n random deviates from a normal distribution y <- rnorm(200,mean=-2,sd=4) hist(y) #Binomial Distribution x <- seq(0,20,by=1) y <- dbinom(x,20,0.2); names(y) <- x barplot(y) y <- dbinom(x,20,0.6); names(y) <- x barplot(y) pbinom( 8,20,0.6) pbinom(12,20,0.6) qbinom(0.6,20,1/2) #--------------------------------------------- #cor(x,y) correlation between variables x & y x <- rnorm(500) y <- 3*(x+rnorm(500,sd=2)) plot(x,y) cor(x,y) y <- 3*(x+rnorm(500,sd=1)) plot(x,y) cor(x,y) http://www.cyclismo.org/tutorial/R/