vignettes/using_sprintr.R

## ---- include = FALSE---------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----setup--------------------------------------------------------------------
library(sprintr)

## -----------------------------------------------------------------------------
library(sprintr)
set.seed(123)
n <- 100
p <- 100
x <- matrix(data = rnorm(n * p), nrow = n, ncol = p)
y <- x[, 1] - 2 * x[, 2] + 3 * x[, 1] * x[, 3] - 4 * x[, 4] * x[, 5] + rnorm(100)

## -----------------------------------------------------------------------------
fit <- sprinter(x = x, y = y, square = FALSE)

## -----------------------------------------------------------------------------
fit$step2[[1]]

## -----------------------------------------------------------------------------
estimate <- fit$step3[[4]]$coef[, 30]

## -----------------------------------------------------------------------------
fit_cvstep1 <- sprinter(x = x, y = y, square = FALSE, cv_step1 = TRUE)

## -----------------------------------------------------------------------------
print(fit, which = 2)

## ----fig.width = 8, fig.height = 6--------------------------------------------
plot(fit, which = 3)

## -----------------------------------------------------------------------------
fit_cv <- cv.sprinter(x = x, y = y, square = FALSE)

## -----------------------------------------------------------------------------
fit_cv$compact

## -----------------------------------------------------------------------------
print(fit_cv)

## ----fig.height=6, fig.width = 8----------------------------------------------
plot(fit_cv)

## -----------------------------------------------------------------------------
newdata <- matrix(rnorm(20 * p), nrow = 20, ncol = p)
pred <- predict(fit, newdata = newdata)

## -----------------------------------------------------------------------------
pred_cv <- predict(fit_cv, newdata = newdata)
hugogogo/sprintr documentation built on Dec. 14, 2021, 6:07 p.m.