#Biostatistics 100 #ANALOGOUS FUNCTIONS FOR #NORMAL AND T DISTRIBUTIONS #NORMAL DISTRIBUTION mu=0 #parameter for mean sigma=1 #paramater for standard deviation n=1000 #number of randomly generated data points X=1.96 #quantile X P=0.95 # cumulative probability phi(X) rnorm(n,mu,sigma) #to generate random data points dnorm(X,mu,sigma) #P(X) from X pnorm(X,mu,sigma) #phi(X) from X qnorm(P,mu,sigma) #X from phi(X) #t DISTRIBUTION df=5 #degrees of freedom parameter n=1000 #number of randomly generated data points X=1.96 #quantile X P=0.95 # cumulative probability phi(X) rt(n,df) #to generate random data points dt(X,df) #P(X) from X pt(X,df) #phi(X) from X qt(P,df) #X from phi(X) #CONFIDENCE INTERVALS mu=50 sigma=10 n=100 X=rnorm(100,mu,sigma) alpha=0.05 #NORMAL DISTRIBUTION L=qnorm((alpha/2),0,1) L U=qnorm((1-alpha/2),0,1) U #confidence interval: mu+L*(sigma/sqrt(n)) mu+U*(sigma/sqrt(n)) #t DISTRIBUTION df=n-1 s=sqrt(var(X)) L=qt((alpha/2),df) L U=qt((1-alpha/2),df) U #confidence interval: mu+L*(s/sqrt(n)) mu+U*(s/sqrt(n)) #NOTE: These values don't match MathCad #because they are based on a different sample!