This application calculates ordinary least squares(OLS) estimates using the the following relation:
The design process of the application is as follows:
- Method 1: computes the OLS estimates directly by using the Normal Equation
$\beta = (X^{T}X)^{-1}X^{T}y$ . This method is referred to as the NE method hereafter. - Method 2: computes the OLS estimates by first rearranging the Normal Equation as
$(X^{T}X) \beta = X^{T}y$ and then solve the systems of linear equations using the LU factorization method. This method is referred to as the AxbLU method hereafter. - The application uses CBLAS and LAPACKE libraries for the linear algebra operations. This enables easy linkage of the application with more optimized and parallel versions of these libraries such as Intel Math Kernel Library.
- The application uses the CMake build system.
The application uses CBLAS and LAPACKE linear algebra libraries. The libraries can be installed using the following command:
$ sudo apt install libopenblas-dev
$ sudo apt-get install liblapacke-dev
After cloning the project use the following commands to build it.
$ cd ordinary-least-squares
$ mkdir build
$ cmake -S . -B build
$ cmake --build build
This builds the executable estOLS
in /build/src
folder.
The program accepts command line arguments which can be probed using the following command:
$ estOLS --help
The above command shows the following output:
Arguments are:
long short arg description
--Xmat -x 1 X matrix csv file (full path)
--yVec -y 1 y Vector csv file (full path)
--XmatSkip -s 1 number of header lines to skip in Xmat file (default 0)
--yVecSkip -k 1 number of header lines to skip in yVec file (default 0)
--method -m 1 select which method to use 0, 1 (default 1, see below for more info)
--writeFile -w 0 output result to file (default writes result to screen)
--benchmark -b 1 run benchmark for Xmat dimensions in file
--help -h 0 print this message
More info:
method 0: compute OLS estimates using direct evaluation of the normal equation
method 1: compute OLS estimates using using LU factorization to solve Ax=b
Note: options with arg=1 require values.
If
$ estOLS -x $path_to_file/XMAT.csv -y $path_to_file/yVEC.csv
Example of XMAT.csv and yVEC.csv are included in the test folder. To run the program with the files, you would need to specify the number of header lines in each file using the -s
and -k
options for the XMAT.csv and yVEC.csv files, respectively. To specify that the program writes the result to an output file (OLSest.csv) use the -w
flag. Below is the full command:
$ estOLS -x $path_to_file/XMAT.csv -y $path_to_file/yVEC.csv -s 1 -k 1 -w
The two methods for calculating the OLS estimates were benchmarked for matrix
The benchmark option for the program accepts a csv file that lists all the benchmark/benchmark.csv
. The file can be modified to run different
$ estOLS -b $path_to_file/benchmark.csv
Future work would look at implementing an iterative method such as the conjugate gradient method to solve the linear systems of equations