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("lasso2-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('lasso2') R Package to solve regression problems while imposing an L1 constraint on the parameters. Based on S-plus Release 2.1 Copyright (C) 1998, 1999 Justin Lokhorst Berwin A. Turlach Bill Venables Copyright (C) 2002 Martin Maechler > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "Iowa" > > ### * Iowa > > flush(stderr()); flush(stdout()) > > ### Name: Iowa > ### Title: The Iowa Wheat Yield Data > ### Aliases: Iowa > ### Keywords: datasets > > ### ** Examples > > data(Iowa) > pairs(Iowa) > > > > cleanEx(); ..nameEx <- "Prostate" > > ### * Prostate > > flush(stderr()); flush(stdout()) > > ### Name: Prostate > ### Title: Prostate Cancer Data > ### Aliases: Prostate > ### Keywords: datasets > > ### ** Examples > > data(Prostate) > attach(Prostate) > pairs(Prostate, col = 1+svi, pch = gleason - 5, + main = paste("Prostate data, n = ", nrow(Prostate))) > detach() > > l1c.P <- l1ce(lcavol ~ ., data = Prostate) > coef(l1c.P)[coef(l1c.P) != 0] ## only age, lcp, lpsa (+ intercept) (Intercept) age lcp lpsa 0.063731165 0.002632999 0.279970078 0.471409992 > summary(l1c.P) Call: l1ce(formula = lcavol ~ ., data = Prostate) Residuals: Min 1Q Median 3Q Max -1.78581 -0.44170 -0.02532 0.54381 2.04761 Coefficients: Value Std. Error Z score Pr(>|Z|) (Intercept) 0.0637 1.1990 0.0532 0.9576 lweight 0.0000 0.1833 0.0000 1.0000 age 0.0026 0.0105 0.2520 0.8011 lbph 0.0000 0.0574 0.0000 1.0000 svi 0.0000 0.2654 0.0000 1.0000 lcp 0.2800 0.0835 3.3527 0.0008 gleason 0.0000 0.1559 0.0000 1.0000 pgg45 0.0000 0.0042 0.0000 1.0000 lpsa 0.4714 0.0870 5.4160 0.0000 Residual standard error: 0.739 on 88.35 degrees of freedom The relative L1 bound was : 0.5 The absolute L1 bound was : 0.9552333 The Lagrangian for the bound is: 9.919065 Correlation of Coefficients: (Intercept) lweight age lbph svi lcp gleason pgg45 lweight -0.5537 age -0.1881 -0.1852 lbph 0.1984 -0.3899 -0.1077 svi -0.1307 0.0022 -0.0263 0.1557 lcp 0.2808 0.0104 -0.0268 0.1211 -0.4317 gleason -0.7329 0.1742 -0.2955 0.1037 0.1845 -0.1969 pgg45 0.3650 -0.0060 0.0608 -0.2025 -0.1678 -0.2217 -0.5635 lpsa 0.2167 -0.2903 -0.0522 -0.0288 -0.3204 -0.2623 -0.2308 0.1108 > > > > cleanEx(); ..nameEx <- "gl1ce" > > ### * gl1ce > > flush(stderr()); flush(stdout()) > > ### Name: gl1ce > ### Title: Generalized Regression With L1-constraint on the Parameters > ### Aliases: gl1ce family.gl1ce > ### Keywords: models optimize regression > > ### ** Examples > > ## example from base: > data(esoph) > summary(esoph) agegp alcgp tobgp ncases ncontrols 25-34:15 0-39g/day:23 0-9g/day:24 Min. : 0.000 Min. : 1.00 35-44:15 40-79 :23 10-19 :24 1st Qu.: 0.000 1st Qu.: 3.00 45-54:16 80-119 :21 20-29 :20 Median : 1.000 Median : 6.00 55-64:16 120+ :21 30+ :20 Mean : 2.273 Mean :11.08 65-74:15 3rd Qu.: 4.000 3rd Qu.:14.00 75+ :11 Max. :17.000 Max. :60.00 > ## effects of alcohol, tobacco and interaction, age-adjusted > modEso <- formula(cbind(ncases, ncontrols) ~ agegp + tobgp * alcgp) > glm.E <- glm(modEso, data = esoph, family = binomial()) > gl1c.E <- gl1ce(modEso, data = esoph, family = binomial()) > gl1c.E Call: gl1ce(formula = modEso, data = esoph, family = binomial()) Coefficients: (Intercept) agegp.L agegp.Q agegp.C agegp^4 -1.4700417 0.3681600 0.0000000 0.0000000 0.0000000 agegp^5 tobgp.L tobgp.Q tobgp.C alcgp.L 0.0000000 0.0000000 0.0000000 0.0000000 0.5566889 alcgp.Q alcgp.C tobgp.L:alcgp.L tobgp.Q:alcgp.L tobgp.C:alcgp.L 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 tobgp.L:alcgp.Q tobgp.Q:alcgp.Q tobgp.C:alcgp.Q tobgp.L:alcgp.C tobgp.Q:alcgp.C 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 tobgp.C:alcgp.C 0.0000000 Family: Family: binomial Link function: logit The absolute L1 bound was : 0.5 The Lagrangian for the bound is : 55.81258 > plot(residuals(gl1c.E) ~ fitted(gl1c.E)) > > sg1c <- summary(gl1c.E) > sg1c Call: gl1ce(formula = modEso, data = esoph, family = binomial()) Deviance Residuals: Min 1Q Median 3Q Max -3.9479 -1.0948 0.2076 0.8383 2.4604 Coefficients Value (Intercept) -1.4700 agegp.L 0.3682 agegp.Q 0 agegp.C 0 agegp^4 0 agegp^5 0 tobgp.L 0 tobgp.Q 0 tobgp.C 0 alcgp.L 0.5567 alcgp.Q 0 alcgp.C 0 tobgp.L:alcgp.L 0 tobgp.Q:alcgp.L 0 tobgp.C:alcgp.L 0 tobgp.L:alcgp.Q 0 tobgp.Q:alcgp.Q 0 tobgp.C:alcgp.Q 0 tobgp.L:alcgp.C 0 tobgp.Q:alcgp.C 0 tobgp.C:alcgp.C 0 Family: Family: binomial Link function: logit The absolute L1 bound was : 0.5 The Lagrangian for the bound is : 55.81258 Number of Iterations: 5 > > ## Another comparison glm() / gl1c.E: > plot(predict(glm.E, type="link"), predict(glm.E, type="response"), + xlim = c(-3,0)) > points(predict(gl1c.E, type="link"), predict(gl1c.E, type="response"), + col = 2, cex = 1.5) > > labels(gl1c.E)#-- oops! empty!! character(0) > > > > cleanEx(); ..nameEx <- "l1ce" > > ### * l1ce > > flush(stderr()); flush(stdout()) > > ### Name: l1ce > ### Title: Regression Fitting With L1-constraint on the Parameters > ### Aliases: l1ce > ### Keywords: models optimize regression > > ### ** Examples > > data(Iowa) > l1c.I <- l1ce(Yield ~ ., Iowa, bound = 10, absolute.t=TRUE) > l1c.I Call: l1ce(formula = Yield ~ ., data = Iowa, bound = 10, absolute.t = TRUE) Coefficients: (Intercept) Year Rain0 Temp1 Rain1 -1.223687e+03 6.665384e-01 8.895341e-03 0.000000e+00 0.000000e+00 Temp2 Rain2 Temp3 Rain3 Temp4 0.000000e+00 1.700162e+00 -1.612996e-01 0.000000e+00 -2.385012e-01 The absolute L1 bound was : 10 The Lagrangian for the bound is: 69.63196 > > ## The same, printing information in each step: > l1ce(Yield ~ ., Iowa, bound = 10, trace = TRUE, absolute.t=TRUE) ****************************** --> Adding variable: 1 ****************************** Iteration number: 0 Value of primal object function : 2782.530000 Value of dual object function : -384.942354 L1 norm of current beta : 0.000000 <= 10.000000 Maximal absolute value in t(X)%*%r : 3.167472e+02 attained 1 time(s) Number of parameters allowed to vary : 1 ****************************** Iteration number: 1 Value of primal object function : 1214.892326 Value of dual object function : 25.579582 L1 norm of current beta : 9.898351 <= 10.000000 Maximal absolute value in t(X)%*%r : 1.189313e+02 attained 1 time(s) Number of parameters allowed to vary : 1 --> Adding variable: 9 --> Stepping onto the border of the L1 ball. ****************************** Iteration number: 2 Value of primal object function : 1088.391622 Value of dual object function : 509.867040 L1 norm of current beta : 10.000000 <= 10.000000 Maximal absolute value in t(X)%*%r : 1.155562e+02 attained 1 time(s) Number of parameters allowed to vary : 2 --> Adding variable: 6 ****************************** Iteration number: 3 Value of primal object function : 1015.808773 Value of dual object function : 925.285484 L1 norm of current beta : 10.000000 <= 10.000000 Maximal absolute value in t(X)%*%r : 7.728661e+01 attained 1 time(s) Number of parameters allowed to vary : 3 --> Adding variable: 7 ****************************** Iteration number: 4 Value of primal object function : 1013.514687 Value of dual object function : 997.935649 L1 norm of current beta : 10.000000 <= 10.000000 Maximal absolute value in t(X)%*%r : 7.058775e+01 attained 1 time(s) Number of parameters allowed to vary : 4 --> Adding variable: 2 ****************************** Iteration number: 5 Value of primal object function : 1013.485899 Value of dual object function : 1013.485899 L1 norm of current beta : 10.000000 <= 10.000000 Maximal absolute value in t(X)%*%r : 6.963196e+01 attained 5 time(s) Number of parameters allowed to vary : 5 Call: l1ce(formula = Yield ~ ., data = Iowa, trace = TRUE, bound = 10, absolute.t = TRUE) Coefficients: (Intercept) Year Rain0 Temp1 Rain1 -1.223687e+03 6.665384e-01 8.895341e-03 0.000000e+00 0.000000e+00 Temp2 Rain2 Temp3 Rain3 Temp4 0.000000e+00 1.700162e+00 -1.612996e-01 0.000000e+00 -2.385012e-01 The absolute L1 bound was : 10 The Lagrangian for the bound is: 69.63196 > > data(Prostate) > l1c.P <- l1ce(lpsa ~ ., Prostate, bound=(1:30)/30) > length(l1c.P)# 30 l1ce models [1] 30 > l1c.P # -- MM: too large; should do this in summary(.)! Call: l1ce(formula = lpsa ~ ., data = Prostate, bound = (1:30)/30) Coefficients: (Intercept) lcavol lweight age lbph svi [1,] 2.4079829 0.05215074 0.00000000 0.000000000 0.000000000 0.00000000 [2,] 2.3375789 0.10430149 0.00000000 0.000000000 0.000000000 0.00000000 [3,] 2.2671749 0.15645223 0.00000000 0.000000000 0.000000000 0.00000000 [4,] 2.1967709 0.20860298 0.00000000 0.000000000 0.000000000 0.00000000 [5,] 2.1263669 0.26075372 0.00000000 0.000000000 0.000000000 0.00000000 [6,] 2.0559629 0.31290446 0.00000000 0.000000000 0.000000000 0.00000000 [7,] 1.9884010 0.36118122 0.00000000 0.000000000 0.000000000 0.01102907 [8,] 1.9371274 0.38725659 0.00000000 0.000000000 0.000000000 0.08526449 [9,] 1.8858539 0.41333196 0.00000000 0.000000000 0.000000000 0.15949991 [10,] 1.7462431 0.43253601 0.02752108 0.000000000 0.000000000 0.22028323 [11,] 1.5266610 0.44551948 0.07995688 0.000000000 0.000000000 0.26888842 [12,] 1.3070788 0.45850294 0.13239268 0.000000000 0.000000000 0.31749362 [13,] 1.0874967 0.47148641 0.18482849 0.000000000 0.000000000 0.36609881 [14,] 0.8679146 0.48446987 0.23726429 0.000000000 0.000000000 0.41470401 [15,] 0.7284811 0.49365402 0.26818634 0.000000000 0.009282588 0.45505849 [16,] 0.6186210 0.50024970 0.29093423 0.000000000 0.021521822 0.48803364 [17,] 0.5087610 0.50684539 0.31368212 0.000000000 0.033761056 0.52100878 [18,] 0.3989010 0.51344107 0.33643002 0.000000000 0.046000291 0.55398393 [19,] 0.4140072 0.51893849 0.35553434 -0.001664361 0.056178983 0.57442325 [20,] 0.5142130 0.52368800 0.37215748 -0.004462120 0.064954486 0.58632593 [21,] 0.6144188 0.52843752 0.38878061 -0.007259879 0.073729989 0.59822860 [22,] 0.6576089 0.53207720 0.40600224 -0.010015486 0.082086242 0.61110512 [23,] 0.6687680 0.53772360 0.41600759 -0.011756627 0.086998743 0.62829926 [24,] 0.6688581 0.54476635 0.42150088 -0.012882424 0.089863829 0.64799306 [25,] 0.6689483 0.55180911 0.42699418 -0.014008221 0.092728916 0.66768687 [26,] 0.6690384 0.55885186 0.43248747 -0.015134019 0.095594003 0.68738067 [27,] 0.6691286 0.56589462 0.43798076 -0.016259816 0.098459090 0.70707447 [28,] 0.6692187 0.57293737 0.44347406 -0.017385613 0.101324177 0.72676828 [29,] 0.6693089 0.57998013 0.44896735 -0.018511410 0.104189264 0.74646208 [30,] 0.6693990 0.58702288 0.45446064 -0.019637208 0.107054351 0.76615588 lcp gleason pgg45 [1,] 0.000000000 0.000000000 0.0000000000 [2,] 0.000000000 0.000000000 0.0000000000 [3,] 0.000000000 0.000000000 0.0000000000 [4,] 0.000000000 0.000000000 0.0000000000 [5,] 0.000000000 0.000000000 0.0000000000 [6,] 0.000000000 0.000000000 0.0000000000 [7,] 0.000000000 0.000000000 0.0000000000 [8,] 0.000000000 0.000000000 0.0000000000 [9,] 0.000000000 0.000000000 0.0000000000 [10,] 0.000000000 0.000000000 0.0000000000 [11,] 0.000000000 0.000000000 0.0000000000 [12,] 0.000000000 0.000000000 0.0000000000 [13,] 0.000000000 0.000000000 0.0000000000 [14,] 0.000000000 0.000000000 0.0000000000 [15,] 0.000000000 0.000000000 0.0001812107 [16,] 0.000000000 0.000000000 0.0005707550 [17,] 0.000000000 0.000000000 0.0009602994 [18,] 0.000000000 0.000000000 0.0013498437 [19,] 0.000000000 0.000000000 0.0017000959 [20,] 0.000000000 0.000000000 0.0020235909 [21,] 0.000000000 0.000000000 0.0023470858 [22,] 0.000000000 0.008508797 0.0025069611 [23,] -0.008582305 0.015186708 0.0027130057 [24,] -0.022423914 0.019465173 0.0029719083 [25,] -0.036265523 0.023743639 0.0032308108 [26,] -0.050107133 0.028022104 0.0034897134 [27,] -0.063948742 0.032300569 0.0037486160 [28,] -0.077790351 0.036579034 0.0040075185 [29,] -0.091631960 0.040857499 0.0042664211 [30,] -0.105473570 0.045135964 0.0045253236 Relative and absolute L1 bounds and the Lagrangians: rel.bound abs.bound Lagrangian [1,] 0.03333333 0.06146616 7.548890e+01 [2,] 0.06666667 0.12293233 6.958815e+01 [3,] 0.10000000 0.18439849 6.368740e+01 [4,] 0.13333333 0.24586466 5.778665e+01 [5,] 0.16666667 0.30733082 5.188590e+01 [6,] 0.20000000 0.36879698 4.598514e+01 [7,] 0.23333333 0.43026315 4.028653e+01 [8,] 0.26666667 0.49172931 3.574636e+01 [9,] 0.30000000 0.55319548 3.120619e+01 [10,] 0.33333333 0.61466164 2.747686e+01 [11,] 0.36666667 0.67612780 2.448159e+01 [12,] 0.40000000 0.73759397 2.148631e+01 [13,] 0.43333333 0.79906013 1.849104e+01 [14,] 0.46666667 0.86052630 1.549576e+01 [15,] 0.50000000 0.92199246 1.305806e+01 [16,] 0.53333333 0.98345862 1.089104e+01 [17,] 0.56666667 1.04492479 8.724026e+00 [18,] 0.60000000 1.10639095 6.557010e+00 [19,] 0.63333333 1.16785712 5.138082e+00 [20,] 0.66666667 1.22932328 4.228589e+00 [21,] 0.70000000 1.29078944 3.319095e+00 [22,] 0.73333333 1.35225561 2.440644e+00 [23,] 0.76666667 1.41372177 1.938086e+00 [24,] 0.80000000 1.47518794 1.661216e+00 [25,] 0.83333333 1.53665410 1.384347e+00 [26,] 0.86666667 1.59812026 1.107478e+00 [27,] 0.90000000 1.65958643 8.306082e-01 [28,] 0.93333333 1.72105259 5.537388e-01 [29,] 0.96666667 1.78251876 2.768694e-01 [30,] 1.00000000 1.84398492 7.371335e-15 > ## Don't show: > str(l1c.P, max.lev = 1) List of 30 $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" $ :List of 14 ..- attr(*, "class")= chr "l1ce" - attr(*, "X.stds")= Named num [1:8] 1.179 0.497 7.445 1.451 0.414 ... ..- attr(*, "names")= chr [1:8] "lcavol" "lweight" "age" "lbph" ... - attr(*, "sweep.out")=List of 7 - attr(*, "xtx")= num [1:8, 1:8] 96.00 18.64 21.60 2.63 51.73 ... ..- attr(*, "dimnames")=List of 2 - attr(*, "terms")=Classes 'terms', 'formula' length 3 lpsa ~ lcavol + lweight + age + lbph + svi + lcp + gleason + pgg45 .. ..- attr(*, "variables")= language list(lpsa, lcavol, lweight, age, lbph, svi, lcp, gleason, pgg45) .. ..- attr(*, "factors")= int [1:9, 1:8] 0 1 0 0 0 0 0 0 0 0 ... .. .. ..- attr(*, "dimnames")=List of 2 .. ..- attr(*, "term.labels")= chr [1:8] "lcavol" "lweight" "age" "lbph" ... .. ..- attr(*, "order")= int [1:8] 1 1 1 1 1 1 1 1 .. ..- attr(*, "intercept")= int 1 .. ..- attr(*, "response")= int 1 .. ..- attr(*, ".Environment")=length 6 - attr(*, "call")= language l1ce(formula = lpsa ~ ., data = Prostate, bound = (1:30)/30) - attr(*, "assign")= int [1:9] 0 1 2 3 4 5 6 7 8 - attr(*, "class")= chr "l1celist" > ## End Don't show > > plot(resid(l1c.I) ~ fitted(l1c.I)) > abline(h = 0, lty = 3, lwd = .2) > > > > cleanEx(); ..nameEx <- "merge.formula" > > ### * merge.formula > > flush(stderr()); flush(stdout()) > > ### Name: merge.formula > ### Title: Merge Formula With Right Hand Side of Second Formula > ### Aliases: merge.formula > ### Keywords: utilities > > ### ** Examples > > merge.formula(y ~ x1, ~ x2) ## -> y ~ x1 + x2 y ~ x1 + x2 > > f2 <- merge.formula(y ~ x1*x2, z ~ (x2+x4)^3) > f. <- merge.formula(y ~ x1*x2, ~ (x2+x4)^3) # no LHS for 2nd term > f2 y ~ x1 * x2 + (x2 + x4)^3 > stopifnot(f2 == f.) > > > > cleanEx(); ..nameEx <- "plot.l1celist" > > ### * plot.l1celist > > flush(stderr()); flush(stdout()) > > ### Name: plot.l1celist > ### Title: Plot Method for `l1celist' Objects > ### Aliases: plot.l1celist > ### Keywords: hplot > > ### ** Examples > > data(Prostate) > l1c.P <- l1ce(lpsa ~ ., Prostate, bound=(1:20)/20) > length(l1c.P)# 20 l1ce models [1] 20 > plot(l1c.P) > > > > cleanEx(); ..nameEx <- "predict.gl1ce" > > ### * predict.gl1ce > > flush(stderr()); flush(stdout()) > > ### Name: predict.gl1ce > ### Title: Prediction Method for a `gl1ce' Object > ### Aliases: predict.gl1ce > ### Keywords: models > > ### ** Examples > > ## start with > example(gl1ce) gl1ce> data(esoph) gl1ce> summary(esoph) agegp alcgp tobgp ncases ncontrols 25-34:15 0-39g/day:23 0-9g/day:24 Min. : 0.000 Min. : 1.00 35-44:15 40-79 :23 10-19 :24 1st Qu.: 0.000 1st Qu.: 3.00 45-54:16 80-119 :21 20-29 :20 Median : 1.000 Median : 6.00 55-64:16 120+ :21 30+ :20 Mean : 2.273 Mean :11.08 65-74:15 3rd Qu.: 4.000 3rd Qu.:14.00 75+ :11 Max. :17.000 Max. :60.00 gl1ce> modEso <- formula(cbind(ncases, ncontrols) ~ agegp + tobgp * alcgp) gl1ce> glm.E <- glm(modEso, data = esoph, family = binomial()) gl1ce> gl1c.E <- gl1ce(modEso, data = esoph, family = binomial()) gl1ce> gl1c.E Call: gl1ce(formula = modEso, data = esoph, family = binomial()) Coefficients: (Intercept) agegp.L agegp.Q agegp.C agegp^4 -1.4700417 0.3681600 0.0000000 0.0000000 0.0000000 agegp^5 tobgp.L tobgp.Q tobgp.C alcgp.L 0.0000000 0.0000000 0.0000000 0.0000000 0.5566889 alcgp.Q alcgp.C tobgp.L:alcgp.L tobgp.Q:alcgp.L tobgp.C:alcgp.L 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 tobgp.L:alcgp.Q tobgp.Q:alcgp.Q tobgp.C:alcgp.Q tobgp.L:alcgp.C tobgp.Q:alcgp.C 0.0000000 0.0000000 0.0000000 0.0000000 0.0000000 tobgp.C:alcgp.C 0.0000000 Family: Family: binomial Link function: logit The absolute L1 bound was : 0.5 The Lagrangian for the bound is : 55.81258 gl1ce> plot(residuals(gl1c.E) ~ fitted(gl1c.E)) gl1ce> sg1c <- summary(gl1c.E) gl1ce> sg1c Call: gl1ce(formula = modEso, data = esoph, family = binomial()) Deviance Residuals: Min 1Q Median 3Q Max -3.9479 -1.0948 0.2076 0.8383 2.4604 Coefficients Value (Intercept) -1.4700 agegp.L 0.3682 agegp.Q 0 agegp.C 0 agegp^4 0 agegp^5 0 tobgp.L 0 tobgp.Q 0 tobgp.C 0 alcgp.L 0.5567 alcgp.Q 0 alcgp.C 0 tobgp.L:alcgp.L 0 tobgp.Q:alcgp.L 0 tobgp.C:alcgp.L 0 tobgp.L:alcgp.Q 0 tobgp.Q:alcgp.Q 0 tobgp.C:alcgp.Q 0 tobgp.L:alcgp.C 0 tobgp.Q:alcgp.C 0 tobgp.C:alcgp.C 0 Family: Family: binomial Link function: logit The absolute L1 bound was : 0.5 The Lagrangian for the bound is : 55.81258 Number of Iterations: 5 gl1ce> plot(predict(glm.E, type = "link"), predict(glm.E, type = "response"), xlim = c(-3, 0)) gl1ce> points(predict(gl1c.E, type = "link"), predict(gl1c.E, type = "response"), col = 2, cex = 1.5) gl1ce> labels(gl1c.E) character(0) > predict(gl1c.E, new = esoph[1:7,])# type 'link' 1 2 3 4 5 6 7 -2.063498 -2.063498 -2.063498 -2.063498 -1.814539 -1.814539 -1.814539 > predict(gl1c.E, new = esoph[1:7,], type = "response") 1 2 3 4 5 6 7 0.1126956 0.1126956 0.1126956 0.1126956 0.1400905 0.1400905 0.1400905 > > ## identities / consistency checks : > stopifnot(predict(gl1c.E, type = "response") == fitted(gl1c.E), + all.equal(predict(gl1c.E)[1:7], + predict(gl1c.E, new = esoph[1:7,])), + all.equal(fitted(gl1c.E)[1:7], + predict(gl1c.E, new = esoph[1:7,], type = "response")) + ) > > > > cleanEx(); ..nameEx <- "predict.l1ce" > > ### * predict.l1ce > > flush(stderr()); flush(stdout()) > > ### Name: predict.l1ce > ### Title: Predict Method for `l1ce' Objects > ### Aliases: predict.l1ce > ### Keywords: models > > ### ** Examples > > data(Iowa) > l1c.I <- l1ce(Yield ~ ., Iowa, bound = 10, absolute.t=TRUE) > p10 <- predict(l1c.I, newdata = Iowa[10:19,]) > stopifnot(all.equal(p10, fitted(l1c.I)[10:19])) > > > > cleanEx(); ..nameEx <- "qr.rtr.inv" > > ### * qr.rtr.inv > > flush(stderr()); flush(stdout()) > > ### Name: qr.rtr.inv > ### Title: Reconstruct the Inverse of R'R from a QR Object > ### Aliases: qr.rtr.inv > ### Keywords: algebra array > > ### ** Examples > > (h3 <- 1/outer(0:5, 1:3, "+")) [,1] [,2] [,3] [1,] 1.0000000 0.5000000 0.3333333 [2,] 0.5000000 0.3333333 0.2500000 [3,] 0.3333333 0.2500000 0.2000000 [4,] 0.2500000 0.2000000 0.1666667 [5,] 0.2000000 0.1666667 0.1428571 [6,] 0.1666667 0.1428571 0.1250000 > rtr <- qr.rtr.inv(qr(h3)) > all.equal(c(rtr %*% 1:3), solve(crossprod(h3), 1:3)) [1] TRUE > > > > cleanEx(); ..nameEx <- "summary.l1ce" > > ### * summary.l1ce > > flush(stderr()); flush(stdout()) > > ### Name: summary.l1ce > ### Title: Summary Method for ``l1ce'' Objects (Regression with L1 > ### Constraint) > ### Aliases: summary.l1ce print.summary.l1ce > ### Keywords: regression > > ### ** Examples > > data(Prostate) > summary(l1ce(lpsa ~ .,Prostate)) Call: l1ce(formula = lpsa ~ ., data = Prostate) Residuals: Min 1Q Median 3Q Max -1.6355 -0.4119 0.0760 0.4520 1.8299 Coefficients: Value Std. Error Z score Pr(>|Z|) (Intercept) 0.7285 1.3898 0.5242 0.6002 lcavol 0.4937 0.0919 5.3711 0.0000 lweight 0.2682 0.1774 1.5115 0.1307 age 0.0000 0.0111 0.0000 1.0000 lbph 0.0093 0.0587 0.1581 0.8744 svi 0.4551 0.2525 1.8023 0.0715 lcp 0.0000 0.0947 0.0000 1.0000 gleason 0.0000 0.1685 0.0000 1.0000 pgg45 0.0002 0.0046 0.0391 0.9688 Residual standard error: 0.7595 on 88.36 degrees of freedom The relative L1 bound was : 0.5 The absolute L1 bound was : 0.9219925 The Lagrangian for the bound is: 13.05806 Correlation of Coefficients: (Intercept) lcavol lweight age lbph svi lcp gleason lcavol 0.1988 lweight -0.4815 -0.2071 age -0.3938 -0.0603 -0.0974 lbph 0.3629 -0.0201 -0.5165 -0.1303 svi -0.0624 -0.2273 -0.1442 0.0635 0.0648 lcp 0.0457 -0.4153 0.0598 0.0665 0.0632 -0.3779 gleason -0.7666 -0.2009 0.1163 -0.0774 -0.0617 0.1084 -0.0243 pgg45 0.4988 0.0956 -0.0380 -0.0630 -0.1111 -0.1921 -0.2935 -0.6526 > > # Produces the following output: > ## Not run: > ##D Call: > ##D l1ce(formula = lpsa ~ ., data = Prostate) > ##D Residuals: > ##D Min 1Q Median 3Q Max > ##D -1.636 -0.4119 0.076 0.452 1.83 > ##D > ##D Coefficients: > ##D Value Std. Error Z score Pr(>|Z|) > ##D (Intercept) 0.7285 1.3898 0.5242 0.6002 > ##D lcavol 0.4937 0.0919 5.3711 0.0000 > ##D lweight 0.2682 0.1774 1.5115 0.1307 > ##D age 0.0000 0.0111 0.0000 1.0000 > ##D lbph 0.0093 0.0587 0.1581 0.8744 > ##D svi 0.4551 0.2525 1.8023 0.0715 > ##D lcp 0.0000 0.0947 0.0000 1.0000 > ##D gleason 0.0000 0.1685 0.0000 1.0000 > ##D pgg45 0.0002 0.0046 0.0391 0.9688 > ##D > ##D Residual standard error: 0.7595 on 88.36 degrees of freedom > ##D The relative L1 bound was : 0.5 > ##D The absolute L1 bound was : 0.9219925 > ##D The Lagrangian for the bound is: 13.05806 > ##D > ##D Correlation of Coefficients: > ##D (Intercept) lcavol lweight age lbph svi lcp gleason > ##D lcavol 0.1988 > ##D lweight -0.4815 -0.2071 > ##D age -0.3938 -0.0603 -0.0974 > ##D lbph 0.3629 -0.0201 -0.5165 -0.1303 > ##D svi -0.0624 -0.2273 -0.1442 0.0635 0.0648 > ##D lcp 0.0457 -0.4153 0.0598 0.0665 0.0632 -0.3779 > ##D gleason -0.7666 -0.2009 0.1163 -0.0774 -0.0617 0.1084 -0.0243 > ##D pgg45 0.4988 0.0956 -0.0380 -0.0630 -0.1111 -0.1921 -0.2935 -0.6526 > ## End(Not run) > > > > cleanEx(); ..nameEx <- "tr" > > ### * tr > > flush(stderr()); flush(stdout()) > > ### Name: tr > ### Title: Trace of a Matrix > ### Aliases: tr > ### Keywords: math > > ### ** Examples > > tr(cbind(1,1:3,4:2)) # 5 [1] 5 > > > > ### *