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("nor1mix-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('nor1mix') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "MarronWand" > > ### * MarronWand > > flush(stderr()); flush(stdout()) > > ### Name: MarronWand > ### Title: Marron-Wand Densities as `norMix' Objects > ### Aliases: MarronWand MW.nm1 MW.nm2 MW.nm3 MW.nm4 MW.nm5 MW.nm6 MW.nm7 > ### MW.nm8 MW.nm9 MW.nm10 MW.nm11 MW.nm12 MW.nm13 MW.nm14 MW.nm15 MW.nm16 > ### Keywords: datasets distribution > > ### ** Examples > > MW.nm10 'Normal Mixture' object ``#10 Claw'' mu sig2 w [1,] 0.0 1.00 0.5 [2,] -1.0 0.01 0.1 [3,] -0.5 0.01 0.1 [4,] 0.0 0.01 0.1 [5,] 0.5 0.01 0.1 [6,] 1.0 0.01 0.1 > plot(MW.nm14) > > ## These are defined as norMix() calls in ../R/zMarrWand-dens.R > ppos <- which("package:nor1mix" == search()) > nms <- ls(pat="^MW.nm", pos = ppos) > nms <- nms[order(as.numeric(substring(nms,6)))] > for(n in nms) { + cat("\n",n,":\n"); print(get(n, pos = ppos)) + } MW.nm1 : 'Normal Mixture' object ``#1 Gaussian'' mu sig2 w [1,] 0 1 1 MW.nm2 : 'Normal Mixture' object ``#2 Skewed'' mu sig2 w [1,] -0.3 1.4400000 0.2 [2,] 0.3 0.6400000 0.2 [3,] 1.0 0.4444444 0.6 MW.nm3 : 'Normal Mixture' object ``#3 Str Skew'' mu sig2 w [1,] 0.000000 1.000000000 0.125 [2,] -1.000000 0.444444444 0.125 [3,] -1.666667 0.197530864 0.125 [4,] -2.111111 0.087791495 0.125 [5,] -2.407407 0.039018442 0.125 [6,] -2.604938 0.017341530 0.125 [7,] -2.736626 0.007707347 0.125 [8,] -2.824417 0.003425487 0.125 MW.nm4 : 'Normal Mixture' object ``#4 Kurtotic'' mu sig2 w [1,] 0 1.00 0.6666667 [2,] 0 0.01 0.3333333 MW.nm5 : 'Normal Mixture' object ``#5 Outlier'' mu sig2 w [1,] 0 1.00 0.1 [2,] 0 0.01 0.9 MW.nm6 : 'Normal Mixture' object ``#6 Bimodal'' mu sig2 w [1,] -1 0.4444444 0.5 [2,] 1 0.4444444 0.5 MW.nm7 : 'Normal Mixture' object ``#7 Separated'' mu sig2 w [1,] -1.5 0.25 0.5 [2,] 1.5 0.25 0.5 MW.nm8 : 'Normal Mixture' object ``#8 Asym Bim'' mu sig2 w [1,] 0.0 1.0000000 0.75 [2,] 1.5 0.1111111 0.25 MW.nm9 : 'Normal Mixture' object ``#9 Trimodal'' mu sig2 w [1,] -1.2 0.3600 0.45 [2,] 1.2 0.3600 0.45 [3,] 0.0 0.0625 0.10 MW.nm10 : 'Normal Mixture' object ``#10 Claw'' mu sig2 w [1,] 0.0 1.00 0.5 [2,] -1.0 0.01 0.1 [3,] -0.5 0.01 0.1 [4,] 0.0 0.01 0.1 [5,] 0.5 0.01 0.1 [6,] 1.0 0.01 0.1 MW.nm11 : 'Normal Mixture' object ``#11 Doub Claw'' mu sig2 w [1,] -1.0 0.4444444 0.490000000 [2,] 1.0 0.4444444 0.490000000 [3,] -1.5 0.0001000 0.002857143 [4,] -1.0 0.0001000 0.002857143 [5,] -0.5 0.0001000 0.002857143 [6,] 0.0 0.0001000 0.002857143 [7,] 0.5 0.0001000 0.002857143 [8,] 1.0 0.0001000 0.002857143 [9,] 1.5 0.0001000 0.002857143 MW.nm12 : 'Normal Mixture' object ``#12 Asym Claw'' mu sig2 w [1,] 0.0 1.000000 0.50000000 [2,] -1.5 0.160000 0.25806452 [3,] -0.5 0.040000 0.12903226 [4,] 0.5 0.010000 0.06451613 [5,] 1.5 0.002500 0.03225806 [6,] 2.5 0.000625 0.01612903 MW.nm13 : 'Normal Mixture' object ``#13 As Do Claw'' mu sig2 w [1,] -1.0 0.4444444 0.460000000 [2,] 1.0 0.4444444 0.460000000 [3,] -1.5 0.0001000 0.003333333 [4,] -1.0 0.0001000 0.003333333 [5,] -0.5 0.0001000 0.003333333 [6,] 0.5 0.0049000 0.023333333 [7,] 1.0 0.0049000 0.023333333 [8,] 1.5 0.0049000 0.023333333 MW.nm14 : 'Normal Mixture' object ``#14 Smoo Comb'' mu sig2 w [1,] -1.4761905 0.2579994961 0.50793651 [2,] 0.8095238 0.0644998740 0.25396825 [3,] 1.9523810 0.0161249685 0.12698413 [4,] 2.5238095 0.0040312421 0.06349206 [5,] 2.8095238 0.0010078105 0.03174603 [6,] 2.9523810 0.0002519526 0.01587302 MW.nm15 : 'Normal Mixture' object ``#15 Disc Comb'' mu sig2 w [1,] -2.1428571 0.081632653 0.28571429 [2,] -0.4285714 0.081632653 0.28571429 [3,] 1.2857143 0.081632653 0.28571429 [4,] 2.2857143 0.002267574 0.04761905 [5,] 2.5714286 0.002267574 0.04761905 [6,] 2.8571429 0.002267574 0.04761905 MW.nm16 : 'Normal Mixture' object ``#16 Dist Bim'' mu sig2 w [1,] -2.5 0.02777778 0.5 [2,] 2.5 0.02777778 0.5 > > ## Plot all of them: > op <- par(mfrow=c(4,4), mgp = c(1.2, 0.5, 0), tcl = -0.2, + mar = .1 + c(2,2,2,1), oma = c(0,0,3,0)) > for(n in nms) { plot(get(n, pos = ppos))} > mtext("The Marron-Wand Densities", outer= TRUE, font= 2, cex= 1.6) > > ## and their Q-Q-plots (not really fast): > prob <- ppoints(N <- 100) > for(n in nms) { + D <- get(n, pos = ppos) + qqnorm(qnorMix(D, prob), main = n) + } > mtext("QQ-plots of Marron-Wand Densities", outer = TRUE, + font = 2, cex = 1.6) > > par(op) > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "dnorMix" > > ### * dnorMix > > flush(stderr()); flush(stdout()) > > ### Name: dnorMix > ### Title: Normal Mixture Density > ### Aliases: dnorMix > ### Keywords: distribution > > ### ** Examples > > ff <- dnorMix(MW.nm7) > str(ff) List of 2 $ x: num [1:511] -4.74 -4.72 -4.71 -4.69 -4.67 ... $ y: num [1:511] 2.91e-10 3.70e-10 4.70e-10 5.96e-10 7.55e-10 ... > plot(ff, type = "h") # rather use plot(ff, ...) > > > > cleanEx(); ..nameEx <- "norMix" > > ### * norMix > > flush(stderr()); flush(stdout()) > > ### Name: norMix > ### Title: Mixtures of Univariate Normal Distributions > ### Aliases: norMix is.norMix m.norMix mean.norMix var.norMix print.norMix > ### Keywords: distribution > > ### ** Examples > > ex <- norMix(mu = c(1,2,5))# s^2 = 1, equal proportions > ex 'Normal Mixture' object ``NM3.125_111'' mu sig2 w [1,] 1 1 0.3333333 [2,] 2 1 0.3333333 [3,] 5 1 0.3333333 > plot(ex)# looks like a mixture of only 2 > > plot(ex, log = "y")# maybe "revealing" > > > > cleanEx(); ..nameEx <- "plot.norMix" > > ### * plot.norMix > > flush(stderr()); flush(stdout()) > > ### Name: plot.norMix > ### Title: Plotting Methods for `norMix' Objects > ### Aliases: plot.norMix lines.norMix > ### Keywords: distribution hplot > > ### ** Examples > > plot(norMix(m=c(0,3),s=c(4,1))) > ## Further examples in ?norMix and ?rnorMix > > > > cleanEx(); ..nameEx <- "pnorMix" > > ### * pnorMix > > flush(stderr()); flush(stdout()) > > ### Encoding: latin1 > > ### Name: pnorMix > ### Title: Normal Mixture Cumulative Distribution and Quantiles > ### Aliases: pnorMix qnorMix > ### Keywords: distribution > > ### ** Examples > > MW.nm3 # the "strange skew" one 'Normal Mixture' object ``#3 Str Skew'' mu sig2 w [1,] 0.000000 1.000000000 0.125 [2,] -1.000000 0.444444444 0.125 [3,] -1.666667 0.197530864 0.125 [4,] -2.111111 0.087791495 0.125 [5,] -2.407407 0.039018442 0.125 [6,] -2.604938 0.017341530 0.125 [7,] -2.736626 0.007707347 0.125 [8,] -2.824417 0.003425487 0.125 > plot(MW.nm3) > ## now the cumlative : > x <- seq(-4,4, length=1001) > plot(x, pnorMix(MW.nm3, x), type="l", col=2) > ## and some of its inverse : > pp <- seq(.1, .9, by=.1) > plot(qnorMix(MW.nm3, pp), pp) > > ## The "true" median of a normal mixture: > median.norMix <- function(x) qnorMix(x, 1/2) > median.norMix(MW.nm3) ## -2.32 [1] -2.320251 > > > > cleanEx(); ..nameEx <- "r.norMix" > > ### * r.norMix > > flush(stderr()); flush(stdout()) > > ### Name: r.norMix > ### Title: Ratio of Normal Mixture to Corresponding Normal > ### Aliases: r.norMix > ### Keywords: distribution > > ### ** Examples > > d3 <- norMix(m = 5*(0:2), w = c(0.6, 0.3, 0.1)) > plot(d3) > rd3 <- r.norMix(d3) > str(rd3) List of 3 $ x : num [1:511] -8.00 -7.96 -7.92 -7.88 -7.84 ... $ y : num [1:511] 2.39e-12 3.21e-12 4.30e-12 5.74e-12 7.67e-12 ... $ f0: num [1:511] 0.00127 0.00131 0.00136 0.00141 0.00146 ... > stopifnot(rd3 $ y == r.norMix(d3, xy.ret = FALSE)) > par(new = TRUE) > plot(rd3, type = "l", col = 3, axes = FALSE, xlab = "", ylab="") > axis(4, col.axis=3) > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "rnorMix" > > ### * rnorMix > > flush(stderr()); flush(stdout()) > > ### Name: rnorMix > ### Title: Generate ``Normal Mixture'' Distributed Random Numbers > ### Aliases: rnorMix > ### Keywords: distribution > > ### ** Examples > > x <- rnorMix(5000, MW.nm10) > hist(x)# you don't see the claw > plot(density(x), ylim = c(0,0.6), + main = "Estim. and true 'MW.nm10' density") > lines(MW.nm10, col = "orange") > > > > ### *