SimpleLinReg is a Julia package that implements the simple linear regression with only one dependent and one independent variable. The possible use cases for this package might be to demonstrate the efficiency of simple linear regression in two variables during the undergrad studies. Being simple and intuitive, it can handle enough data, but in only two variables.
using Pkg
Pkg.add(url = "https://github.com/itsdebartha/SimpleLinReg.jl.git")
using Distributions, Random, StableRNGs
rng = StableRNG(1)
ϵ = rand(rng,Normal(),1000)
x = rand(rng,Uniform(),1000)
y = 2 .+5x .+ϵ
linreg(x,y)
linreg(x,y;intercept = false)
SIMPLE LINEAR REGRESSION IN TWO VARIABLES:
==========================================
Slope: 5.04638
Intercept: 1.98306
SIMPLE LINEAR REGRESSION IN TWO VARIABLES:
==========================================
Slope: 5.04638
Intercept: 0.0
@test linreg(x,y,intrcept = true).slope ≈ 5 atol = 0.2
Test passed
@test linreg(x,y,intrcept = false).intrcpt == 0
Test passed
This package implements the simple linear regression using the solutions by solving the normal equations. The assumed model is:
where the variable
The estimates of the slope and the intercepts, thus obtained, are:
- Ability to handle missing values
- Significance tests for estimated parameters