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("distr-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('distr') Loading required package: setRNG > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "AbscontDistribution-class" > > ### * AbscontDistribution-class > > flush(stderr()); flush(stdout()) > > ### Name: AbscontDistribution-class > ### Title: Class "AbscontDistribution" > ### Aliases: AbscontDistribution-class > ### initialize,AbscontDistribution-method > ### Keywords: distribution > > ### ** Examples > > N = Norm() # N is a normal distribution with mean=0 and sd=1. > E = Exp() # E is an exponential distribution with rate=1. > A1 = E+1 # a new absolutely continuous distributions with exact slots d, p, q > A2 = A1*3 # a new absolutely continuous distributions with exact slots d, p, q > A3 = N*0.9 + E*0.1 # a new absolutely continuous distribution with approximated slots d, p, q > r(A3)(1) # one random number generated from this distribution, e.g. -0.7150937 [1] -0.5492378 > d(A3)(0) # The (approximated) density for x=0 is 0.4379882. [1] 0.4379965 > p(A3)(0) # The (approximated) probability that x <= 0 is 0.4562021. [1] 0.4561991 > q(A3)(.1) # The (approximated) 10 percent quantile is 0.1. [1] -1.060143 > > > > cleanEx(); ..nameEx <- "Beta-class" > > ### * Beta-class > > flush(stderr()); flush(stdout()) > > ### Name: Beta-class > ### Title: Class "Beta" > ### Aliases: Beta-class Beta initialize,Beta-method > ### Keywords: distribution > > ### ** Examples > > B <- Beta(shape1 = 1, shape2 = 1) > # B is a beta distribution with shape1 = 1 and shape2 = 1. > r(B)(1) # one random number generated from this distribution, e.g. 0.6979795 [1] 0.7344913 > d(B)(1) # Density of this distribution is 1 for x=1. [1] 1 > p(B)(1) # Probability that x < 1 is 1. [1] 1 > q(B)(.1) # Probability that x < 0.1 is 0.1. [1] 0.1 > shape1(B) # shape1 of this distribution is 1. [1] 1 > shape1(B) <- 2 # shape1 of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "BetaParameter-class" > > ### * BetaParameter-class > > flush(stderr()); flush(stdout()) > > ### Name: BetaParameter-class > ### Title: Class "BetaParameter" > ### Aliases: BetaParameter-class initialize,BetaParameter-method > > > ### ** Examples > > W <- new("BetaParameter", shape1 = 1, shape2 = 1) > shape2(W) # shape2 of this distribution is 1. [1] 1 > shape2(W) <- 2 # shape2 of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "Binom-class" > > ### * Binom-class > > flush(stderr()); flush(stdout()) > > ### Name: Binom-class > ### Title: Class "Binom" > ### Aliases: Binom-class Binom initialize,Binom-method > ### Keywords: distribution > > ### ** Examples > > B=Binom(prob=0.5,size=1) # B is a binomial distribution with prob=0.5 and size=1. > r(B)(1) # # one random number generated from this distribution, e.g. 1 [1] 0 > d(B)(1) # Density of this distribution is 0.5 for x=1. [1] 0.5 > p(B)(0.4) # Probability that x<0.4 is 0.5. [1] 0.5 > q(B)(.1) # x=0 is the smallest value x such that p(B)(x)>=0.1. [1] 0 > size(B) # size of this distribution is 1. [1] 1 > size(B)=2 # size of this distribution is now 2. > C=Binom(prob=0.5,size=1) # C is a binomial distribution with prob=0.5 and size=1. > D=Binom(prob=0.6,size=1) # D is a binomial distribution with prob=0.6 and size=1. > E=B+C # E is a binomial distribution with prob=0.5 and size=3. > F=B+D # F is an object of class DiscreteDistribution. > > > > cleanEx(); ..nameEx <- "BinomParameter-class" > > ### * BinomParameter-class > > flush(stderr()); flush(stdout()) > > ### Name: BinomParameter-class > ### Title: Class "BinomParameter" > ### Aliases: BinomParameter-class initialize,BinomParameter-method > > > ### ** Examples > > W=new("BinomParameter",prob=0.5,size=1) > size(W) # size of this distribution is 1. [1] 1 > size(W)=2 # size of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "Cauchy-class" > > ### * Cauchy-class > > flush(stderr()); flush(stdout()) > > ### Name: Cauchy-class > ### Title: Class "Cauchy" > ### Aliases: Cauchy-class Cauchy initialize,Cauchy-method > ### Keywords: distribution > > ### ** Examples > > C=Cauchy(location=1,scale=1) # C is a Cauchy distribution with location=1 and scale=1. > r(C)(1) # one random number generated from this distribution, e.g. 4.104603 [1] 2.10252 > d(C)(1) # Density of this distribution is 0.3183099 for x=1. [1] 0.3183099 > p(C)(1) # Probability that x<1 is 0.5. [1] 0.5 > q(C)(.1) # Probability that x<-2.077684 is 0.1. [1] -2.077684 > location(C) # location of this distribution is 1. [1] 1 > location(C)=2 # location of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "CauchyParameter-class" > > ### * CauchyParameter-class > > flush(stderr()); flush(stdout()) > > ### Name: CauchyParameter-class > ### Title: Class "CauchyParameter" > ### Aliases: CauchyParameter-class initialize,CauchyParameter-method > > > ### ** Examples > > W=new("CauchyParameter",location=1,scale=1) > location(W) # location of this distribution is 1. [1] 1 > location(W)=2 # location of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "Chisq-class" > > ### * Chisq-class > > flush(stderr()); flush(stdout()) > > ### Name: Chisq-class > ### Title: Class "Chisq" > ### Aliases: Chisq-class Chisq initialize,Chisq-method > ### Keywords: distribution > > ### ** Examples > > C <- Chisq(df = 1, ncp = 1) # C is a chi-squared distribution with df=1 and ncp=1. > r(C)(1) # one random number generated from this distribution, e.g. 0.2557184 [1] 3.052466 > d(C)(1) # Density of this distribution is 0.2264666 for x = 1. [1] 0.2264666 > p(C)(1) # Probability that x < 1 is 0.4772499. [1] 0.4772499 > q(C)(.1) # Probability that x < 0.04270125 is 0.1. [1] 0.04270125 > df(C) # df of this distribution is 1. [1] 1 > df(C) <- 2 # df of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "ChisqParameter-class" > > ### * ChisqParameter-class > > flush(stderr()); flush(stdout()) > > ### Name: ChisqParameter-class > ### Title: Class "ChisqParameter" > ### Aliases: ChisqParameter-class initialize,ChisqParameter-method > > > ### ** Examples > > W=new("ChisqParameter",df=1,ncp=1) > ncp(W) # ncp of this distribution is 1. [1] 1 > ncp(W)=2 # ncp of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "Contsimulation-class" > > ### * Contsimulation-class > > flush(stderr()); flush(stdout()) > > ### Name: Contsimulation-class > ### Title: Class "Contsimulation" > ### Aliases: Contsimulation-class Contsimulation > ### initialize,Contsimulation-method > > > ### ** Examples > > N <- Norm() # N is a standard normal distribution. > C <- Cauchy() # C is a Cauchy distribution > cs <- Contsimulation(filename = "csim", + runs = 10, + samplesize = 3, + seed = setRNG(), + distribution.id = N, + distribution.c = C, + rate = 0.1) > simulate(cs) > # Each of the 30 random numbers is ideal (N-distributed) with > # probability 0.9 and contaminated (C-distributed) with > # probability = 0.1 > summary(cs) name of simulation: csim number of runs: 10 size of sample: 3 rate of contamination: 0.1 real Data: [,1] [,2] [,3] [,4] [,5] [,6] Min. -0.6265 0.1836 -0.83560 -1.9890 0.3295 -0.82050 1st Qu. 0.4427 0.2867 -0.72840 -0.1970 0.4747 -0.43830 Median 1.5120 0.3898 -0.62120 1.5950 0.6198 -0.05613 Mean 1.8960 0.4519 -0.46080 0.4478 0.6914 -0.30720 3rd Qu. 3.1570 0.5860 -0.27330 1.6660 0.8724 -0.05053 Max. 4.8030 0.7821 0.07456 1.7380 1.1250 -0.04493 > Data(cs) # different data [,1] [,2] [,3] [1,] -0.6264538 1.51178117 4.80293716 [2,] 0.1836433 0.38984324 0.78213630 [3,] -0.8356286 -0.62124058 0.07456498 [4,] 1.5952808 1.73761346 -1.98935170 [5,] 0.3295078 1.12493092 0.61982575 [6,] -0.8204684 -0.04493361 -0.05612874 [7,] 0.4874291 -0.01619026 -0.15579551 [8,] 0.7383247 0.94383621 -1.47075238 [9,] 0.5757814 -0.84154958 -0.47815006 [10,] -0.3053884 0.59390132 0.41794156 > savedata(cs) # saves the object in the working directory of R... > load("csim") # loads it again... > Data(cs) # ...without the data - use simulate to return it! NULL > > > > cleanEx(); ..nameEx <- "Dataclass-class" > > ### * Dataclass-class > > flush(stderr()); flush(stdout()) > > ### Name: Dataclass-class > ### Title: Class "Dataclass" > ### Aliases: Dataclass-class Dataclass initialize,Dataclass-method > > > ### ** Examples > > D <- Dataclass(Data = matrix(c(1,2,3,4,5,6),2), + filename = "xyz.sav") > # A new object of type "Dataclass" is created. > savedata(D) > # creates a file called "xyz.sav" where the information is saved and a > # copy "xyz.sav.comment" without data > Data(D) <- matrix(c(11,12,13,14,15,16),2) # changes the data of D > cload("xyz.sav") # loads the object without data - it is called "D.comment" > D.comment filename of Dataclass: xyz.sav number of runs: 2 size of sample: 3 > load("xyz.sav") # loads the original object "D" > Data(D) # the original data: matrix(c(1,2,3,4,5,6),2) [,1] [,2] [,3] [1,] 1 3 5 [2,] 2 4 6 > evaluate(object = D, estimator = mean) # returns the mean of each variable An Evaluation Object name of Dataobject: D name of Datafile: xyz.sav estimator: mean Result: num [1:2] 3 4 > > > > cleanEx(); ..nameEx <- "Dirac-class" > > ### * Dirac-class > > flush(stderr()); flush(stdout()) > > ### Name: Dirac-class > ### Title: Class "Dirac" > ### Aliases: Dirac-class Dirac initialize,Dirac-method > ### Keywords: distribution > > ### ** Examples > > D <- Dirac(location = 0) # D is a Dirac distribution with location=0. > r(D)(1) [1] 0 > # r(D)(1) generates a pseudo-random-number according to a Dirac > # distribution with location = 0, > # which of course will take 0 as value almost surely. > d(D)(0) # Density of this distribution is 1 for x = 0. [1] 1 > p(D)(1) # Probability that x < 1 is 1. [1] 1 > q(D)(.1) # q(D)(x) is always 0 (= location). [1] 0 > location(D) # location of this distribution is 0. [1] 0 > location(D) <- 2 # location of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "DiracParameter-class" > > ### * DiracParameter-class > > flush(stderr()); flush(stdout()) > > ### Name: DiracParameter-class > ### Title: Class "DiracParameter" > ### Aliases: DiracParameter-class initialize,DiracParameter-method > > > ### ** Examples > > W=new("DiracParameter",location=1) > location(W) # location of this distribution is 1. [1] 1 > location(W)=2 # location of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "DiscreteDistribution-class" > > ### * DiscreteDistribution-class > > flush(stderr()); flush(stdout()) > > ### Name: DiscreteDistribution-class > ### Title: Class "DiscreteDistribution" > ### Aliases: DiscreteDistribution-class > ### initialize,DiscreteDistribution-method > ### Keywords: distribution > > ### ** Examples > > B = Binom(prob=0.1,size=10) # B is a Binomial distribution with prob=0.1 and size=10. > P = Pois(lambda=1) # P is a Poisson distribution with lambda=1. > D1 = B+1 # a new discrete distributions with exact slots d, p, q > D2 = D1*3 # a new discrete distributions with exact slots d, p, q > D3 = B+P # a new discrete distributions with approximated slots d, p, q > D4 = D1+P # a new discrete distributions with approximated slots d, p, q > support(D4) # the (approximated) support of this distribution is 1, 2, ..., 21 [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 > r(D4)(1) # one random number generated from this distribution, e.g. 4 [1] 2 > d(D4)(1) # The (approximated) density for x=1 is 0.1282716. [1] 0.1282716 > p(D4)(1) # The (approximated) probability that x<=1 is 0.1282716. [1] 0.1282716 > q(D4)(.5) # The (approximated) 50 percent quantile is 3. [1] 3 > > > > cleanEx(); ..nameEx <- "EuclideanSpace-class" > > ### * EuclideanSpace-class > > flush(stderr()); flush(stdout()) > > ### Name: EuclideanSpace-class > ### Title: Class "EuclideanSpace" > ### Aliases: EuclideanSpace-class initialize,EuclideanSpace-method > > > ### ** Examples > > E=new("EuclideanSpace",dimension=2) > dimension(E) # The dimension of this space is 2. [1] 2 > dimension(E)=3 # The dimension of this space is now 3. > liesIn(E,c(0,0,0)) # TRUE [1] TRUE > liesIn(E,c(0,0)) # FALSE [1] FALSE > > > > cleanEx(); ..nameEx <- "Evaluation-class" > > ### * Evaluation-class > > flush(stderr()); flush(stdout()) > > ### Name: Evaluation-class > ### Title: Class "Evaluation" > ### Aliases: Evaluation-class initialize,Evaluation-method > > > ### ** Examples > > N <- Norm() # N is a standard normal distribution. > C <- Cauchy() # C is a Cauchy distribution > cs <- Contsimulation(filename = "csim", + runs = 5, + samplesize=5000, + seed=setRNG(), + distribution.id = N, + distribution.c = C, + rate = 0.1) > simulate(cs) > # Each of the 25000 random numbers is ideal (N-distributed) with > # probability 0.9 and contaminated (C-distributed) with probability = 0.1 > summary(cs) name of simulation: csim number of runs: 5 size of sample: 5000 rate of contamination: 0.1 real Data: [,1] [,2] [,3] [,4] [,5] Min. -1.033e+02 -1.725e+02 -339.10000 -4.633e+02 -6.713e+01 1st Qu. -7.080e-01 -6.981e-01 -0.69920 -6.746e-01 -6.808e-01 Median 3.138e-03 -2.468e-03 -0.01819 2.946e-03 -7.169e-03 Mean -3.604e-02 3.034e-02 -0.09989 -1.779e-01 4.324e-01 3rd Qu. 7.001e-01 7.237e-01 0.65800 6.824e-01 6.791e-01 Max. 1.315e+02 8.266e+01 113.30000 3.011e+02 1.753e+03 > ev1 <- evaluate(cs, mean) # estimates the data with mean > ev1 # bad results An Evaluation Object name of Dataobject: cs name of Datafile: csim estimator: mean Result: num [1:5] -0.0360 0.0303 -0.0999 -0.1779 0.4324 > ev2 <- evaluate(cs,median) # estimates the data with median > ev2 # better results because median is robust An Evaluation Object name of Dataobject: cs name of Datafile: csim estimator: median Result: num [1:5] 0.00314 -0.00247 -0.01819 0.00295 -0.00717 > savedata(ev1) > # saves the evaluation with result as "csim.mean" and without result as > # "csim.mean.comment" in the working directory # of R - "csim" is the > # filename of the Contsimulation object, mean the name of the estimator > rm(ev1) > cload("csim.mean") > # loads the evaluation without result - the object is called ev1.comment > ev1.comment An Evaluation Object name of Dataobject: cs name of Datafile: csim estimator: mean Result: NULL > load("csim.mean") # loads the evaluation with result > ev1 An Evaluation Object name of Dataobject: cs name of Datafile: csim estimator: mean Result: num [1:5] -0.0360 0.0303 -0.0999 -0.1779 0.4324 > > > > cleanEx(); ..nameEx <- "Exp-class" > > ### * Exp-class > > flush(stderr()); flush(stdout()) > > ### Name: Exp-class > ### Title: Class "Exp" > ### Aliases: Exp-class Exp initialize,Exp-method > ### Keywords: distribution > > ### ** Examples > > E <- Exp(rate = 1) # E is a exp distribution with rate = 1. > r(E)(1) # one random number generated from this distribution, e.g. 0.4190765 [1] 0.7551818 > d(E)(1) # Density of this distribution is 0.3678794 for x = 1. [1] 0.3678794 > p(E)(1) # Probability that x < 1 is 0.6321206. [1] 0.6321206 > q(E)(.1) # Probability that x < 0.1053605 is 0.1. [1] 0.1053605 > rate(E) # rate of this distribution is 1. [1] 1 > rate(E) <- 2 # rate of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "ExpParameter-class" > > ### * ExpParameter-class > > flush(stderr()); flush(stdout()) > > ### Name: ExpParameter-class > ### Title: Class "ExpParameter" > ### Aliases: ExpParameter-class initialize,ExpParameter-method > > > ### ** Examples > > W=new("ExpParameter", rate=1) > rate(W) # rate of this distribution is 1. [1] 1 > rate(W)=2 # rate of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "FParameter-class" > > ### * FParameter-class > > flush(stderr()); flush(stdout()) > > ### Name: FParameter-class > ### Title: Class "FParameter" > ### Aliases: FParameter-class initialize,FParameter-method > > > ### ** Examples > > W <- new("FParameter", df1 = 1, df2 = 1) > df2(W) # df2 of this distribution is 1. [1] 1 > df2(W) <- 2 # df2 of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "Fd-class" > > ### * Fd-class > > flush(stderr()); flush(stdout()) > > ### Name: Fd-class > ### Title: Class "Fd" > ### Aliases: Fd-class Fd initialize,Fd-method > ### Keywords: distribution > > ### ** Examples > > F=Fd(df1=1,df2=1) # F is a F distribution with df=1 and df2=1. > r(F)(1) # one random number generated from this distribution, e.g. 29.37863 [1] 0.1781142 > d(F)(1) # Density of this distribution is 0.1591549 for x=1 . [1] 0.1591549 > p(F)(1) # Probability that x<1 is 0.5. [1] 0.5 > q(F)(.1) # Probability that x<0.02508563 is 0.1. [1] 0.02508563 > df1(F) # df1 of this distribution is 1. [1] 1 > df1(F)=2 # df1 of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "GammaParameter-class" > > ### * GammaParameter-class > > flush(stderr()); flush(stdout()) > > ### Name: GammaParameter-class > ### Title: Class "GammaParameter" > ### Aliases: GammaParameter-class initialize,GammaParameter-method > > > ### ** Examples > > W=new("GammaParameter",scale=1,shape=1) > shape(W) # shape of this distribution is 1. [1] 1 > shape(W)=2 # shape of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "Gammad-class" > > ### * Gammad-class > > flush(stderr()); flush(stdout()) > > ### Name: Gammad-class > ### Title: Class "Gammad" > ### Aliases: Gammad-class Gammad initialize,Gammad-method > ### Keywords: distribution > > ### ** Examples > > G=Gammad(scale=1,shape=1) # G is a gamma distribution with scale=1 and shape=1. > r(G)(1) # one random number generated from this distribution, e.g. 0.1304441 [1] 0.1551414 > d(G)(1) # Density of this distribution is 0.3678794 for x=1. [1] 0.3678794 > p(G)(1) # Probability that x<1 is 0.6321206. [1] 0.6321206 > q(G)(.1) # Probability that x<0.1053605 is 0.1. [1] 0.1053605 > scale(G) # scale of this distribution is 1. [1] 1 > scale(G)=2 # scale of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "Geom-class" > > ### * Geom-class > > flush(stderr()); flush(stdout()) > > ### Name: Geom-class > ### Title: Class "Geom" > ### Aliases: Geom-class Geom initialize,Geom-method > ### Keywords: distribution > > ### ** Examples > > G <- Geom(prob = 0.5) # G is a geometric distribution with prob = 0.5. > r(G)(1) # one random number generated from this distribution, e.g. 0 [1] 0 > d(G)(1) # Density of this distribution is 0.25 for x = 1. [1] 0.25 > p(G)(1) # Probability that x<1 is 0.75. [1] 0.75 > q(G)(.1) # x = 0 is the smallest value x such that p(G)(x) >= 0.1. [1] 0 > prob(G) # prob of this distribution is 0.5. [1] 0.5 > prob(G) <- 0.6 # prob of this distribution is now 0.6. > > > > cleanEx(); ..nameEx <- "GeomParameter-class" > > ### * GeomParameter-class > > flush(stderr()); flush(stdout()) > > ### Name: GeomParameter-class > ### Title: Class "GeomParameter" > ### Aliases: GeomParameter-class initialize,GeomParameter-method > > > ### ** Examples > > W=new("GeomParameter",prob=0.5) > prob(W) # prob of this distribution is 0.5. [1] 0.5 > prob(W)=0.4 # prob of this distribution is now 0.4. > > > > cleanEx(); ..nameEx <- "Hyper-class" > > ### * Hyper-class > > flush(stderr()); flush(stdout()) > > ### Name: Hyper-class > ### Title: Class "Hyper" > ### Aliases: Hyper-class Hyper initialize,Hyper-method > ### Keywords: distribution > > ### ** Examples > > H=Hyper(m=3,n=3,k=3) # H is a hypergeometric distribution with m=3,n=3,k=3. > r(H)(1) # one random number generated from this distribution, e.g. 2 [1] 2 > d(H)(1) # Density of this distribution is 0.45 for x=1. [1] 0.45 > p(H)(1) # Probability that x<1 is 0.5. [1] 0.5 > q(H)(.1) # x=1 is the smallest value x such that p(H)(x)>=0.1. [1] 1 > m(H) # m of this distribution is 3. [1] 3 > m(H)=2 # m of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "HyperParameter-class" > > ### * HyperParameter-class > > flush(stderr()); flush(stdout()) > > ### Name: HyperParameter-class > ### Title: Class "HyperParameter" > ### Aliases: HyperParameter-class initialize,HyperParameter-method > > > ### ** Examples > > W=new("HyperParameter",k=3, m=3, n=3) > m(W) # m of this distribution is 3. [1] 3 > m(W)=2 # m of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "Lnorm-class" > > ### * Lnorm-class > > flush(stderr()); flush(stdout()) > > ### Name: Lnorm-class > ### Title: Class "Lnorm" > ### Aliases: Lnorm-class Lnorm initialize,Lnorm-method > ### Keywords: distribution > > ### ** Examples > > L=Lnorm(meanlog=1,sdlog=1) # L is a lnorm distribution with mean=1 and sd=1. > r(L)(1) # one random number generated from this distribution, e.g. 3.608011 [1] 1.452878 > d(L)(1) # Density of this distribution is 0.2419707 for x=1. [1] 0.2419707 > p(L)(1) # Probability that x<1 is 0.1586553. [1] 0.1586553 > q(L)(.1) # Probability that x<0.754612 is 0.1. [1] 0.754612 > meanlog(L) # meanlog of this distribution is 1. [1] 1 > meanlog(L)=2 # meanlog of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "LnormParameter-class" > > ### * LnormParameter-class > > flush(stderr()); flush(stdout()) > > ### Name: LnormParameter-class > ### Title: Class "LnormParameter" > ### Aliases: LnormParameter-class initialize,LnormParameter-method > > > ### ** Examples > > W=new("LnormParameter",sdlog=1,meanlog=0) > meanlog(W) # meanlog of this distribution is 0. [1] 0 > meanlog(W)=2 # meanlog of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "Logis-class" > > ### * Logis-class > > flush(stderr()); flush(stdout()) > > ### Name: Logis-class > ### Title: Class "Logis" > ### Aliases: Logis-class Logis initialize,Logis-method > ### Keywords: distribution > > ### ** Examples > > L <- Logis(location = 1,scale = 1) > # L is a logistic distribution with location = 1 and scale = 1. > r(L)(1) # one random number generated from this distribution, e.g. 5.87557 [1] -0.01753073 > d(L)(1) # Density of this distribution is 0.25 for x = 1. [1] 0.25 > p(L)(1) # Probability that x < 1 is 0.5. [1] 0.5 > q(L)(.1) # Probability that x < -1.197225 is 0.1. [1] -1.197225 > location(L) # location of this distribution is 1. [1] 1 > location(L) <- 2 # location of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "LogisParameter-class" > > ### * LogisParameter-class > > flush(stderr()); flush(stdout()) > > ### Name: LogisParameter-class > ### Title: Class "LogisParameter" > ### Aliases: LogisParameter-class initialize,LogisParameter-method > > > ### ** Examples > > W=new("LogisParameter",location=0,scale=1) > scale(W) # scale of this distribution is 1. [1] 1 > scale(W)=2 # scale of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "Naturals-class" > > ### * Naturals-class > > flush(stderr()); flush(stdout()) > > ### Name: Naturals-class > ### Title: Class "Naturals" > ### Aliases: Naturals-class initialize,Naturals-method > ### Keywords: distribution > > ### ** Examples > > N=new("Naturals") > liesIn(N,1) # TRUE [1] TRUE > liesIn(N,c(0,1)) # FALSE [1] FALSE > liesIn(N,0.1) # FALSE [1] FALSE > > > > cleanEx(); ..nameEx <- "Nbinom-class" > > ### * Nbinom-class > > flush(stderr()); flush(stdout()) > > ### Name: Nbinom-class > ### Title: Class "Nbinom" > ### Aliases: Nbinom-class Nbinom initialize,Nbinom-method > ### Keywords: distribution > > ### ** Examples > > N=Nbinom(prob=0.5,size=1) # N is a binomial distribution with prob=0.5 and size=1. > r(N)(1) # one random number generated from this distribution, e.g. 3 [1] 1 > d(N)(1) # Density of this distribution is 0.25 for x=1. [1] 0.25 > p(N)(0.4) # Probability that x<0.4 is 0.5. [1] 0.5 > q(N)(.1) # x=0 is the smallest value x such that p(B)(x)>=0.1. [1] 0 > size(N) # size of this distribution is 1. [1] 1 > size(N)=2 # size of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "NbinomParameter-class" > > ### * NbinomParameter-class > > flush(stderr()); flush(stdout()) > > ### Name: NbinomParameter-class > ### Title: Class "NbinomParameter" > ### Aliases: NbinomParameter-class initialize,NbinomParameter-method > > > ### ** Examples > > W=new("NbinomParameter",prob=0.5,size=1) > size(W) # size of this distribution is 1. [1] 1 > size(W)=2 # size of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "Norm-class" > > ### * Norm-class > > flush(stderr()); flush(stdout()) > > ### Name: Norm-class > ### Title: Class "Norm" > ### Aliases: Norm-class Norm initialize,Norm-method > ### Keywords: distribution > > ### ** Examples > > N=Norm(mean=1,sd=1) # N is a normal distribution with mean=1 and sd=1. > r(N)(1) # one random number generated from this distribution, e.g. 2.257783 [1] 0.3735462 > d(N)(1) # Density of this distribution is 0.3989423 for x=1. [1] 0.3989423 > p(N)(1) # Probability that x<1 is 0.5. [1] 0.5 > q(N)(.1) # Probability that x<-0.2815516 is 0.1. [1] -0.2815516 > mean(N) # mean of this distribution is 1. [1] 1 > sd(N)=2 # sd of this distribution is now 2. > M=Norm() # M is a normal distribution with mean=0 and sd=1. > O=M+N # O is a normal distribution with mean=1 (=1+0) and sd=sqrt(5) (=sqrt(2^2+1^2)). > > > > cleanEx(); ..nameEx <- "NormParameter-class" > > ### * NormParameter-class > > flush(stderr()); flush(stdout()) > > ### Name: NormParameter-class > ### Title: Class "NormParameter" > ### Aliases: NormParameter-class initialize,NormParameter-method > > > ### ** Examples > > W <- new("NormParameter", mean = 0, sd = 1) > sd(W) # sd of this distribution is 1. [1] 1 > sd(W) <- 2 # sd of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "Pois-class" > > ### * Pois-class > > flush(stderr()); flush(stdout()) > > ### Name: Pois-class > ### Title: Class "Pois" > ### Aliases: Pois-class Pois initialize,Pois-method > ### Keywords: distribution > > ### ** Examples > > P <- Pois(lambda = 1) # P is a Poisson distribution with lambda = 1. > r(P)(1) # one random number generated from this distribution, e.g. 1 [1] 0 > d(P)(1) # Density of this distribution is 0.3678794 for x = 1. [1] 0.3678794 > p(P)(0.4) # Probability that x < 0.4 is 0.3678794. [1] 0.3678794 > q(P)(.1) # x = 0 is the smallest value x such that p(B)(x) >= 0.1. [1] 0 > lambda(P) # lambda of this distribution is 1. [1] 1 > lambda(P) <- 2 # lambda of this distribution is now 2. > R <- Pois(lambda = 3) # R is a Poisson distribution with lambda = 2. > S <- P + R # R is a Poisson distribution with lambda = 5(=2+3). > > > > cleanEx(); ..nameEx <- "PoisParameter-class" > > ### * PoisParameter-class > > flush(stderr()); flush(stdout()) > > ### Name: PoisParameter-class > ### Title: Class "PoisParameter" > ### Aliases: PoisParameter-class initialize,PoisParameter-method > > > ### ** Examples > > W <- new("PoisParameter",lambda = 1) > lambda(W) # lambda of this distribution is 1. [1] 1 > lambda(W) <- 2 # lambda of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "Reals-class" > > ### * Reals-class > > flush(stderr()); flush(stdout()) > > ### Name: Reals-class > ### Title: Class "Reals" > ### Aliases: Reals-class initialize,Reals-method > ### Keywords: distribution > > ### ** Examples > > R=new("Reals") > liesIn(R,c(0,0)) # FALSE [1] FALSE > > > > cleanEx(); ..nameEx <- "RtoDPQ" > > ### * RtoDPQ > > flush(stderr()); flush(stdout()) > > ### Name: RtoDPQ > ### Title: RtoDPQ > ### Aliases: RtoDPQ > > > ### ** Examples > > rn2 <- function(n){rnorm(n)^2} > x <- RtoDPQ(r = rn2, e = 4, n = 512) > # returns density, cumulative distribution and quantile function of > # squared standard normal distribution > x$dfun(4) [1] 0.02973328 > RtoDPQ(r = rn2, e = 5, n = 1024) # for a better result $dfun function (v) .C("R_approx", as.double(x), as.double(y), as.integer(n), xout = as.double(v), as.integer(length(v)), as.integer(method), as.double(yleft), as.double(yright), as.double(f), NAOK = TRUE, PACKAGE = "base")$xout $pfun function (x) pfun0(x) $qfun function (x) ifelse(x > 1, NA, ifelse(x < 0, NA, qfun(x))) > > rp2 <- function(n){rpois(n, lambda = 1)^2} > x <- RtoDPQ.d(r = rp2, e = 5) > # returns density, cumulative distribution and quantile function of > # squared Poisson distribution with parameter lambda=1 > > > > cleanEx(); ..nameEx <- "RtoDPQ.d" > > ### * RtoDPQ.d > > flush(stderr()); flush(stdout()) > > ### Name: RtoDPQ.d > ### Title: RtoDPQ.d > ### Aliases: RtoDPQ.d > > > ### ** Examples > > rn2 <- function(n){rnorm(n)^2} > x <- RtoDPQ(r = rn2, e = 4, n = 512) > # returns density, cumulative distribution and quantile function of > # squared standard normal distribution > > x$dfun(4) [1] 0.02973328 > RtoDPQ(r = rn2, e = 5, n = 1024) # for a better result $dfun function (v) .C("R_approx", as.double(x), as.double(y), as.integer(n), xout = as.double(v), as.integer(length(v)), as.integer(method), as.double(yleft), as.double(yright), as.double(f), NAOK = TRUE, PACKAGE = "base")$xout $pfun function (x) pfun0(x) $qfun function (x) ifelse(x > 1, NA, ifelse(x < 0, NA, qfun(x))) > > rp2 <- function(n){rpois(n, lambda = 1)^2} > x <- RtoDPQ.d(r = rp2, e = 5) > # returns density, cumulative distribution and quantile function of > # squared Poisson distribution with parameter lambda=1 > > > > cleanEx(); ..nameEx <- "Simulation-class" > > ### * Simulation-class > > flush(stderr()); flush(stdout()) > > ### Name: Simulation-class > ### Title: Class "Simulation" > ### Aliases: Simulation-class Simulation initialize,Simulation-method > > > ### ** Examples > > N=Norm() # N is a standard normal distribution. > S=Simulation(filename="xyz",runs=10,samplesize=3,seed=setRNG(),distribution=N) > Data(S) # no data yet NULL > simulate(S) > Data(S) # now there are random numbers [,1] [,2] [,3] [1,] -0.6264538 1.51178117 0.91897737 [2,] 0.1836433 0.38984324 0.78213630 [3,] -0.8356286 -0.62124058 0.07456498 [4,] 1.5952808 -2.21469989 -1.98935170 [5,] 0.3295078 1.12493092 0.61982575 [6,] -0.8204684 -0.04493361 -0.05612874 [7,] 0.4874291 -0.01619026 -0.15579551 [8,] 0.7383247 0.94383621 -1.47075238 [9,] 0.5757814 0.82122120 -0.47815006 [10,] -0.3053884 0.59390132 0.41794156 > Data(S) # the same data as before because the seed has not changed [,1] [,2] [,3] [1,] -0.6264538 1.51178117 0.91897737 [2,] 0.1836433 0.38984324 0.78213630 [3,] -0.8356286 -0.62124058 0.07456498 [4,] 1.5952808 -2.21469989 -1.98935170 [5,] 0.3295078 1.12493092 0.61982575 [6,] -0.8204684 -0.04493361 -0.05612874 [7,] 0.4874291 -0.01619026 -0.15579551 [8,] 0.7383247 0.94383621 -1.47075238 [9,] 0.5757814 0.82122120 -0.47815006 [10,] -0.3053884 0.59390132 0.41794156 > seed(S)=setRNG() > simulate(S) > Data(S) # different data [,1] [,2] [,3] [1,] 1.35867955 -0.1645236 0.3981059 [2,] -0.10278773 -0.2533617 -0.6120264 [3,] 0.38767161 0.6969634 0.3411197 [4,] -0.05380504 0.5566632 -1.1293631 [5,] -1.37705956 -0.6887557 1.4330237 [6,] -0.41499456 -0.7074952 1.9803999 [7,] -0.39428995 0.3645820 -0.3672215 [8,] -0.05931340 0.7685329 -1.0441346 [9,] 1.10002537 -0.1123462 0.5697196 [10,] 0.76317575 0.8811077 -0.1350546 > savedata(S) # saves the object in the directory of R... > load("xyz") # loads it again... > Data(S) # ...without the data - use simulate to return it! NULL > > > > cleanEx(); ..nameEx <- "TParameter-class" > > ### * TParameter-class > > flush(stderr()); flush(stdout()) > > ### Name: TParameter-class > ### Title: Class "TParameter" > ### Aliases: TParameter-class initialize,TParameter-method > > > ### ** Examples > > W=new("TParameter",df=1) > df(W) # df of this distribution is 1. [1] 1 > df(W)=2 # df of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "Td-class" > > ### * Td-class > > flush(stderr()); flush(stdout()) > > ### Name: Td-class > ### Title: Class "Td" > ### Aliases: Td-class Td initialize,Td-method > ### Keywords: distribution > > ### ** Examples > > T <- Td(df = 1) # T is a t distribution with df = 1. > r(T)(1) # one random number generated from this distribution, e.g. -0.09697573 [1] -0.5947235 > d(T)(1) # Density of this distribution is 0.1591549 for x = 1. [1] 0.1591549 > p(T)(1) # Probability that x < 1 is 0.75. [1] 0.75 > q(T)(.1) # Probability that x < -3.077684 is 0.1. [1] -3.077684 > df(T) # df of this distribution is 1. [1] 1 > df(T) <- 2 # df of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "UniNormParameter-class" > > ### * UniNormParameter-class > > flush(stderr()); flush(stdout()) > > ### Name: UniNormParameter-class > ### Title: Class "UniNormParameter" > ### Aliases: UniNormParameter-class initialize,UniNormParameter-method > > > ### ** Examples > > W <- new("UniNormParameter", mean = 0, sd = 1) > sd(W) # sd of this distribution is 1 [1] 1 > sd(W) <- 2 # sd of this distribution is now 2 > > > > cleanEx(); ..nameEx <- "Unif-class" > > ### * Unif-class > > flush(stderr()); flush(stdout()) > > ### Name: Unif-class > ### Title: Class "Unif" > ### Aliases: Unif-class Unif initialize,Unif-method > ### Keywords: distribution > > ### ** Examples > > U=Unif(Min=0,Max=2) # U is a uniform distribution with Min=0 and Max=2. > r(U)(1) # one random number generated from this distribution, e.g. 1.984357 [1] 0.5310173 > d(U)(1) # Density of this distribution is 0.5 for x=1. [1] 0.5 > p(U)(1) # Probability that x<1 is 0.5. [1] 0.5 > q(U)(.1) # Probability that x<0.2 is 0.1. [1] 0.2 > Min(U) # Min of this distribution is 0. [1] 0 > Min(U)=1 # Min of this distribution is now 1. > > > > cleanEx(); ..nameEx <- "UnifParameter-class" > > ### * UnifParameter-class > > flush(stderr()); flush(stdout()) > > ### Name: UnifParameter-class > ### Title: Class "UnifParameter" > ### Aliases: UnifParameter-class initialize,UnifParameter-method > > > ### ** Examples > > W=new("UnifParameter",Min=0,Max=1) > Max(W) # Max of this distribution is 1. [1] 1 > Max(W)=2 # Max of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "Weibull-class" > > ### * Weibull-class > > flush(stderr()); flush(stdout()) > > ### Name: Weibull-class > ### Title: Class "Weibull" > ### Aliases: Weibull-class Weibull initialize,Weibull-method > ### Keywords: distribution > > ### ** Examples > > W=Weibull(shape=1,scale=1) # W is a Weibull distribution with shape=1 and scale=1. > r(W)(1) # one random number generated from this distribution, e.g. 0.5204105 [1] 1.326108 > d(W)(1) # Density of this distribution is 0.3678794 for x=1. [1] 0.3678794 > p(W)(1) # Probability that x<1 is 0.6321206. [1] 0.6321206 > q(W)(.1) # Probability that x<0.1053605 is 0.1. [1] 0.1053605 > shape(W) # shape of this distribution is 1. [1] 1 > shape(W)=2 # shape of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "WeibullParameter-class" > > ### * WeibullParameter-class > > flush(stderr()); flush(stdout()) > > ### Name: WeibullParameter-class > ### Title: Class "WeibullParameter" > ### Aliases: WeibullParameter-class initialize,WeibullParameter-method > > > ### ** Examples > > W=new("WeibullParameter",shape=1,scale=1) > shape(W) # shape of this distribution is 1. [1] 1 > shape(W)=2 # shape of this distribution is now 2. > > > > cleanEx(); ..nameEx <- "cload" > > ### * cload > > flush(stderr()); flush(stdout()) > > ### Name: cload > ### Title: cload > ### Aliases: cload > > > ### ** Examples > > # see Dataclass and Evaluation for examples > ## The function is currently defined as > function(filename){ + eval.parent(parse(text=paste("load(\"",filename,".comment\")", sep = ""))) + } function (filename) { eval.parent(parse(text = paste("load(\"", filename, ".comment\")", sep = ""))) } > > > > cleanEx(); ..nameEx <- "distroptions" > > ### * distroptions > > flush(stderr()); flush(stdout()) > > ### Name: distroptions > ### Title: function to change the global variables of the package `distr' > ### Aliases: distroptions DefaultNrGridPoints DistrResolution TruncQuantile > ### DefaultNrFFTGridPointsExponent RtoDPQ.e > > > ### ** Examples > > distroptions("RtoDPQ.e") # returns the value of RtoDPQ.e, by default = 5 [1] 5 > distroptions("RtoDPQ.e",6) # now RtoDPQ.e = 6 > > ## The function is currently defined as > function (arg = "missing", value = -1) + { + globals <- list(DefaultNrFFTGridPointsExponent = DefaultNrFFTGridPointsExponent, + DefaultNrGridPoints = DefaultNrGridPoints, DistrResolution = DistrResolution, + RtoDPQ.e = RtoDPQ.e, TruncQuantile = TruncQuantile) + if (arg == "missing") { + print(globals) + return(invisible()) + } + if (!any(arg == names(globals))) + stop(paste("No such variable:", arg)) + if (value == -1) + switch(arg, DefaultNrGridPoints = DefaultNrGridPoints, + DistrResolution = DistrResolution, TruncQuantile = TruncQuantile, + DefaultNrFFTGridPointsExponent = DefaultNrFFTGridPointsExponent, + RtoDPQ.e = RtoDPQ.e) + else eval.parent(parse(text = paste("assignInNamespace(\"", + arg, "\",", value, ", \"distr\")", sep = ""))) + } function (arg = "missing", value = -1) { globals <- list(DefaultNrFFTGridPointsExponent = DefaultNrFFTGridPointsExponent, DefaultNrGridPoints = DefaultNrGridPoints, DistrResolution = DistrResolution, RtoDPQ.e = RtoDPQ.e, TruncQuantile = TruncQuantile) if (arg == "missing") { print(globals) return(invisible()) } if (!any(arg == names(globals))) stop(paste("No such variable:", arg)) if (value == -1) switch(arg, DefaultNrGridPoints = DefaultNrGridPoints, DistrResolution = DistrResolution, TruncQuantile = TruncQuantile, DefaultNrFFTGridPointsExponent = DefaultNrFFTGridPointsExponent, RtoDPQ.e = RtoDPQ.e) else eval.parent(parse(text = paste("assignInNamespace(\"", arg, "\",", value, ", \"distr\")", sep = ""))) } > > > > cleanEx(); ..nameEx <- "simplifyr-methods" > > ### * simplifyr-methods > > flush(stderr()); flush(stdout()) > > ### Name: simplifyr-methods > ### Title: Methods for Function simplifyr in Package `distr' > ### Aliases: simplifyr-methods simplifyr > ### simplifyr,UnivariateDistribution-method > > > ### ** Examples > > F <- ( Norm() + Binom() + Pois() + Exp() ) * 2 - 10 > system.time(r(F)(10^6)) [1] 2.03 0.17 2.20 0.00 0.00 > simplifyr(F, size = 10^6) > system.time(r(F)(10^6)) [1] 0.35 0.03 0.38 0.00 0.00 > > > cleanEx(); ..nameEx <- "standardMethods" > > ### * standardMethods > > flush(stderr()); flush(stdout()) > > ### Name: standardMethods > ### Title: standardMethods > ### Aliases: standardMethods > > > ### ** Examples > > setClass("testclass", representation(a = "numeric", b = "character")) [1] "testclass" > standardMethods("testclass") if(!isGeneric("a")) setGeneric("a", function(object) standardGeneric("a")) if(!isGeneric("b")) setGeneric("b", function(object) standardGeneric("b")) setMethod("a", "testclass", function(object) object@a) setMethod("b", "testclass", function(object) object@b) if(!isGeneric("a<-")) setGeneric("a<-", function(object, value) standardGeneric("a<-")) if(!isGeneric("b<-")) setGeneric("b<-", function(object, value) standardGeneric("b<-")) setReplaceMethod("a", "testclass", function(object, value){ object@a = value; object}) setReplaceMethod("b", "testclass", function(object, value){ object@b = value; object}) > #directory = "C:/Dokumente und Einstellungen/X/Eigene Dateien/Studium/R/SWP/" > #standardMethods("testclass", writetofile = TRUE, directory = directory) > > > > ### *