Estimating a linear regression
Linear regression is one of the basic models for predictive modeling. In this recipe, we show you how to implement a fully functional method that allows the estimation of such models. This recipe mainly concentrates on array manipulation, but also shows a typical example of more complex Julia code, combining several standard functionalities.
Getting ready
Make sure you have the DataFrames.jl
and CSV.jl
packages installed. If they are missing, add them using the following commands:
julia> using Pkg julia> Pkg.add("DataFrames") julia> Pkg.add("CSV")
Linear regression is a model following the
formula. It is known that if you define vector
as the observations of the explained variables and a matrix
of explanatory variables, then the least squares estimator of
is
.
We can see that, in this formula, both explained and explanatory variables must be numeric. In practice, a typical challenge is that raw explanatory variables are often nominal. In such cases...