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("outliers-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('outliers') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "chisq.out.test" > > ### * chisq.out.test > > flush(stderr()); flush(stdout()) > > ### Name: chisq.out.test > ### Title: Chi-squared test for outlier > ### Aliases: chisq.out.test > ### Keywords: htest > > ### ** Examples > > > set.seed(1234) > x = rnorm(10) > chisq.out.test(x) chi-squared test for outlier data: x X-squared = 3.8842, p-value = 0.04874 alternative hypothesis: lowest value -2.34569770262935 is an outlier > chisq.out.test(x,opposite=TRUE) chi-squared test for outlier data: x X-squared = 2.1721, p-value = 0.1405 alternative hypothesis: highest value 1.08444117668306 is an outlier > > > > > cleanEx(); ..nameEx <- "cochran.test" > > ### * cochran.test > > flush(stderr()); flush(stdout()) > > ### Name: cochran.test > ### Title: Test for outlying or inlying variance > ### Aliases: cochran.test > ### Keywords: htest > > ### ** Examples > > set.seed(1234) > x=rnorm(100) > d=data.frame(x=x,group=rep(1:10,10)) > cochran.test(x~group,d) Cochran test for outlying variance data: x ~ group C = 0.1619, df = 10, k = 10, p-value = 0.841 alternative hypothesis: Group 10 has outlying variance sample estimates: 1 2 3 4 5 6 7 8 0.9702567 1.0762180 0.9489474 0.9098832 1.1665495 0.9753678 1.2960769 0.8036918 9 10 0.7193931 1.7127172 > cochran.test(x~group,d,inlying=TRUE) Cochran test for inlying variance data: x ~ group C = 0.068, df = 10, k = 10, p-value < 2.2e-16 alternative hypothesis: Group 9 has inlying variance sample estimates: 1 2 3 4 5 6 7 8 0.9702567 1.0762180 0.9489474 0.9098832 1.1665495 0.9753678 1.2960769 0.8036918 9 10 0.7193931 1.7127172 > x=runif(5) > cochran.test(x,rep(5,5)) Cochran test for outlying variance data: x C = 0.2742, df = 5, k = 5, p-value = 1 alternative hypothesis: Group 4 has outlying variance sample estimates: 1 2 3 4 5 0.6607546 0.5283594 0.3174938 0.7678555 0.5263085 > cochran.test(x,rep(100,5)) Cochran test for outlying variance data: x C = 0.2742, df = 100, k = 5, p-value = 0.01519 alternative hypothesis: Group 4 has outlying variance sample estimates: 1 2 3 4 5 0.6607546 0.5283594 0.3174938 0.7678555 0.5263085 > > > > cleanEx(); ..nameEx <- "dixon.test" > > ### * dixon.test > > flush(stderr()); flush(stdout()) > > ### Name: dixon.test > ### Title: Dixon tests for outlier > ### Aliases: dixon.test > ### Keywords: htest > > ### ** Examples > > > set.seed(1234) > x = rnorm(10) > dixon.test(x) Dixon test for outliers data: x Q = 0.3993, p-value = 0.2187 alternative hypothesis: lowest value -2.34569770262935 is an outlier > dixon.test(x,opposite=TRUE) Dixon test for outliers data: x Q = 0.2524, p-value = 0.6484 alternative hypothesis: highest value 1.08444117668306 is an outlier > dixon.test(x,type=10) Dixon test for outliers data: x Q = 0.3319, p-value = 0.237 alternative hypothesis: lowest value -2.34569770262935 is an outlier > > > > > cleanEx(); ..nameEx <- "grubbs.test" > > ### * grubbs.test > > flush(stderr()); flush(stdout()) > > ### Name: grubbs.test > ### Title: Grubbs tests for one or two outliers in data sample > ### Aliases: grubbs.test > ### Keywords: htest > > ### ** Examples > > > set.seed(1234) > x = rnorm(10) > grubbs.test(x) Grubbs test for one outlier data: x G = 1.9708, U = 0.5205, p-value = 0.1323 alternative hypothesis: lowest value -2.34569770262935 is an outlier > grubbs.test(x,type=20) Grubbs test for two outliers data: x U = 0.3836, p-value = 0.2459 alternative hypothesis: lowest values -2.34569770262935 , -1.20706574938542 are outliers > grubbs.test(x,type=11) Grubbs test for two opposite outliers data: x G = 3.4446, U = 0.3236, p-value = 0.1950 alternative hypothesis: -2.34569770262935 and 1.08444117668306 are outliers > > > > > cleanEx(); ..nameEx <- "outlier" > > ### * outlier > > flush(stderr()); flush(stdout()) > > ### Name: outlier > ### Title: Find value with largest difference from the mean > ### Aliases: outlier > ### Keywords: htest > > ### ** Examples > > set.seed(1234) > y=rnorm(100) > outlier(y) [1] 2.548991 > outlier(y,opposite=TRUE) [1] -2.345698 > dim(y) <- c(20,5) > outlier(y) [1] 2.415835 1.102298 1.647817 -1.390701 2.121117 > outlier(y,opposite=TRUE) [1] -2.345698 -2.180040 -1.806031 2.548991 -1.372302 > > > > cleanEx(); ..nameEx <- "qcochran" > > ### * qcochran > > flush(stderr()); flush(stdout()) > > ### Name: qcochran > ### Title: Critical values and p-values for Cochran outlying variance test > ### Aliases: qcochran pcochran > ### Keywords: distribution > > ### ** Examples > > qcochran(0.05,5,5) [1] 0.2934398 > pcochran(0.293,5,5) [1] 0.04564117 > > > > cleanEx(); ..nameEx <- "rm.outlier" > > ### * rm.outlier > > flush(stderr()); flush(stdout()) > > ### Name: rm.outlier > ### Title: Remove the value(s) most differing from the mean > ### Aliases: rm.outlier > ### Keywords: htest > > ### ** Examples > > set.seed(1234) > y=rnorm(100) > outlier(y) [1] 2.548991 > outlier(y,opposite=TRUE) [1] -2.345698 > rm.outlier(y) [1] -1.207065749 0.277429242 1.084441177 -2.345697703 0.429124689 [6] 0.506055892 -0.574739960 -0.546631856 -0.564451999 -0.890037829 [11] -0.477192700 -0.998386445 -0.776253895 0.064458817 0.959494059 [16] -0.110285494 -0.511009506 -0.911195417 -0.837171680 2.415835178 [21] 0.134088220 -0.490685897 -0.440547872 0.459589441 -0.693720247 [26] -1.448204910 0.574755721 -1.023655723 -0.015138300 -0.935948601 [31] 1.102297546 -0.475593079 -0.709440038 -0.501258061 -1.629093469 [36] -1.167619262 -2.180039649 -1.340993192 -0.294293859 -0.465897540 [41] 1.449496265 -1.068642724 -0.855364634 -0.280623002 -0.994340076 [46] -0.968514318 -1.107318193 -1.251985886 -0.523828119 -0.496849957 [51] -1.806031257 -0.582075925 -1.108889624 -1.014962009 -0.162309524 [56] 0.563055819 1.647817473 -0.773353424 1.605909629 -1.157808548 [61] 0.656588464 -0.034760390 -0.669633580 -0.007604756 1.777084448 [66] -1.138607737 1.367827179 1.329564791 0.336472797 0.006892838 [71] -0.455468738 -0.366523933 0.648286568 2.070270861 -0.153398412 [76] -1.390700947 -0.723581777 0.258261762 -0.317059115 -0.177789958 [81] -0.169994077 -1.372301886 -0.173787170 0.850232257 0.697608712 [86] 0.549997351 -0.402731975 -0.191593770 -1.194527880 -0.053158819 [91] 0.255196001 1.705964007 1.001513252 -0.495583443 0.355550297 [96] -1.134608044 0.878203627 0.972916753 2.121117105 > rm.outlier(y,opposite=TRUE) [1] -1.207065749 0.277429242 1.084441177 0.429124689 0.506055892 [6] -0.574739960 -0.546631856 -0.564451999 -0.890037829 -0.477192700 [11] -0.998386445 -0.776253895 0.064458817 0.959494059 -0.110285494 [16] -0.511009506 -0.911195417 -0.837171680 2.415835178 0.134088220 [21] -0.490685897 -0.440547872 0.459589441 -0.693720247 -1.448204910 [26] 0.574755721 -1.023655723 -0.015138300 -0.935948601 1.102297546 [31] -0.475593079 -0.709440038 -0.501258061 -1.629093469 -1.167619262 [36] -2.180039649 -1.340993192 -0.294293859 -0.465897540 1.449496265 [41] -1.068642724 -0.855364634 -0.280623002 -0.994340076 -0.968514318 [46] -1.107318193 -1.251985886 -0.523828119 -0.496849957 -1.806031257 [51] -0.582075925 -1.108889624 -1.014962009 -0.162309524 0.563055819 [56] 1.647817473 -0.773353424 1.605909629 -1.157808548 0.656588464 [61] 2.548991071 -0.034760390 -0.669633580 -0.007604756 1.777084448 [66] -1.138607737 1.367827179 1.329564791 0.336472797 0.006892838 [71] -0.455468738 -0.366523933 0.648286568 2.070270861 -0.153398412 [76] -1.390700947 -0.723581777 0.258261762 -0.317059115 -0.177789958 [81] -0.169994077 -1.372301886 -0.173787170 0.850232257 0.697608712 [86] 0.549997351 -0.402731975 -0.191593770 -1.194527880 -0.053158819 [91] 0.255196001 1.705964007 1.001513252 -0.495583443 0.355550297 [96] -1.134608044 0.878203627 0.972916753 2.121117105 > dim(y) <- c(20,5) > outlier(y) [1] 2.415835 1.102298 1.647817 -1.390701 2.121117 > outlier(y,logical=TRUE) [,1] [,2] [,3] [,4] [,5] [1,] FALSE FALSE FALSE FALSE FALSE [2,] FALSE FALSE FALSE FALSE FALSE [3,] FALSE FALSE FALSE FALSE FALSE [4,] FALSE FALSE FALSE FALSE FALSE [5,] FALSE FALSE FALSE FALSE FALSE [6,] FALSE FALSE FALSE FALSE FALSE [7,] FALSE FALSE FALSE FALSE FALSE [8,] FALSE FALSE FALSE FALSE FALSE [9,] FALSE FALSE FALSE FALSE FALSE [10,] FALSE FALSE FALSE FALSE FALSE [11,] FALSE TRUE FALSE FALSE FALSE [12,] FALSE FALSE FALSE FALSE FALSE [13,] FALSE FALSE FALSE FALSE FALSE [14,] FALSE FALSE FALSE FALSE FALSE [15,] FALSE FALSE FALSE FALSE FALSE [16,] FALSE FALSE FALSE FALSE FALSE [17,] FALSE FALSE TRUE TRUE FALSE [18,] FALSE FALSE FALSE FALSE FALSE [19,] FALSE FALSE FALSE FALSE FALSE [20,] TRUE FALSE FALSE FALSE TRUE > outlier(y,logical=TRUE,opposite=TRUE) [,1] [,2] [,3] [,4] [,5] [1,] FALSE FALSE FALSE FALSE FALSE [2,] FALSE FALSE FALSE TRUE FALSE [3,] FALSE FALSE FALSE FALSE TRUE [4,] TRUE FALSE FALSE FALSE FALSE [5,] FALSE FALSE FALSE FALSE FALSE [6,] FALSE FALSE FALSE FALSE FALSE [7,] FALSE FALSE FALSE FALSE FALSE [8,] FALSE FALSE FALSE FALSE FALSE [9,] FALSE FALSE FALSE FALSE FALSE [10,] FALSE FALSE FALSE FALSE FALSE [11,] FALSE FALSE TRUE FALSE FALSE [12,] FALSE FALSE FALSE FALSE FALSE [13,] FALSE FALSE FALSE FALSE FALSE [14,] FALSE FALSE FALSE FALSE FALSE [15,] FALSE FALSE FALSE FALSE FALSE [16,] FALSE FALSE FALSE FALSE FALSE [17,] FALSE TRUE FALSE FALSE FALSE [18,] FALSE FALSE FALSE FALSE FALSE [19,] FALSE FALSE FALSE FALSE FALSE [20,] FALSE FALSE FALSE FALSE FALSE > rm.outlier(y) [,1] [,2] [,3] [,4] [,5] [1,] -1.20706575 0.1340882 1.4494963 0.656588464 -0.17778996 [2,] 0.27742924 -0.4906859 -1.0686427 2.548991071 -0.16999408 [3,] 1.08444118 -0.4405479 -0.8553646 -0.034760390 -1.37230189 [4,] -2.34569770 0.4595894 -0.2806230 -0.669633580 -0.17378717 [5,] 0.42912469 -0.6937202 -0.9943401 -0.007604756 0.85023226 [6,] 0.50605589 -1.4482049 -0.9685143 1.777084448 0.69760871 [7,] -0.57473996 0.5747557 -1.1073182 -1.138607737 0.54999735 [8,] -0.54663186 -1.0236557 -1.2519859 1.367827179 -0.40273198 [9,] -0.56445200 -0.0151383 -0.5238281 1.329564791 -0.19159377 [10,] -0.89003783 -0.9359486 -0.4968500 0.336472797 -1.19452788 [11,] -0.47719270 -0.4755931 -1.8060313 0.006892838 -0.05315882 [12,] -0.99838644 -0.7094400 -0.5820759 -0.455468738 0.25519600 [13,] -0.77625389 -0.5012581 -1.1088896 -0.366523933 1.70596401 [14,] 0.06445882 -1.6290935 -1.0149620 0.648286568 1.00151325 [15,] 0.95949406 -1.1676193 -0.1623095 2.070270861 -0.49558344 [16,] -0.11028549 -2.1800396 0.5630558 -0.153398412 0.35555030 [17,] -0.51100951 -1.3409932 -0.7733534 -0.723581777 -1.13460804 [18,] -0.91119542 -0.2942939 1.6059096 0.258261762 0.87820363 [19,] -0.83717168 -0.4658975 -1.1578085 -0.317059115 0.97291675 > rm.outlier(y,opposite=TRUE) [,1] [,2] [,3] [,4] [,5] [1,] -1.20706575 0.1340882 1.4494963 0.656588464 -0.17778996 [2,] 0.27742924 -0.4906859 -1.0686427 -0.034760390 -0.16999408 [3,] 1.08444118 -0.4405479 -0.8553646 -0.669633580 -0.17378717 [4,] 0.42912469 0.4595894 -0.2806230 -0.007604756 0.85023226 [5,] 0.50605589 -0.6937202 -0.9943401 1.777084448 0.69760871 [6,] -0.57473996 -1.4482049 -0.9685143 -1.138607737 0.54999735 [7,] -0.54663186 0.5747557 -1.1073182 1.367827179 -0.40273198 [8,] -0.56445200 -1.0236557 -1.2519859 1.329564791 -0.19159377 [9,] -0.89003783 -0.0151383 -0.5238281 0.336472797 -1.19452788 [10,] -0.47719270 -0.9359486 -0.4968500 0.006892838 -0.05315882 [11,] -0.99838644 1.1022975 -0.5820759 -0.455468738 0.25519600 [12,] -0.77625389 -0.4755931 -1.1088896 -0.366523933 1.70596401 [13,] 0.06445882 -0.7094400 -1.0149620 0.648286568 1.00151325 [14,] 0.95949406 -0.5012581 -0.1623095 2.070270861 -0.49558344 [15,] -0.11028549 -1.6290935 0.5630558 -0.153398412 0.35555030 [16,] -0.51100951 -1.1676193 1.6478175 -1.390700947 -1.13460804 [17,] -0.91119542 -1.3409932 -0.7733534 -0.723581777 0.87820363 [18,] -0.83717168 -0.2942939 1.6059096 0.258261762 0.97291675 [19,] 2.41583518 -0.4658975 -1.1578085 -0.317059115 2.12111711 > > > > cleanEx(); ..nameEx <- "scores" > > ### * scores > > flush(stderr()); flush(stdout()) > > ### Name: scores > ### Title: Calculate scores of the sample > ### Aliases: scores > ### Keywords: models > > ### ** Examples > > set.seed(1234) > x = rnorm(10) > scores(x) [1] -0.8273937 0.6633811 1.4738069 -1.9708424 0.8157183 0.8929749 [7] -0.1923930 -0.1641660 -0.1820615 -0.5090247 > scores(x,prob=1) [1] 0.20400697 0.74645675 0.92973321 0.02437095 0.79266936 0.81406470 [7] 0.42371719 0.43480024 0.42776722 0.30536747 > scores(x,prob=0.5) [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE > scores(x,prob=0.1) [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE > scores(x,prob=0.93) [1] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE > scores(x,type="iqr") [1] -0.32921467 0.00000000 0.57654039 -1.27616952 0.03153977 0.09552038 [7] 0.00000000 0.00000000 0.00000000 -0.06555517 > scores(x,type="mad") [1] -0.592048879 0.756932640 1.490275758 -1.626739781 0.894780431 [6] 0.964688899 -0.017445523 0.008096708 -0.008096708 -0.303961140 > scores(x,prob=0) [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE > > > > ### *