Debian Codegraph @

R/stats-smooth.spline.R

raw
1 #' @templateVar class smooth.spline
2 #' @template title_desc_tidy
3 #'
4 #' @param x A `smooth.spline` object returned from [stats::smooth.spline()].
5 #' @template param_data
6 #' @template param_unused_dots
7 #'
8 # sometimes triggers CRAN NOTE `elapsed time > 10s`
9 #' @examplesIf FALSE
10 #'
11 #' # fit model
12 #' spl <- smooth.spline(mtcars$wt, mtcars$mpg, df = 4)
13 #'
14 #' # summarize model fit with tidiers
15 #' augment(spl, mtcars)
16 #'
17 #' # calls original columns x and y
18 #' augment(spl)
19 #'
20 #' library(ggplot2)
21 #' ggplot(augment(spl, mtcars), aes(wt, mpg)) +
22 #' geom_point() +
23 #' geom_line(aes(y = .fitted))
24 #'
25 #' @evalRd return_augment()
26 #'
27 #' @aliases smooth.spline_tidiers
28 #' @export
29 #' @family smoothing spline tidiers
30 #' @seealso [augment()], [stats::smooth.spline()],
31 #' [stats::predict.smooth.spline()]
32 augment.smooth.spline <- function(x, data = x$data, ...) {
33 check_ellipses("newdata", "augment", "smooth.spline", ...)
34
35 data <- as_tibble(data)
36 data$.fitted <- stats::fitted(x)
37 data$.resid <- stats::resid(x)
38 data
39 }
40
41
42 #' @templateVar class smooth.spine
43 #' @template title_desc_tidy
44 #'
45 #' @inherit augment.smooth.spline params examples
46 #'
47 #' @evalRd return_glance(
48 #' "spar",
49 #' "lambda",
50 #' "df",
51 #' "crit",
52 #' "pen.crit",
53 #' "cv.crit",
54 #' "nobs"
55 #' )
56 #'
57 #' @export
58 #' @family smoothing spline tidiers
59 #' @seealso [augment()], [stats::smooth.spline()]
60 #'
61 glance.smooth.spline <- function(x, ...) {
62 ret <- x[c("df", "lambda", "cv.crit", "pen.crit", "crit", "spar")]
63 ret <- as_tibble(ret)
64 ret$nobs <- stats::nobs(x)
65 ret
66 }