knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The summer before the second year of my master's degree, I identified two weaknesses in
my skills:
I didn't know enough about linear regression, and I had grown a bit too dependent on
tidyverse
over base R. The solution was obvious: write a package implementing
linear regression from the ground up,
using only base R. Instead of relying on lm
, I built a LinRegProblem
class to
store a linear model and associated data. I extended this with functions designed to make
it easier to solve textbook problems. I don't need a profiler to know this approach is
a lot less efficient than R's built-in functions, but implementing it was a useful exercise.
You can create LinRegProblem
objects like so:
library(RegLesson) X <- LinRegProblem(mtcars[, -1], mtcars$mpg)
This represents a regression of mpg
on all other mtcars
variables.
the do_problems
function evaluates expressions in an environment and prints the results. Required, omitted arguments are replaced with their values in the environment. Now we can check whether the model passes the overall $F$ test and get Working-Hoteling confidence bands for the observations.
do_problems( X, regression_relation(), Working_Hoteling(X_h = cbind(1, as.matrix(mtcars[, -1]))) )
This package contains functions for several diagnostic tests as well. Have fun!
You can install the development version of RegLesson from GitHub with:
# install.packages("devtools") devtools::install_github("ryan-heslin/RegLesson")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.