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("elasticnet-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('elasticnet') Loading required package: lars > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "cv.enet" > > ### * cv.enet > > flush(stderr()); flush(stdout()) > > ### Name: cv.enet > ### Title: Computes K-fold cross-validated error curve for elastic net > ### Aliases: cv.enet > ### Keywords: regression > > ### ** Examples > > data(diabetes) > attach(diabetes) > ## use the L1 fraction norm as the tuning parameter > cv.enet(x2,y,lambda=0.05,s=seq(0,1,length=100),mode="fraction",trace=TRUE,max.steps=80) CV Fold 1 CV Fold 2 CV Fold 3 CV Fold 4 CV Fold 5 CV Fold 6 CV Fold 7 CV Fold 8 CV Fold 9 CV Fold 10 > ## use the number of steps as the tuning parameter > cv.enet(x2,y,lambda=0.05,s=1:50,mode="step") > detach(diabetes) > > > > cleanEx(); ..nameEx <- "enet" > > ### * enet > > flush(stderr()); flush(stdout()) > > ### Name: enet > ### Title: Fits Elastic Net regression models > ### Aliases: enet > ### Keywords: regression > > ### ** Examples > > data(diabetes) > attach(diabetes) > ##fit the lasso model (treated as a special case of the elastic net) > object1 <- enet(x,y,lambda=0) > plot(object1) > ##fit the elastic net model with lambda=1. > object2 <- enet(x,y,lambda=1) > plot(object2) > ##early stopping after 50 LARS-EN steps > object4 <- enet(x2,y,lambda=0.5,max.steps=50) > plot(object4) > detach(diabetes) > > > > cleanEx(); ..nameEx <- "plot.enet" > > ### * plot.enet > > flush(stderr()); flush(stdout()) > > ### Name: plot.enet > ### Title: Plot method for enet objects > ### Aliases: plot.enet > ### Keywords: hplot methods > > ### ** Examples > > data(diabetes) > attach(diabetes) > object <- enet(x,y,lambda=1) > par(mfrow=c(2,2)) > plot(object) > plot(object,xvar="step") > detach(diabetes) > > > > graphics::par(get("par.postscript", env = .CheckExEnv)) > cleanEx(); ..nameEx <- "predict.enet" > > ### * predict.enet > > flush(stderr()); flush(stdout()) > > ### Name: predict.enet > ### Title: Make predictions or extract coefficients from a fitted elastic > ### net model > ### Aliases: predict.enet > ### Keywords: regression methods > > ### ** Examples > > data(diabetes) > attach(diabetes) > object <- enet(x,y,lambda=0.1) > ### make predictions at the values in x, at each of the > ### steps produced in object > fits <- predict.enet(object, x, type="fit") > ### extract the coefficient vector with L1 norm=2000 > coef2000 <- predict(object, s=2000, type="coef", mode="norm") > ### extract the coefficient vector with L1 norm fraction=0.45 > coef.45 <- predict(object, s=0.45, type="coef", mode="fraction") > detach(diabetes) > > > > cleanEx(); ..nameEx <- "spca" > > ### * spca > > flush(stderr()); flush(stdout()) > > ### Name: spca > ### Title: Sparse Principal Components Analysis > ### Aliases: spca > ### Keywords: multivariate > > ### ** Examples > > data(pitprops) > out1<-spca(pitprops,K=6,type="Gram",sparse="penalty",trace=TRUE,para=c(0.06,0.16,0.1,0.5,0.5,0.5)) iterations 10 iterations 20 iterations 30 iterations 40 iterations 50 iterations 60 > ## print the object out1 > out1 Call: spca(x = pitprops, K = 6, para = c(0.06, 0.16, 0.1, 0.5, 0.5, 0.5), type = "Gram", sparse = "penalty", trace = TRUE) 6 sparse PCs Pct. of exp. var. : 28.0 14.0 13.3 7.4 6.8 6.2 Num. of non-zero loadings : 7 4 4 1 1 1 Sparse loadings PC1 PC2 PC3 PC4 PC5 PC6 topdiam -0.477 0.000 0.000 0 0 0 length -0.476 0.000 0.000 0 0 0 moist 0.000 0.785 0.000 0 0 0 testsg 0.000 0.619 0.000 0 0 0 ovensg 0.177 0.000 0.641 0 0 0 ringtop 0.000 0.000 0.589 0 0 0 ringbut -0.250 0.000 0.492 0 0 0 bowmax -0.344 -0.021 0.000 0 0 0 bowdist -0.416 0.000 0.000 0 0 0 whorls -0.400 0.000 0.000 0 0 0 clear 0.000 0.000 0.000 -1 0 0 knots 0.000 0.013 0.000 0 -1 0 diaknot 0.000 0.000 -0.016 0 0 1 > out2<-spca(pitprops,K=6,type="Gram",sparse="varnum",trace=TRUE,para=c(7,4,4,1,1,1)) iterations 10 iterations 20 iterations 30 iterations 40 > out2 Call: spca(x = pitprops, K = 6, para = c(7, 4, 4, 1, 1, 1), type = "Gram", sparse = "varnum", trace = TRUE) 6 sparse PCs Pct. of exp. var. : 28.2 13.9 13.1 7.4 6.8 6.3 Num. of non-zero loadings : 7 4 4 1 1 1 Sparse loadings PC1 PC2 PC3 PC4 PC5 PC6 topdiam -0.477 0.003 0.000 0 0 0 length -0.469 0.000 0.000 0 0 0 moist 0.000 0.785 0.000 0 0 0 testsg 0.000 0.619 0.000 0 0 0 ovensg 0.180 0.000 0.656 0 0 0 ringtop 0.000 0.000 0.589 0 0 0 ringbut -0.290 0.000 0.470 0 0 0 bowmax -0.343 -0.029 -0.048 0 0 0 bowdist -0.414 0.000 0.000 0 0 0 whorls -0.383 0.000 0.000 0 0 0 clear 0.000 0.000 0.000 -1 0 0 knots 0.000 0.000 0.000 0 -1 0 diaknot 0.000 0.000 0.000 0 0 1 > ## to see the contents of out2 > names(out2) [1] "call" "type" "K" "loadings" "pev" "var.all" "vn" [8] "para" "lambda" > ## to get the loadings > out2$loadings PC1 PC2 PC3 PC4 PC5 PC6 topdiam -0.4774878 0.002735770 0.00000000 0 0 0 length -0.4691409 0.000000000 0.00000000 0 0 0 moist 0.0000000 0.785205834 0.00000000 0 0 0 testsg 0.0000000 0.618547389 0.00000000 0 0 0 ovensg 0.1797963 0.000000000 0.65551907 0 0 0 ringtop 0.0000000 0.000000000 0.58924631 0 0 0 ringbut -0.2898492 0.000000000 0.46990985 0 0 0 bowmax -0.3425338 -0.029042064 -0.04762634 0 0 0 bowdist -0.4138718 0.000000000 0.00000000 0 0 0 whorls -0.3833453 0.000000000 0.00000000 0 0 0 clear 0.0000000 0.000000000 0.00000000 -1 0 0 knots 0.0000000 0.000000000 0.00000000 0 -1 0 diaknot 0.0000000 0.000000000 0.00000000 0 0 1 > > > > ### *