R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for a HTML browser interface to help. Type 'q()' to quit R. > # pqdfns Sept 2007 > # > # demo of probability functions > # pdist gives cdf P(x) > # qdist gives quantile q(p) or P(q(p))=p > # ddist gives density > # > # > # first some normals > # > pnorm(1.96) # P(1.96) [1] 0.9750021 > pnorm(1.96, lower.tail=F) # 1-P(1.96) [1] 0.02499790 > pnorm(1.96, lower.tail=F, log.p=T) # log(1-P(1.96)) [1] -3.688964 > # just a simple check > log(.05) [1] -2.995732 > # go far into tail > pnorm(100, lower.tail=F, log.p=T) # -x*x/2 - log x - stuff [1] -5005.524 > # quantiles > qnorm(.025) [1] -1.959964 > qnorm(.95) [1] 1.644854 > # go far into tail > qnorm(1e-6) # one in a million [1] -4.753424 > qnorm(log(1e-6), log.p=T) [1] -4.753424 > # > # now Student's t > # > pt(1,df=1) # Cauchy symmetries [1] 0.75 > qt(.25,1) [1] -1 > df <- 5:10 # can it do a vector? > pt(2.306,df) # vague memory of a critical value [1] 0.9653740 0.9697000 0.9727465 0.9749998 0.9767299 0.9780977 > qt(.975,df) [1] 2.570582 2.446912 2.364624 2.306004 2.262157 2.228139 > qt(1.e-4,10000) # far in tail, big df [1] -3.720396 > # > # gamma and Poisson > # > pgamma(2*log(2),1) # 1 - 2**(-2) [1] 0.75 > pgamma(4,3) # incomplete gamma to 4, shape 3 [1] 0.7618967 > x <- 4 > (1 + x + x*x/2)*exp(-x) # check [1] 0.2381033 > 2*qgamma(.95,df/2) # chi-square with manydf [1] 11.07050 12.59159 14.06714 15.50731 16.91898 18.30704 > lam = .3 # Poisson rate > (1+lam)*exp(-lam) # Pr(X=0) + Pr(X=1) [1] 0.9630637 > pgamma(.3,2,lower.tail=F) # upper tail [1] 0.9630637 > # > # beta and binomial > # > pbinom(0:8,8,.4) # Binomial df, n=8, p=.4 [1] 0.01679616 0.10637568 0.31539456 0.59408640 0.82632960 0.95019264 0.99148032 [8] 0.99934464 1.00000000 > p <- dbinom(0:8,8,.4) # Binomial probs, n=8, p=.4 > p [1] 0.01679616 0.08957952 0.20901888 0.27869184 0.23224320 0.12386304 0.04128768 [8] 0.00786432 0.00065536 > cumsum(p) # check df [1] 0.01679616 0.10637568 0.31539456 0.59408640 0.82632960 0.95019264 0.99148032 [8] 0.99934464 1.00000000 > sum(p*log(p)) # information [1] -1.740283 > pbinom(0:6,6,.4) # cumulatives [1] 0.046656 0.233280 0.544320 0.820800 0.959040 0.995904 1.000000 > pbinom(3,6,.4) # Pr(X=0)+Pr(X=1)+Pr(X=2)+Pr(X=3) [1] 0.8208 > pbeta(.4,4,3,lower.tail=F) # using incomplete beta function [1] 0.8208 > # > # done > rm(list=ls()) > q()