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. 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. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("urn-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('urn') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "urn" > > ### * urn > > flush(stderr()); flush(stdout()) > > ### Name: urn > ### Title: Repeated Sampling Without Replacement > ### Aliases: urn sampleu refill.urn > ### Keywords: datagen distribution > > ### ** Examples > > > library(urn) > > # Create urn with 3 items > u<-urn(list(1,2,3)) > > # custom print and summary methods > print(u ) List type: current: 1, 2, 3 initial: 1, 2, 3 > summary(u) 1 2 3 1 1 1 > > # draw 2 samples from the urn > sampleu(u,2) [[1]] [1] 1 [[2]] [1] 3 > # can't sample more items than in the urn, without refilling: > # sampleu(u,2) > sum(u) [1] 1 > sampleu(u,1) [[1]] [1] 2 > # refill > refill.urn(u) [1] 3 > # Create an urn with 100010 items of two types in ~51:49 proportions > ub<-urn(c(51006,49004)) > summary(ub) A B 51006 49004 > > # take ten draws each of 10001 items > rep<-replicate(10, table(sampleu(ub,10001)), simplify=TRUE) > print(rep) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] 1 5144 5095 5163 5072 4999 5091 5091 5108 5162 5081 2 4857 4906 4838 4929 5002 4910 4910 4893 4839 4920 > > # should equal 51006 > sum(rep[1,]) [1] 51006 > > > > > ### *