The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.
library(aspline)
library(ggplot2)
library(dplyr)
library(tidyr)
library(mgcv)
library(splines2)
data(helmet)
<- helmet$x
x <- helmet$y y
<- 40
k <- seq(min(x), max(x), length = k + 2)[-c(1, k + 2)]
knots <- 10 ^ seq(-4, 4, 0.25)
pen <- seq(min(x), max(x), length = 1000)
x_seq <- aspline::aspline(x, y, knots, pen)
aridge <- lm(y ~ splines2::bSpline(x, knots = aridge$knots_sel[[which.min(aridge$ebic)]]))
a_fit <- splines2::bSpline(x_seq, knots = aridge$knots_sel[[which.min(aridge$ebic)]], intercept = TRUE)
X_seq <- (X_seq %*% diag(coef(a_fit))) %>%
a_basis as.data.frame() %>%
::mutate(x = x_seq) %>%
dplyr::pivot_longer(cols = paste0("V", 1:9), names_to = "spline_n", values_to = "y") %>%
tidyr::filter(y != 0)
dplyr<- dplyr::data_frame(x = x_seq, pred = predict(a_fit, data.frame(x = x_seq)))
a_predict #> Warning: `data_frame()` was deprecated in tibble 1.1.0.
#> Please use `tibble()` instead.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.
::ggplot() +
ggplot2::geom_point(data = helmet, aes(x, y), shape = 1) +
ggplot2::geom_line(data = a_predict, aes(x, pred), size = 0.5) +
ggplot2::geom_line(data = a_basis, aes(x, y, group = spline_n), linetype = 1, size = 0.1) +
ggplot2::theme(legend.position = "none") +
ggplot2::ylab("") +
ggplot2::xlab("") ggplot2
<- mgcv::gam(y ~ s(x, bs = "ps", k = length(knots) + 3 + 1, m = c(3, 2)))
p_fit <- splines2::bSpline(x_seq, knots = knots, intercept = TRUE)
X <- (X %*% diag(coef(p_fit))) %>%
p_basis as.data.frame() %>%
::mutate(x = x_seq) %>%
dplyr::pivot_longer(cols = paste0("V", 1:9), names_to = "spline_n", values_to = "y") %>%
tidyr::as_tibble() %>%
dplyr::filter(y != 0)
dplyr<- dplyr::data_frame(x = x_seq, pred = predict(p_fit, data.frame(x = x_seq)))
p_predict ::ggplot() +
ggplot2::geom_point(data = helmet, aes(x, y), shape = 1) +
ggplot2::geom_line(data = p_predict, aes(x, pred), size = 0.5) +
ggplot2::geom_line(data = p_basis, aes(x, y, group = spline_n), linetype = 1, size = 0.1) +
ggplot2::theme(legend.position = "none") +
ggplot2::ylab("") + ggplot2::xlab("") ggplot2
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.