Debian Codegraph @

man/glance.cv.glmnet.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/glmnet-cv-glmnet.R
3 \name{glance.cv.glmnet}
4 \alias{glance.cv.glmnet}
5 \title{Glance at a(n) cv.glmnet object}
6 \usage{
7 \method{glance}{cv.glmnet}(x, ...)
8 }
9 \arguments{
10 \item{x}{A \code{cv.glmnet} object returned from \code{\link[glmnet:cv.glmnet]{glmnet::cv.glmnet()}}.}
11
12 \item{...}{Additional arguments. Not used. Needed to match generic
13 signature only. \strong{Cautionary note:} Misspelled arguments will be
14 absorbed in \code{...}, where they will be ignored. If the misspelled
15 argument has a default value, the default value will be used.
16 For example, if you pass \code{conf.lvel = 0.9}, all computation will
17 proceed using \code{conf.level = 0.95}. Two exceptions here are:
18 \itemize{
19 \item \code{tidy()} methods will warn when supplied an \code{exponentiate} argument if
20 it will be ignored.
21 \item \code{augment()} methods will warn when supplied a \code{newdata} argument if it
22 will be ignored.
23 }}
24 }
25 \description{
26 Glance accepts a model object and returns a \code{\link[tibble:tibble]{tibble::tibble()}}
27 with exactly one row of model summaries. The summaries are typically
28 goodness of fit measures, p-values for hypothesis tests on residuals,
29 or model convergence information.
30
31 Glance never returns information from the original call to the modeling
32 function. This includes the name of the modeling function or any
33 arguments passed to the modeling function.
34
35 Glance does not calculate summary measures. Rather, it farms out these
36 computations to appropriate methods and gathers the results together.
37 Sometimes a goodness of fit measure will be undefined. In these cases
38 the measure will be reported as \code{NA}.
39
40 Glance returns the same number of columns regardless of whether the
41 model matrix is rank-deficient or not. If so, entries in columns
42 that no longer have a well-defined value are filled in with an \code{NA}
43 of the appropriate type.
44 }
45 \examples{
46 \dontshow{if (rlang::is_installed(c("glmnet", "ggplot2"))) withAutoprint(\{ # examplesIf}
47
48 # load libraries for models and data
49 library(glmnet)
50
51 set.seed(27)
52
53 nobs <- 100
54 nvar <- 50
55 real <- 5
56
57 x <- matrix(rnorm(nobs * nvar), nobs, nvar)
58 beta <- c(rnorm(real, 0, 1), rep(0, nvar - real))
59 y <- c(t(beta) \%*\% t(x)) + rnorm(nvar, sd = 3)
60
61 cvfit1 <- cv.glmnet(x, y)
62
63 tidy(cvfit1)
64 glance(cvfit1)
65
66 library(ggplot2)
67
68 tidied_cv <- tidy(cvfit1)
69 glance_cv <- glance(cvfit1)
70
71 # plot of MSE as a function of lambda
72 g <- ggplot(tidied_cv, aes(lambda, estimate)) +
73 geom_line() +
74 scale_x_log10()
75 g
76
77 # plot of MSE as a function of lambda with confidence ribbon
78 g <- g + geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = .25)
79 g
80
81 # plot of MSE as a function of lambda with confidence ribbon and choices
82 # of minimum lambda marked
83 g <- g +
84 geom_vline(xintercept = glance_cv$lambda.min) +
85 geom_vline(xintercept = glance_cv$lambda.1se, lty = 2)
86 g
87
88 # plot of number of zeros for each choice of lambda
89 ggplot(tidied_cv, aes(lambda, nzero)) +
90 geom_line() +
91 scale_x_log10()
92
93 # coefficient plot with min lambda shown
94 tidied <- tidy(cvfit1$glmnet.fit)
95
96 ggplot(tidied, aes(lambda, estimate, group = term)) +
97 scale_x_log10() +
98 geom_line() +
99 geom_vline(xintercept = glance_cv$lambda.min) +
100 geom_vline(xintercept = glance_cv$lambda.1se, lty = 2)
101 \dontshow{\}) # examplesIf}
102 }
103 \seealso{
104 \code{\link[=glance]{glance()}}, \code{\link[glmnet:cv.glmnet]{glmnet::cv.glmnet()}}
105
106 Other glmnet tidiers:
107 \code{\link{glance.glmnet}()},
108 \code{\link{tidy.cv.glmnet}()},
109 \code{\link{tidy.glmnet}()}
110 }
111 \concept{glmnet tidiers}
112 \value{
113 A \code{\link[tibble:tibble]{tibble::tibble()}} with exactly one row and columns:
114 \item{lambda.1se}{The value of the penalization parameter lambda that results in the sparsest model while remaining within one standard error of the minimum loss.}
115 \item{lambda.min}{The value of the penalization parameter lambda that achieved minimum loss as estimated by cross validation.}
116 \item{nobs}{Number of observations used.}
117
118 }