#Biostatistics 070 #COMMANDS FOR PROBABILITY DISTRIBUTIONS IN R #FOR INFORMATION ON FUNCTIONS ? dnorm() ? dt() ? dchisq() ? df() ? dbinom() # BINOMIAL DISTRIBUTION: # SETS UP VARIABLE X AS A RANGE x=seq(0,20,1) #NUMBER OF TRIALS: n=20 #PROBABILITY p=0.5 dist=dbinom(x,n,p) plot(dist,type="s") # NORMAL DISTRIBUTION: # SETS UP VARIABLE X AS A RANGE x=seq(-4,4,0.1) # SPECIFY MEAN (mu) & # STANDARD DEVIATION (sigma) mu=0 sigma=1 dist=dnorm(x,mu,sigma) plot(dist, type="p") #STUDENT'S t DISTRIBUTION: # SETS UP VARIABLE X AS A RANGE x=seq(-4,4,0.1) # SPECIFY DEGREES OF FREEDOM dft=1 #PLOTTING WITH LINE TYPE “1” (the letter l) dist=dt(x,dft) plot(dist,type="l") # CHI-SQUARE DISTRIBUTION: # SETS UP VARIABLE X AS A RANGE x=seq(0,8,0.1) # SPECIFY DEGREES OF FREEDOM dfchisq=5 #PLOTTING dist=dchisq(x,dfchisq) plot(dist) # F DISTRIBUTION: # SETS UP VARIABLE X AS A RANGE x=seq(0,8,0.1) # SPECIFY DEGREES OF FREEDOM dfF1=2 dfF2=7 #PLOTTING dist=df(x,dfF1,dfF2) plot(dist) #p AND q FUNCTIONS FOR EACH DISTRIBUTION: #PQ FUNCTIONS FOR BINOMIAL DISTRIBUTION: n=20 p=0.50 x=5 PHI=0.95 pbinom(x,n,p) qbinom(PHI,n,p) #PQ FUNCTIONS FOR NORMAL DISTRIBUTION: mu=0 sigma=1 x=1.6449 PHI=0.90 pnorm(x,mu,sigma) qnorm(PHI,mu,sigma) #PQ FUNCTIONS FOR STUDENT'S t DISTRIBUTION: dft=1 x=1.6449 PHI=0.90 pt(x,dft) qt(PHI,dft) #PQ FUNCTIONS FOR CHISQ DISTRIBUTION: dfchisq=1 x=1.6449 PHI=0.90 pchisq(x,dfchisq) qchisq(PHI,dfchisq) #PQ FUNCTIONS FOR F DISTRIBUTION: dfF1=2 dfF2=7 x=1.6449 PHI=0.95 pf(x,dfF1,dfF2) qf(PHI,dfF1,dfF2) # PSEUDO-RANDOM VECTORS: # SPECIFY VECTOR LENGTH m m=1000 # SPECIFY PARAMETERS: mu=0 sigma=1 dft=1 dfchisq=3 dfF1=2 dfF2=7 n=20 p=0.50 Knorm=rnorm(m,mu,sigma) Kt=rt(m,dft) Kchisq=rchisq(m,dfchisq) KF=rf(m,dfF1,dfF2) Kbinom=rbinom(m,n,p) # MAKE HISTOGRAMS: hist(Knorm) hist(Kt) hist(Kchisq) hist(KF) hist(Kbinom)