Debian Codegraph @

man/tidy.glmnet.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/glmnet-glmnet.R
3 \name{tidy.glmnet}
4 \alias{tidy.glmnet}
5 \alias{glmnet_tidiers}
6 \title{Tidy a(n) glmnet object}
7 \usage{
8 \method{tidy}{glmnet}(x, return_zeros = FALSE, ...)
9 }
10 \arguments{
11 \item{x}{A \code{glmnet} object returned from \code{\link[glmnet:glmnet]{glmnet::glmnet()}}.}
12
13 \item{return_zeros}{Logical indicating whether coefficients with value zero
14 zero should be included in the results. Defaults to \code{FALSE}.}
15
16 \item{...}{Additional arguments. Not used. Needed to match generic
17 signature only. \strong{Cautionary note:} Misspelled arguments will be
18 absorbed in \code{...}, where they will be ignored. If the misspelled
19 argument has a default value, the default value will be used.
20 For example, if you pass \code{conf.lvel = 0.9}, all computation will
21 proceed using \code{conf.level = 0.95}. Two exceptions here are:
22 \itemize{
23 \item \code{tidy()} methods will warn when supplied an \code{exponentiate} argument if
24 it will be ignored.
25 \item \code{augment()} methods will warn when supplied a \code{newdata} argument if it
26 will be ignored.
27 }}
28 }
29 \description{
30 Tidy summarizes information about the components of a model.
31 A model component might be a single term in a regression, a single
32 hypothesis, a cluster, or a class. Exactly what tidy considers to be a
33 model component varies across models but is usually self-evident.
34 If a model has several distinct types of components, you will need to
35 specify which components to return.
36 }
37 \details{
38 Note that while this representation of GLMs is much easier
39 to plot and combine than the default structure, it is also much
40 more memory-intensive. Do not use for large, sparse matrices.
41
42 No \code{augment} method is yet provided even though the model produces
43 predictions, because the input data is not tidy (it is a matrix that
44 may be very wide) and therefore combining predictions with it is not
45 logical. Furthermore, predictions make sense only with a specific
46 choice of lambda.
47 }
48 \examples{
49 \dontshow{if (FALSE) withAutoprint(\{ # examplesIf}
50
51 # load libraries for models and data
52 library(glmnet)
53
54 set.seed(2014)
55 x <- matrix(rnorm(100 * 20), 100, 20)
56 y <- rnorm(100)
57 fit1 <- glmnet(x, y)
58
59 # summarize model fit with tidiers + visualization
60 tidy(fit1)
61 glance(fit1)
62
63 library(dplyr)
64 library(ggplot2)
65
66 tidied <- tidy(fit1) |> filter(term != "(Intercept)")
67
68 ggplot(tidied, aes(step, estimate, group = term)) +
69 geom_line()
70
71 ggplot(tidied, aes(lambda, estimate, group = term)) +
72 geom_line() +
73 scale_x_log10()
74
75 ggplot(tidied, aes(lambda, dev.ratio)) +
76 geom_line()
77
78 # works for other types of regressions as well, such as logistic
79 g2 <- sample(1:2, 100, replace = TRUE)
80 fit2 <- glmnet(x, g2, family = "binomial")
81 tidy(fit2)
82 \dontshow{\}) # examplesIf}
83 }
84 \seealso{
85 \code{\link[=tidy]{tidy()}}, \code{\link[glmnet:glmnet]{glmnet::glmnet()}}
86
87 Other glmnet tidiers:
88 \code{\link{glance.cv.glmnet}()},
89 \code{\link{glance.glmnet}()},
90 \code{\link{tidy.cv.glmnet}()}
91 }
92 \concept{glmnet tidiers}
93 \value{
94 A \code{\link[tibble:tibble]{tibble::tibble()}} with columns:
95 \item{dev.ratio}{Fraction of null deviance explained at each value of lambda.}
96 \item{estimate}{The estimated value of the regression term.}
97 \item{lambda}{Value of penalty parameter lambda.}
98 \item{step}{Which step of lambda choices was used.}
99 \item{term}{The name of the regression term.}
100
101 }