## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse  = TRUE,
  comment   = "#>",
  fig.width = 7,
  fig.height = 5
)
library(RougeLM)

## ----datasets, echo = FALSE---------------------------------------------------
knitr::kable(
  data.frame(
    Dataset   = c("`medical`", "`curiosity`", "`curiosity_quantum`",
                  "`mobility`", "`employment`", "`nutrition`", "`lifecalc`"),
    Chapter   = c("Strong Enough / The Shape of Cost",
                  "The Same Direction",
                  "The Threshold",
                  "The Crossing",
                  "The Second Chance",
                  "The Outlier",
                  "The Wall"),
    Method    = c("Simple regression, Box-Cox",
                  "One-way ANOVA",
                  "Piecewise regression, MED",
                  "Two-way ANOVA, interaction",
                  "ANCOVA, cream skimming",
                  "Nested ANOVA, fixed effects",
                  "Multiple regression, LASSO, Ridge"),
    n         = c(96, 1200, 1012, 412, 431, 1066, 5000)
  ),
  col.names = c("Dataset", "Chapter", "Method", "n")
)

## ----lasso-preview, eval = FALSE----------------------------------------------
# library(RougeLM)
# library(glmnet)
# 
# data(lifecalc)
# 
# X  <- model.matrix(SocialScore ~ ., data = lifecalc)[, -1]
# y  <- lifecalc$SocialScore
# cv <- cv.glmnet(X, y, alpha = 1, nfolds = 10)
# 
# coef(cv, s = "lambda.min")[
#   coef(cv, s = "lambda.min")[, 1] != 0, , drop = FALSE
# ]

## ----quickstart---------------------------------------------------------------
library(RougeLM)

# The dataset from the first chapter
data(medical)
head(medical)

# Correlation between LifeContract partner medical
cor(medical$partner_a, medical$partner_b)

# Simple regression
model <- lm(partner_b ~ partner_a, data = medical)
coef(model)

