#Random variables- generating, distribution functions #0. random number seed; fix for reproducible simulations i <- 5 set.seed(i) #i must be between 0 and 1000 # the same effect can be created by saving .Random.seed and then # assigning that value to .Random.seed later. #1. random sampling z <- c(18,22,15,25,36) sample(x=z,size=3,replace=F) #take a SRS w/o replacement from z sample(x=z,size=3,replace=T) #now w/ replacement; as for bootstrap sample(x=z,size=3,replace=T,prob=c(0.1, 0.3, 0.2, 0.1, 0.3)) #unequal prob sampling #2. univariate random variable generation (see p. 164, Table 5.1) #beta, binomial, Cauchy, normal, lognormal, gamma, F, poisson, Chi-square rbeta(n=10,shape1=3,shape2=4) # ten obs'ns from Beta(3,4) rbinom(n=10,size=100,prob=0.2) # ten obs'ns from Binomial(100,0.2) rnorm(n=10,mean=20,sd=5.1) # ten obs'ns from Normal(20,5.1^2) rpois(n=30,lambda=3) # ten obs'ns from Poisson(3) #3. percentages- for P-values in particular; can discard tables in back of stat texts... pnorm(q=1.645,mean=0,sd=1) 1-pf(q=5.7,df1=3,df2=15) #4. quantiles- for test statistics, for example qt(p=0.975,df=21) #5. density function value; or probability for discrete valued rv dnorm(x=0.5,mean=0,sd=1) dpois(x=1,lambda=2)