SimpLin is an R package that performs simple linear regression using a high- performance C++ backend via RcppArmadillo. It calculates regression coefficients, standard errors, 95% confidence intervals, fitted values, and residuals.
This package was developed for CSU's STAT 600 HW1, but it can be used in any context requiring simple linear regression.
This package can be installed via GitHub using the line
devtools::install_github("jack-phippen/SimpLin")
The main function of this package is SimpLinR(x,y). This function expects:
- x numeric vector of length >2
- y numeric vector of same dimension as x
This function checks that x and y are the same dimension and of a dimension bigger than 2, and returns a list with the following outputs:
- coefficients
$\hat{\beta}_0$ and$\hat{\beta}_1$ - standard errors of the coefficients
- 95% confidence intervals for the coefficients
- fitted values
- residuals
library(SimpLin)
set.seed(600)
beta0 <- 1
beta1 <- -1
x <- rnorm(10)
epsilon <- rnorm(10)
y <- beta0 + beta1 * x + epsilon
# Run simple linear regression
slr_mod <- SimpLinR(x, y)
# Inspect results
slr_mod$coefficients # Intercept and slope
slr_mod$b0conf # 95% CI for intercept
slr_mod$b1conf # 95% CI for slope
slr_mod$fitted vals # Predicted values
slr_mod$residuals # Residuals