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("subselect-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('subselect') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "anneal" > > ### * anneal > > flush(stderr()); flush(stdout()) > > ### Name: anneal > ### Title: Simulated Annealing Search for an optimal k-variable subset > ### Aliases: anneal > ### Keywords: manip > > ### ** Examples > > > # For illustration of use, a small data set with very few iterations > # of the algorithm. > > data(swiss) > anneal(cor(swiss),2,3,nsol=4,niter=10,criterion="RM") $subsets , , Card.2 Var.1 Var.2 Var.3 Solution 1 3 6 0 Solution 2 4 5 0 Solution 3 4 5 0 Solution 4 3 6 0 , , Card.3 Var.1 Var.2 Var.3 Solution 1 3 5 6 Solution 2 4 5 6 Solution 3 4 5 6 Solution 4 1 2 5 $values card.2 card.3 Solution 1 0.8016409 0.8769672 Solution 2 0.7982296 0.9043760 Solution 3 0.7982296 0.9043760 Solution 4 0.8016409 0.8791856 $bestvalues Card.2 Card.3 0.8016409 0.9043760 $bestsets Var.1 Var.2 Var.3 Card.2 3 6 0 Card.3 4 5 6 $call anneal(mat = cor(swiss), kmin = 2, kmax = 3, nsol = 4, niter = 10, criterion = "RM") > > ##$subsets > ##, , Card.2 > ## > ## Var.1 Var.2 Var.3 > ##Solution 1 3 6 0 > ##Solution 2 4 5 0 > ##Solution 3 1 2 0 > ##Solution 4 3 6 0 > ## > ##, , Card.3 > ## > ## Var.1 Var.2 Var.3 > ##Solution 1 4 5 6 > ##Solution 2 3 5 6 > ##Solution 3 3 4 6 > ##Solution 4 4 5 6 > ## > ## > ##$values > ## card.2 card.3 > ##Solution 1 0.8016409 0.9043760 > ##Solution 2 0.7982296 0.8769672 > ##Solution 3 0.7945390 0.8777509 > ##Solution 4 0.8016409 0.9043760 > ## > ##$bestvalues > ## Card.2 Card.3 > ##0.8016409 0.9043760 > ## > ##$bestsets > ## Var.1 Var.2 Var.3 > ##Card.2 3 6 0 > ##Card.3 4 5 6 > ## > ##$call > ##anneal(cor(swiss), 2, 3, nsol = 4, niter = 10, criterion = "RM") > > # > # > # Excluding variable number 6 from the subsets. > # > > data(swiss) > anneal(cor(swiss),2,3,nsol=4,niter=10,criterion="RM",exclude=c(6)) $subsets , , Card.2 Var.1 Var.2 Var.3 Solution 1 1 2 0 Solution 2 4 5 0 Solution 3 4 5 0 Solution 4 4 5 0 , , Card.3 Var.1 Var.2 Var.3 Solution 1 1 2 4 Solution 2 1 4 5 Solution 3 1 2 5 Solution 4 1 2 5 $values card.2 card.3 Solution 1 0.7945390 0.8537422 Solution 2 0.7982296 0.8686515 Solution 3 0.7982296 0.8791856 Solution 4 0.7982296 0.8791856 $bestvalues Card.2 Card.3 0.7982296 0.8791856 $bestsets Var.1 Var.2 Var.3 Card.2 4 5 0 Card.3 1 2 5 $call anneal(mat = cor(swiss), kmin = 2, kmax = 3, nsol = 4, niter = 10, exclude = c(6), criterion = "RM") > > ##$subsets > ##, , Card.2 > ## > ## Var.1 Var.2 Var.3 > ##Solution 1 4 5 0 > ##Solution 2 4 5 0 > ##Solution 3 4 5 0 > ##Solution 4 4 5 0 > ## > ##, , Card.3 > ## > ## Var.1 Var.2 Var.3 > ##Solution 1 1 2 5 > ##Solution 2 1 2 5 > ##Solution 3 1 2 5 > ##Solution 4 1 4 5 > ## > ## > ##$values > ## card.2 card.3 > ##Solution 1 0.7982296 0.8791856 > ##Solution 2 0.7982296 0.8791856 > ##Solution 3 0.7982296 0.8791856 > ##Solution 4 0.7982296 0.8686515 > ## > ##$bestvalues > ## Card.2 Card.3 > ##0.7982296 0.8791856 > ## > ##$bestsets > ## Var.1 Var.2 Var.3 > ##Card.2 4 5 0 > ##Card.3 1 2 5 > ## > ##$call > ##anneal(cor(swiss), 2, 3, nsol = 4, niter = 10, criterion = "RM", > ## exclude=c(6)) > > # specifying initial solutions: using the subsets produced by > # simulated annealing for one criterion (RM, by default) as initial > # solutions for the simulated annealing search with a different criterion. > > data(swiss) > rmresults<-anneal(cor(swiss),2,3,nsol=4,niter=10, setseed=TRUE) > anneal(cor(swiss),2,3,nsol=4,niter=10,criterion="gcd", initialsol=rmresults$subsets) $subsets , , Card.2 Var.1 Var.2 Var.3 Solution 1 4 6 0 Solution 2 3 6 0 Solution 3 3 6 0 Solution 4 3 6 0 , , Card.3 Var.1 Var.2 Var.3 Solution 1 4 5 6 Solution 2 4 5 6 Solution 3 1 5 6 Solution 4 4 5 6 $values card.2 card.3 Solution 1 0.7792651 0.9253720 Solution 2 0.8487026 0.9253720 Solution 3 0.8487026 0.8048528 Solution 4 0.8487026 0.9253720 $bestvalues Card.2 Card.3 0.8487026 0.9253720 $bestsets Var.1 Var.2 Var.3 Card.2 3 6 0 Card.3 4 5 6 $call anneal(mat = cor(swiss), kmin = 2, kmax = 3, nsol = 4, niter = 10, criterion = "gcd", initialsol = rmresults$subsets) > > ##$subsets > ##, , Card.2 > ## > ## Var.1 Var.2 Var.3 > ##Solution 1 3 6 0 > ##Solution 2 3 6 0 > ##Solution 3 3 6 0 > ##Solution 4 3 6 0 > ## > ##, , Card.3 > ## > ## Var.1 Var.2 Var.3 > ##Solution 1 4 5 6 > ##Solution 2 4 5 6 > ##Solution 3 3 4 6 > ##Solution 4 4 5 6 > ## > ## > ##$values > ## card.2 card.3 > ##Solution 1 0.8487026 0.925372 > ##Solution 2 0.8487026 0.925372 > ##Solution 3 0.8487026 0.798864 > ##Solution 4 0.8487026 0.925372 > ## > ##$bestvalues > ## Card.2 Card.3 > ##0.8487026 0.9253720 > ## > ##$bestsets > ## Var.1 Var.2 Var.3 > ##Card.2 3 6 0 > ##Card.3 4 5 6 > ## > ##$call > ##anneal(cor(swiss), 2, 3, nsol = 4, niter = 10, criterion = "gcd", > ## initialsol = rmresults$subsets) > > > > cleanEx(); ..nameEx <- "gcd" > > ### * gcd > > flush(stderr()); flush(stdout()) > > ### Name: gcd.coef > ### Title: Computes Yanai's GCD in the context of the variable-subset > ### selection problem > ### Aliases: gcd.coef > ### Keywords: manip > > ### ** Examples > > > ## An example with a very small data set. > > data(iris3) > x<-iris3[,,1] > gcd.coef(cor(x),c(1,3)) [1] 0.7666286 > ## [1] 0.7666286 > gcd.coef(cor(x),c(1,3),pcindices=c(1,3)) [1] 0.584452 > ## [1] 0.584452 > gcd.coef(cor(x),c(1,3),pcindices=1) [1] 0.6035127 > ## [1] 0.6035127 > > ## An example computing the GCDs of three subsets produced when the > ## anneal function attempted to optimize the RV criterion (using an > ## absurdly small number of iterations). > > data(swiss) > rvresults<-anneal(cor(swiss),2,nsol=4,niter=5,criterion="Rv") > gcd.coef(cor(swiss),rvresults$subsets) Card.2 Solution 1 0.7092591 Solution 2 0.5608784 Solution 3 0.6351617 Solution 4 0.4962297 > > ## Card.2 > ##Solution 1 0.4962297 > ##Solution 2 0.7092591 > ##Solution 3 0.4748525 > ##Solution 4 0.4649259 > > > > cleanEx(); ..nameEx <- "genetic" > > ### * genetic > > flush(stderr()); flush(stdout()) > > ### Name: genetic > ### Title: Genetic Algorithm searching for an optimal k-variable subset > ### Aliases: genetic > ### Keywords: manip > > ### ** Examples > > # For illustration of use, a small data set with very few iterations > # of the algorithm. > > data(swiss) > genetic(cor(swiss),3,4,popsize=10,nger=5,criterion="Rv") ABORTING. For cardinality k= [1] 4 there is not enough genetic diversity in generation number [1] 3 for acceptable levels of consanguinity (couples differing by at least 2 genes). Try reducing the maximum acceptable number of clones (maxclone) or increasing the population size (popsize) Best criterion value found so far: [1] 0.9557145 $subsets Var.1 Var.2 Var.3 Solution 1 1 2 3 Solution 2 1 2 3 Solution 3 1 2 3 Solution 4 3 4 6 Solution 5 3 4 6 Solution 6 3 4 5 Solution 7 3 4 5 Solution 8 1 3 6 Solution 9 1 3 6 Solution 10 1 3 6 $values Solution 1 Solution 2 Solution 3 Solution 4 Solution 5 Solution 6 0.9141995 0.9141995 0.9141995 0.9034868 0.9034868 0.9020271 Solution 7 Solution 8 Solution 9 Solution 10 0.9020271 0.8988192 0.8988192 0.8988192 $bestvalues Card.3 0.9141995 $bestsets Var.1 Var.2 Var.3 1 2 3 $call genetic(mat = cor(swiss), kmin = 3, kmax = 4, popsize = 10, nger = 5, criterion = "Rv") > > ## For cardinality k= > ##[1] 4 > ## there is not enough genetic diversity in generation number > ##[1] 5 > ## for acceptable levels of consanguinity (couples differing by at > ## least 2 genes). > ## [1] > ## Try reducing the maximum acceptable number of clones (maxclone) or > ## increasing the population size (popsize) > ## [1] > ## Best criterion value found so far: > ##[1] 0.9590526 > ##$subsets > ## Var.1 Var.2 Var.3 > ##Solution 1 1 2 3 > ##Solution 2 1 2 3 > ##Solution 3 1 2 5 > ##Solution 4 1 2 6 > ##Solution 5 3 4 6 > ##Solution 6 3 4 5 > ##Solution 7 3 4 5 > ##Solution 8 1 3 6 > ##Solution 9 2 4 5 > ##Solution 10 1 3 4 > ## > ##$values > ## Solution 1 Solution 2 Solution 3 Solution 4 Solution 5 Solution 6 > ## 0.9141995 0.9141995 0.9098502 0.9074543 0.9034868 0.9020271 > ## Solution 7 Solution 8 Solution 9 Solution 10 > ## 0.9020271 0.8988192 0.8982510 0.8940945 > ## > ##$bestvalues > ## Card.3 > ##0.9141995 > ## > ##$bestsets > ##Var.1 Var.2 Var.3 > ## 1 2 3 > ## > ##$call > ##genetic(cor(swiss), 3, 4, popsize = 10, nger = 5, criterion = "Rv") > > > > cleanEx(); ..nameEx <- "improve" > > ### * improve > > flush(stderr()); flush(stdout()) > > ### Name: improve > ### Title: Restricted Local Improvement search for an optimal k-variable > ### subset > ### Aliases: improve > ### Keywords: manip > > ### ** Examples > > # For illustration of use, a small data set with very few iterations > # of the algorithm. > # > > data(swiss) > improve(cor(swiss),2,3,nsol=4,criterion="GCD") $subsets , , Card.2 Var.1 Var.2 Var.3 Solution 1 3 6 0 Solution 2 3 6 0 Solution 3 3 6 0 Solution 4 3 6 0 , , Card.3 Var.1 Var.2 Var.3 Solution 1 4 5 6 Solution 2 4 5 6 Solution 3 4 5 6 Solution 4 4 5 6 $values card.2 card.3 Solution 1 0.8487026 0.925372 Solution 2 0.8487026 0.925372 Solution 3 0.8487026 0.925372 Solution 4 0.8487026 0.925372 $bestvalues Card.2 Card.3 0.8487026 0.9253720 $bestsets Var.1 Var.2 Var.3 Card.2 3 6 0 Card.3 4 5 6 $call improve(mat = cor(swiss), kmin = 2, kmax = 3, nsol = 4, criterion = "GCD") > ## $subsets > ## , , Card.2 > ## > ## Var.1 Var.2 Var.3 > ## Solution 1 3 6 0 > ## Solution 2 3 6 0 > ## Solution 3 3 6 0 > ## Solution 4 3 6 0 > ## > ## , , Card.3 > ## > ## Var.1 Var.2 Var.3 > ## Solution 1 4 5 6 > ## Solution 2 4 5 6 > ## Solution 3 4 5 6 > ## Solution 4 4 5 6 > ## > ## > ## $values > ## card.2 card.3 > ## Solution 1 0.8487026 0.925372 > ## Solution 2 0.8487026 0.925372 > ## Solution 3 0.8487026 0.925372 > ## Solution 4 0.8487026 0.925372 > ## > ## $bestvalues > ## Card.2 Card.3 > ## 0.8487026 0.9253720 > ## > ## $bestsets > ## Var.1 Var.2 Var.3 > ## Card.2 3 6 0 > ## Card.3 4 5 6 > ## > ##$call > ##improve(cor(swiss), 2, 3, nsol = 4, criterion = "GCD") > > # > # > # Forcing the inclusion of variable 1 in the subset > # > > improve(cor(swiss),2,3,nsol=4,criterion="GCD",include=c(1)) $subsets , , Card.2 Var.1 Var.2 Var.3 Solution 1 1 6 0 Solution 2 1 6 0 Solution 3 1 6 0 Solution 4 1 6 0 , , Card.3 Var.1 Var.2 Var.3 Solution 1 1 5 6 Solution 2 1 5 6 Solution 3 1 5 6 Solution 4 1 5 6 $values card.2 card.3 Solution 1 0.7284477 0.8048528 Solution 2 0.7284477 0.8048528 Solution 3 0.7284477 0.8048528 Solution 4 0.7284477 0.8048528 $bestvalues Card.2 Card.3 0.7284477 0.8048528 $bestsets Var.1 Var.2 Var.3 Card.2 1 6 0 Card.3 1 5 6 $call improve(mat = cor(swiss), kmin = 2, kmax = 3, nsol = 4, include = c(1), criterion = "GCD") > > ## $subsets > ## , , Card.2 > ## > ## Var.1 Var.2 Var.3 > ## Solution 1 1 6 0 > ## Solution 2 1 6 0 > ## Solution 3 1 6 0 > ## Solution 4 1 6 0 > ## > ## , , Card.3 > ## > ## Var.1 Var.2 Var.3 > ## Solution 1 1 5 6 > ## Solution 2 1 5 6 > ## Solution 3 1 5 6 > ## Solution 4 1 5 6 > ## > ## > ## $values > ## card.2 card.3 > ## Solution 1 0.7284477 0.8048528 > ## Solution 2 0.7284477 0.8048528 > ## Solution 3 0.7284477 0.8048528 > ## Solution 4 0.7284477 0.8048528 > ## > ## $bestvalues > ## Card.2 Card.3 > ## 0.7284477 0.8048528 > ## > ## $bestsets > ## Var.1 Var.2 Var.3 > ## Card.2 1 6 0 > ## Card.3 1 5 6 > ## > ##$call > ##improve(cor(swiss), 2, 3, nsol = 4, criterion = "GCD", include = c(1)) > > > > cleanEx(); ..nameEx <- "leaps" > > ### * leaps > > flush(stderr()); flush(stdout()) > > ### Name: leaps > ### Title: A Leaps and Bounds Algorithm for finding the best variable > ### subsets > ### Aliases: leaps > ### Keywords: manip > > ### ** Examples > > > # For illustration of use, a small data set with very few iterations > # of the algorithm. > > data(swiss) > leaps(cor(swiss),nsol=3,criterion="RM") $subsets , , Card.1 Var.1 Var.2 Var.3 Var.4 Var.5 Solution 1 3 0 0 0 0 Solution 2 1 0 0 0 0 Solution 3 4 0 0 0 0 , , Card.2 Var.1 Var.2 Var.3 Var.4 Var.5 Solution 1 3 6 0 0 0 Solution 2 4 5 0 0 0 Solution 3 1 2 0 0 0 , , Card.3 Var.1 Var.2 Var.3 Var.4 Var.5 Solution 1 4 5 6 0 0 Solution 2 1 2 5 0 0 Solution 3 3 4 6 0 0 , , Card.4 Var.1 Var.2 Var.3 Var.4 Var.5 Solution 1 2 4 5 6 0 Solution 2 1 2 5 6 0 Solution 3 1 4 5 6 0 , , Card.5 Var.1 Var.2 Var.3 Var.4 Var.5 Solution 1 1 2 3 5 6 Solution 2 1 2 4 5 6 Solution 3 2 3 4 5 6 $values card.1 card.2 card.3 card.4 card.5 Solution 1 0.6729689 0.8016409 0.9043760 0.9510757 0.9804629 Solution 2 0.6286185 0.7982296 0.8791856 0.9506434 0.9776338 Solution 3 0.6286130 0.7945390 0.8777509 0.9395708 0.9752551 $bestvalues Card.1 Card.2 Card.3 Card.4 Card.5 0.6729689 0.8016409 0.9043760 0.9510757 0.9804629 $bestsets Var.1 Var.2 Var.3 Var.4 Var.5 Card.1 3 0 0 0 0 Card.2 3 6 0 0 0 Card.3 4 5 6 0 0 Card.4 2 4 5 6 0 Card.5 1 2 3 5 6 $call leaps(mat = cor(swiss), nsol = 3, criterion = "RM") > > ##$subsets > ##, , Card.1 > ## > ## Var.1 Var.2 Var.3 Var.4 Var.5 > ##Solution 1 3 0 0 0 0 > ##Solution 2 1 0 0 0 0 > ##Solution 3 4 0 0 0 0 > ## > ##, , Card.2 > ## > ## Var.1 Var.2 Var.3 Var.4 Var.5 > ##Solution 1 3 6 0 0 0 > ##Solution 2 4 5 0 0 0 > ##Solution 3 1 2 0 0 0 > ## > ##, , Card.3 > ## > ## Var.1 Var.2 Var.3 Var.4 Var.5 > ##Solution 1 4 5 6 0 0 > ##Solution 2 1 2 5 0 0 > ##Solution 3 3 4 6 0 0 > ## > ##, , Card.4 > ## > ## Var.1 Var.2 Var.3 Var.4 Var.5 > ##Solution 1 2 4 5 6 0 > ##Solution 2 1 2 5 6 0 > ##Solution 3 1 4 5 6 0 > ## > ##, , Card.5 > ## > ## Var.1 Var.2 Var.3 Var.4 Var.5 > ##Solution 1 1 2 3 5 6 > ##Solution 2 1 2 4 5 6 > ##Solution 3 2 3 4 5 6 > ## > ## > ##$values > ## card.1 card.2 card.3 card.4 card.5 > ##Solution 1 0.6729689 0.8016409 0.9043760 0.9510757 0.9804629 > ##Solution 2 0.6286185 0.7982296 0.8791856 0.9506434 0.9776338 > ##Solution 3 0.6286130 0.7945390 0.8777509 0.9395708 0.9752551 > ## > ##$bestvalues > ## Card.1 Card.2 Card.3 Card.4 Card.5 > ##0.6729689 0.8016409 0.9043760 0.9510757 0.9804629 > ## > ##$bestsets > ## Var.1 Var.2 Var.3 Var.4 Var.5 > ##Card.1 3 0 0 0 0 > ##Card.2 3 6 0 0 0 > ##Card.3 4 5 6 0 0 > ##Card.4 2 4 5 6 0 > ##Card.5 1 2 3 5 6 > ## > ##$call > ##leaps(cor(swiss), nsol = 3, criterion = "RM") > > # > # > # Asking only for 2- and 3- dimensional subsets and excluding > # variable number 6. > # > > data(swiss) > leaps(cor(swiss),2,3,exclude=6,nsol=3,criterion="RM") $subsets , , Card.2 Var.1 Var.2 Var.3 Solution 1 4 5 0 Solution 2 1 2 0 Solution 3 1 3 0 , , Card.3 Var.1 Var.2 Var.3 Solution 1 1 2 5 Solution 2 1 4 5 Solution 3 2 4 5 $values card.2 card.3 Solution 1 0.7982296 0.8791856 Solution 2 0.7945390 0.8686515 Solution 3 0.7755232 0.8628693 $bestvalues Card.2 Card.3 0.7982296 0.8791856 $bestsets Var.1 Var.2 Var.3 Card.2 4 5 0 Card.3 1 2 5 $call leaps(mat = cor(swiss), kmin = 2, kmax = 3, nsol = 3, exclude = 6, criterion = "RM") > > ##$subsets > ##, , Card.2 > ## > ## Var.1 Var.2 Var.3 > ##Solution 1 4 5 0 > ##Solution 2 1 2 0 > ##Solution 3 1 3 0 > ## > ##, , Card.3 > ## > ## Var.1 Var.2 Var.3 > ##Solution 1 1 2 5 > ##Solution 2 1 4 5 > ##Solution 3 2 4 5 > ## > ## > ##$values > ## card.2 card.3 > ##Solution 1 0.7982296 0.8791856 > ##Solution 2 0.7945390 0.8686515 > ##Solution 3 0.7755232 0.8628693 > ## > ##$bestvalues > ## Card.2 Card.3 > ##0.7982296 0.8791856 > ## > ##$bestsets > ## Var.1 Var.2 Var.3 > ##Card.2 4 5 0 > ##Card.3 1 2 5 > ## > ##$call > ##leaps(cor(swiss), 2, 3, exclude = 6, nsol = 3, criterion = "RM") > > # > # Searching for 2- and 3- dimensional subsets that best approximate the > # spaces generated by the first three Principal Components > # > > data(swiss) > leaps(cor(swiss),2,3,criterion="gcd",pcindices=1:3,nsol=3) $subsets , , Card.2 Var.1 Var.2 Var.3 Solution 1 4 5 0 Solution 2 5 6 0 Solution 3 4 6 0 , , Card.3 Var.1 Var.2 Var.3 Solution 1 4 5 6 Solution 2 3 5 6 Solution 3 2 5 6 $values card.2 card.3 Solution 1 0.7831833 0.9253720 Solution 2 0.7475694 0.8459354 Solution 3 0.7383667 0.8243148 $bestvalues Card.2 Card.3 0.7831833 0.9253720 $bestsets Var.1 Var.2 Var.3 Card.2 4 5 0 Card.3 4 5 6 $call leaps(mat = cor(swiss), kmin = 2, kmax = 3, nsol = 3, criterion = "gcd", pcindices = 1:3) > > ##$subsets > ##, , Card.2 > ## > ## Var.1 Var.2 Var.3 > ##Solution 1 4 5 0 > ##Solution 2 5 6 0 > ##Solution 3 4 6 0 > ## > ##, , Card.3 > ## > ## Var.1 Var.2 Var.3 > ##Solution 1 4 5 6 > ##Solution 2 3 5 6 > ##Solution 3 2 5 6 > ## > ## > ##$values > ## card.2 card.3 > ##Solution 1 0.7831827 0.9253684 > ##Solution 2 0.7475630 0.8459302 > ##Solution 3 0.7383665 0.8243032 > ## > ##$bestvalues > ## Card.2 Card.3 > ##0.7831827 0.9253684 > ## > ##$bestsets > ## Var.1 Var.2 Var.3 > ##Card.2 4 5 0 > ##Card.3 4 5 6 > ## > ##$call > ##leaps(cor(swiss), 2, 3, criterion = "gcd", pcindices = 1:3, nsol = 3) > > > > cleanEx(); ..nameEx <- "rm" > > ### * rm > > flush(stderr()); flush(stdout()) > > ### Name: rm.coef > ### Title: Computes the RM coefficient for variable subset selection > ### Aliases: rm.coef > ### Keywords: manip > > ### ** Examples > > > ## An example with a very small data set. > > data(iris3) > x<-iris3[,,1] > rm.coef(var(x),c(1,3)) [1] 0.8724422 > ## [1] 0.8724422 > > ## An example computing the RMs of three subsets produced when the > ## anneal function attempted to optimize the RV criterion (using an > ## absurdly small number of iterations). > > data(swiss) > rvresults<-anneal(cor(swiss),2,nsol=4,niter=5,criterion="Rv") > rm.coef(cor(swiss),rvresults$subsets) Card.2 Solution 1 0.7945390 Solution 2 0.7468382 Solution 3 0.7755232 Solution 4 0.7982296 > > ## Card.2 > ##Solution 1 0.7982296 > ##Solution 2 0.7945390 > ##Solution 3 0.7649296 > ##Solution 4 0.7623326 > > > > cleanEx(); ..nameEx <- "rv" > > ### * rv > > flush(stderr()); flush(stdout()) > > ### Name: rv.coef > ### Title: Computes the RV-coefficient applied to the variable subset > ### selection problem > ### Aliases: rv.coef > ### Keywords: manip > > ### ** Examples > > > # A simple example with a trivially small data set > > data(iris3) > x<-iris3[,,1] > rv.coef(var(x),c(1,3)) [1] 0.8659685 > ## [1] 0.8659685 > > ## An example computing the RVs of three subsets produced when the > ## anneal function attempted to optimize the RM criterion (using an > ## absurdly small number of iterations). > > data(swiss) > rmresults<-anneal(cor(swiss),2,nsol=4,niter=5,criterion="Rm") > rv.coef(cor(swiss),rmresults$subsets) Card.2 Solution 1 0.8389669 Solution 2 0.7529066 Solution 3 0.8389669 Solution 4 0.8668403 > > ## Card.2 > ##Solution 1 0.8389669 > ##Solution 2 0.8663006 > ##Solution 3 0.8093862 > ##Solution 4 0.7529066 > > > > cleanEx(); ..nameEx <- "trimmatrix" > > ### * trimmatrix > > flush(stderr()); flush(stdout()) > > ### Name: trim.matrix > ### Title: Given an ill-conditioned square matrix, deletes rows/columns > ### until a well-conditioned submatrix is obtained. > ### Aliases: trim.matrix > ### Keywords: manip > > ### ** Examples > > > # a trivial example, for illustration of use: creating an extra column, > # as the sum of columns in the "iris" data, and then using the function > # trim.matrix to exclude it from the data's correlation matrix > > data(iris) > lindepir<-cbind(apply(iris[,-5],1,sum),iris[,-5]) > colnames(lindepir)[1]<-"Sum" > cor(lindepir) Sum Sepal.Length Sepal.Width Petal.Length Petal.Width Sum 1.0000000 0.9409143 -0.2230928 0.9713793 0.9538850 Sepal.Length 0.9409143 1.0000000 -0.1175698 0.8717538 0.8179411 Sepal.Width -0.2230928 -0.1175698 1.0000000 -0.4284401 -0.3661259 Petal.Length 0.9713793 0.8717538 -0.4284401 1.0000000 0.9628654 Petal.Width 0.9538850 0.8179411 -0.3661259 0.9628654 1.0000000 > > ## Sum Sepal.Length Sepal.Width Petal.Length Petal.Width > ##Sum 1.0000000 0.9409143 -0.2230928 0.9713793 0.9538850 > ##Sepal.Length 0.9409143 1.0000000 -0.1175698 0.8717538 0.8179411 > ##Sepal.Width -0.2230928 -0.1175698 1.0000000 -0.4284401 -0.3661259 > ##Petal.Length 0.9713793 0.8717538 -0.4284401 1.0000000 0.9628654 > ##Petal.Width 0.9538850 0.8179411 -0.3661259 0.9628654 1.0000000 > > trim.matrix(cor(lindepir)) $trimmedmat Sepal.Length Sepal.Width Petal.Length Petal.Width Sepal.Length 1.0000000 -0.1175698 0.8717538 0.8179411 Sepal.Width -0.1175698 1.0000000 -0.4284401 -0.3661259 Petal.Length 0.8717538 -0.4284401 1.0000000 0.9628654 Petal.Width 0.8179411 -0.3661259 0.9628654 1.0000000 $numbers.discarded [1] 1 $names.discarded [1] "Sum" $size [1] 4 > > ##$trimmedmat > ## Sepal.Length Sepal.Width Petal.Length Petal.Width > ##Sepal.Length 1.0000000 -0.1175698 0.8717538 0.8179411 > ##Sepal.Width -0.1175698 1.0000000 -0.4284401 -0.3661259 > ##Petal.Length 0.8717538 -0.4284401 1.0000000 0.9628654 > ##Petal.Width 0.8179411 -0.3661259 0.9628654 1.0000000 > ## > ##$numbers.discarded > ##[1] 1 > ## > ##$names.discarded > ##[1] "Sum" > ## > ##$size > ##[1] 4 > > data(swiss) > lindepsw<-cbind(apply(swiss,1,sum),swiss) > colnames(lindepsw)[1]<-"Sum" > trim.matrix(cor(lindepsw)) $trimmedmat Fertility Agriculture Examination Education Catholic Fertility 1.0000000 0.35307918 -0.6458827 -0.66378886 0.4636847 Agriculture 0.3530792 1.00000000 -0.6865422 -0.63952252 0.4010951 Examination -0.6458827 -0.68654221 1.0000000 0.69841530 -0.5727418 Education -0.6637889 -0.63952252 0.6984153 1.00000000 -0.1538589 Catholic 0.4636847 0.40109505 -0.5727418 -0.15385892 1.0000000 Infant.Mortality 0.4165560 -0.06085861 -0.1140216 -0.09932185 0.1754959 Infant.Mortality Fertility 0.41655603 Agriculture -0.06085861 Examination -0.11402160 Education -0.09932185 Catholic 0.17549591 Infant.Mortality 1.00000000 $numbers.discarded [1] 1 $names.discarded [1] "Sum" $size [1] 6 > > ##$lowrankmat > ## Fertility Agriculture examination Education Catholic > ##Fertility 1.0000000 0.35307918 -0.6458827 -0.66378886 0.4636847 > ##Agriculture 0.3530792 1.00000000 -0.6865422 -0.63952252 0.4010951 > ##Examination -0.6458827 -0.68654221 1.0000000 0.69841530 -0.5727418 > ##Education -0.6637889 -0.63952252 0.6984153 1.00000000 -0.1538589 > ##Catholic 0.4636847 0.40109505 -0.5727418 -0.15385892 1.0000000 > ##Infant.Mortality 0.4165560 -0.06085861 -0.1140216 -0.09932185 0.1754959 > ## Infant.Mortality > ##Fertility 0.41655603 > ##Agriculture -0.06085861 > ##Examination -0.11402160 > ##Education -0.09932185 > ##Catholic 0.17549591 > ##Infant.Mortality 1.00000000 > ## > ##$numbers.discarded > ##[1] 1 > ## > ##$names.discarded > ##[1] "Sum" > ## > ##$size > ##[1] 6 > > > > > ### *