An R package for quickly performing linear smoothing by group (loop) while simultaneously computing prediction error (err). Or maybe an R package for quickly performing leave-one-out (loo) prediction error (perr).
Fast implementation in C++ using OpenMP and non-redundant matrix decomposition methods.
Method | Submethod | Multivariate | By Group? |
---|---|---|---|
Least-Squares Regression | Unweighted | ✔️ | ✔️ |
Weighted | ✔️ | ✔️ | |
Local Linear Regression | Uniform Kernel | ❌ | ✔️ |
Epanechnikov Kernel | ❌ | ❌ | |
Gaussian Kernel | ✔️ | ❌ |
OS | Version Tested | Build Passing | Out-of-Package OpenMP Support |
---|---|---|---|
Windows | Microsoft Windows 10.0 | ✔️ | ✔️ |
Mac | Mac OS X 10.15.7 (Catalina) | ✔️ | ❌ (see extra setup installations) |
Linux | Ubuntu 20.04 | ✔️ | ✔️ |
Installation is the same for Windows, Linux, and Mac. Just type the following in the R Console:
devtools::install_github("harveybarnhard/looperr")
However, since the default compiler of Mac OS does not support OpenMP, you will not benefit from the increased efficiency of parallelization unless you perform some extra setup steps. See the looperr wiki page for these extra installation steps.
The main function of this package is linsmooth()
which
performs a similar role to the standard lm()
function for
regressions. By default, linsmooth()
performs linear regression.
If your dataset is X
, your response vector is y
, and your
group identifier is g
. Here is a smörgåsbord of
commands you might want to run:
# Linear regression
linsmooth(X,y)
# Weighted linear regression
linsmooth(X,y, w=wts)
# Linear regression by group
linsmooth(X,y, g=bygroup)
# Weighted linear regression by group
linsmooth(X,y, w=wts, g=bygroup)
# Local linear regression with Gaussian kernel and optimal bandwidth
linsmooth(X, y, method="loclin")
# Local linear regression with Epanechnikov kernel and optimal bandwidth
linsmooth(X, y, method="loclin", kernel="epan")
# Local linear regression with Gaussian kernel and bandwidth H=1
linsmooth(X, y, method="loclin", H=1)
# Local linear regression with Uniform Kernel, bandwidth H=1, by group g
linsmooth(X, y, method="loclin", H=1, bygroup=g)
This package uses a bunch of linear algebra "tricks" to reduce the number of computations, leading to quicker runtimes and better numerical stability.