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("energy-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('energy') Loading required package: boot > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "edist" > > ### * edist > > flush(stderr()); flush(stdout()) > > ### Name: edist > ### Title: E-distance > ### Aliases: edist > ### Keywords: multivariate cluster nonparametric > > ### ** Examples > > ## compute e-distances for 3 samples of iris data > data(iris) > edist(iris[,1:4], c(50,50,50)) 1 2 2 123.55381 3 195.30396 38.85415 > > ## Don't show: > ## compute e-distances from a distance object > data(iris) > edist(dist(iris[,1:4]), c(50, 50, 50), distance=TRUE) 1 2 2 123.55381 3 195.30396 38.85415 > > ## compute e-distances from a distance matrix > data(iris) > d <- as.matrix(dist(iris[,1:4])) > edist(d, c(50, 50, 50), distance=TRUE) 1 2 2 123.55381 3 195.30396 38.85415 > > ## End Don't show > ## compute e-distances from vector of group labels > d <- dist(matrix(rnorm(100), nrow=50)) > g <- cutree(energy.hclust(d), k=4) > edist(d, sizes=table(g), ix=rank(g, ties.method="first")) 1 2 3 2 7.345510 3 7.484970 5.879414 4 5.488066 5.848766 4.614402 > > > > cleanEx(); ..nameEx <- "energy.hclust" > > ### * energy.hclust > > flush(stderr()); flush(stdout()) > > ### Name: energy.hclust > ### Title: Hierarchical Clustering by Minimum (Energy) E-distance > ### Aliases: energy.hclust > ### Keywords: multivariate cluster > > ### ** Examples > > ## Not run: > ##D > ##D library(cluster) > ##D data(animals) > ##D plot(energy.hclust(dist(animals))) > ##D > ## End(Not run) > > data(USArrests) > ecl <- energy.hclust(dist(USArrests)) > print(ecl) Call: energy.hclust(dst = dist(USArrests)) Cluster method : e-distance Distance : euclidean Number of objects: 50 > plot(ecl) > cutree(ecl, k=3) Alabama Alaska Arizona Arkansas California 1 1 1 2 1 Colorado Connecticut Delaware Florida Georgia 2 3 1 1 2 Hawaii Idaho Illinois Indiana Iowa 3 3 1 3 3 Kansas Kentucky Louisiana Maine Maryland 3 3 1 3 1 Massachusetts Michigan Minnesota Mississippi Missouri 2 1 3 1 2 Montana Nebraska Nevada New Hampshire New Jersey 3 3 1 3 2 New Mexico New York North Carolina North Dakota Ohio 1 1 1 3 3 Oklahoma Oregon Pennsylvania Rhode Island South Carolina 2 2 3 2 1 South Dakota Tennessee Texas Utah Vermont 3 2 2 3 3 Virginia Washington West Virginia Wisconsin Wyoming 2 2 3 3 2 > cutree(ecl, h=150) Alabama Alaska Arizona Arkansas California 1 2 3 4 3 Colorado Connecticut Delaware Florida Georgia 4 5 1 6 4 Hawaii Idaho Illinois Indiana Iowa 7 5 1 5 7 Kansas Kentucky Louisiana Maine Maryland 5 5 1 8 3 Massachusetts Michigan Minnesota Mississippi Missouri 9 1 7 2 4 Montana Nebraska Nevada New Hampshire New Jersey 5 5 1 7 9 New Mexico New York North Carolina North Dakota Ohio 3 1 6 7 5 Oklahoma Oregon Pennsylvania Rhode Island South Carolina 9 9 5 9 2 South Dakota Tennessee Texas Utah Vermont 8 4 4 5 7 Virginia Washington West Virginia Wisconsin Wyoming 9 9 8 7 9 > > ## compare performance of e-clustering, Ward's method, group average method > ## when sampled populations have equal means: n=200, d=5, two groups > z <- rbind(matrix(rnorm(1000), nrow=200), matrix(rnorm(1000, 0, 5), nrow=200)) > g <- c(rep(1, 200), rep(2, 200)) > d <- dist(z) > e <- energy.hclust(d) > a <- hclust(d, method="average") > w <- hclust(d^2, method="ward") > list("E" = table(cutree(e, k=2) == g), "Ward" = table(cutree(w, k=2) == g), + "Avg" = table(cutree(a, k=2) == g)) $E FALSE TRUE 12 388 $Ward FALSE TRUE 143 257 $Avg FALSE TRUE 199 201 > > > > cleanEx(); ..nameEx <- "eqdist.etest" > > ### * eqdist.etest > > flush(stderr()); flush(stdout()) > > ### Name: eqdist.etest > ### Title: Multisample E-statistic (Energy) Test of Equal Distributions > ### Aliases: eqdist.etest > ### Keywords: multivariate htest nonparametric > > ### ** Examples > > data(iris) > > ## test if the 3 varieties of iris data (d=4) have equal distributions > eqdist.etest(iris[,1:4], c(50,50,50)) Multivariate 3-sample E-test of equal distributions Sample sizes: 50 50 50 Test statistic: 357.7 Approx. p-value: < 2.22e-16 999 replicates, resampling method = permutation > > ## compare incomplete versions of two sample test > x <- c(rpois(400, 2), rnbinom(600, size=1, mu=2)) > eqdist.etest(x, c(400, 600), incomplete=TRUE, N=100) Univariate 2-sample E-test of equal distributions, incomplete version with max size 100 Sample sizes: 400 600 Test statistic: 8.83 Approx. p-value: 0.003003 999 replicates, resampling method = permutation > eqdist.etest(x, c(400, 600), incomplete=TRUE, N=200) Univariate 2-sample E-test of equal distributions, incomplete version with max size 200 Sample sizes: 400 600 Test statistic: 14.66 Approx. p-value: < 2.22e-16 999 replicates, resampling method = permutation > > ## Don't show: > x <- matrix(rnorm(500), nrow=100) > y <- matrix(rnorm(500, mean=5), nrow=100) > x <- rbind(x, y) > eqdist.etest(dist(x), sizes=c(100, 100), distance=TRUE) 2-sample E-test of equal distributions Sample sizes: 100 100 Test statistic: 861 Approx. p-value: < 2.22e-16 999 replicates, resampling method = permutation > eqdist.etest(x, sizes=c(100, 100), incomplete=TRUE, N=50, R=100) Multivariate 2-sample E-test of equal distributions, incomplete version with max size 50 Sample sizes: 100 100 Test statistic: 431.5 Approx. p-value: < 2.22e-16 100 replicates, resampling method = permutation > ## End Don't show > > > > cleanEx(); ..nameEx <- "ksample.e" > > ### * ksample.e > > flush(stderr()); flush(stdout()) > > ### Name: ksample.e > ### Title: E-statistic (Energy Statistic) for Multivariate k-sample Test of > ### Equal Distributions > ### Aliases: ksample.e > ### Keywords: multivariate htest nonparametric > > ### ** Examples > > ## compute 3-sample E-statistic for 4-dimensional iris data > data(iris) > ksample.e(iris[,1:4], c(50,50,50)) [1] 357.7119 > > ## compute a 3-sample univariate E-statistic > ksample.e(rnorm(150), c(25,75,50)) [1] 5.677216 > > > > cleanEx(); ..nameEx <- "mvnorm.e" > > ### * mvnorm.e > > flush(stderr()); flush(stdout()) > > ### Name: mvnorm.e > ### Title: E-statistic (Energy Statistic) for Testing Multivariate > ### Normality > ### Aliases: mvnorm.e > ### Keywords: multivariate htest > > ### ** Examples > > > ## compute multivariate normality test statistic for iris Setosa data > data(iris) > mvnorm.e(iris[1:50, 1:4]) [1] 1.203397 > > > > cleanEx(); ..nameEx <- "mvnorm.etest" > > ### * mvnorm.etest > > flush(stderr()); flush(stdout()) > > ### Name: mvnorm.etest > ### Title: E-statistic (Energy) Test of Multivariate Normality > ### Aliases: mvnorm.etest > ### Keywords: multivariate htest > > ### ** Examples > > ## test if the iris Setosa data has multivariate normal distribution > data(iris) > mvnorm.etest(iris[1:50,1:4]) E-test of multivariate normality Sample size: 50 Dimension: 4 Test statistic: 1.203 Approx. p-value: 0.041041 999 replicates > > ## test a univariate sample for normality > x <- runif(50, 0, 10) > mvnorm.etest(x) E-test of multivariate normality Sample size: 50 Dimension: 1 Test statistic: 1.524 Approx. p-value: < 2.22e-16 999 replicates > > > > cleanEx(); ..nameEx <- "normal.e" > > ### * normal.e > > flush(stderr()); flush(stdout()) > > ### Name: normal.e > ### Title: E-statistic (Energy Statistic) for Testing Univariate Normality > ### Aliases: normal.e > ### Keywords: htest > > ### ** Examples > > x <- rnorm(30) > normal.e(x) [1] 0.5225757 > > > > cleanEx(); ..nameEx <- "poisson.m" > > ### * poisson.m > > flush(stderr()); flush(stdout()) > > ### Name: poisson.m > ### Title: Mean Distance Statistic for Testing Poisson Distribution > ### Aliases: poisson.m > ### Keywords: htest > > ### ** Examples > > x <- rpois(20, 1) > poisson.m(x) [1] 0.02680415 > > > > cleanEx(); ..nameEx <- "poisson.mtest" > > ### * poisson.mtest > > flush(stderr()); flush(stdout()) > > ### Name: poisson.mtest > ### Title: Mean Distance Test for Poisson Distribution > ### Aliases: poisson.mtest > ### Keywords: htest > > ### ** Examples > > x <- rpois(20, 1) > poisson.mtest(x) Mean distance test of Poisson distribution Sample size: 20 Sample mean: 1.2 Test statistic: 0.02680 Approx. p-value: 0.57157 999 replicates > > > > cleanEx(); ..nameEx <- "print.etest.eqdist" > > ### * print.etest.eqdist > > flush(stderr()); flush(stdout()) > > ### Name: print.etest.eqdist > ### Title: Print Multisample E-test (Energy Test) for Equal Distributions > ### Aliases: print.etest.eqdist > ### Keywords: print > > ### ** Examples > > ## print test if the 3 varieties of iris data (d=4) have equal distributions > data(iris) > e <- eqdist.etest(iris[,1:4], c(50,50,50)) > print.etest.eqdist(e) Multivariate 3-sample E-test of equal distributions Sample sizes: 50 50 50 Test statistic: 357.7 Approx. p-value: < 2.22e-16 999 replicates, resampling method = permutation > > > > cleanEx(); ..nameEx <- "print.etest.mvnorm" > > ### * print.etest.mvnorm > > flush(stderr()); flush(stdout()) > > ### Name: print.etest.mvnorm > ### Title: Print E-test (Energy Test) of Multivariate Normality > ### Aliases: print.etest.mvnorm > ### Keywords: print > > ### ** Examples > > ## print E-test for 5-dimensional data > x <- matrix(rnorm(100), nrow=20, ncol=5) > e <- mvnorm.etest(x) > print.etest.mvnorm(e) E-test of multivariate normality Sample size: 20 Dimension: 5 Test statistic: 1.138 Approx. p-value: 0.25726 999 replicates > > > > cleanEx(); ..nameEx <- "print.etest.poisson" > > ### * print.etest.poisson > > flush(stderr()); flush(stdout()) > > ### Name: print.etest.poisson > ### Title: Print Mean Distance Test for Poisson Distribution > ### Aliases: print.etest.poisson > ### Keywords: print > > ### ** Examples > > x <- rpois(20, 1) > e <- poisson.mtest(x) > print.etest.poisson(e) Mean distance test of Poisson distribution Sample size: 20 Sample mean: 1.2 Test statistic: 0.02680 Approx. p-value: 0.57157 999 replicates > > > > ### *