A single C++ source-file implementing the following function:
float Multivariate_Regression(float x, float y, int n, int x_count, float& a, float& b, float& t_stat)
Function performs standard least-squares multivariate regression of y against x.
Return value is R2 of regression.
x_count is number of x variables.
n is number of data points for each x and y variable.
a is the intercept, passed by reference.
b are the regression betas, a pointer to a pre-allocated array of size x_count.
t_stat are the T-statistics of each beta, a pointer to a pre-allocated array of size x_count.
Performance must be polynomial-time -- O(n^2) unless otherwise approved.
Source code must be comprehensible to a typical C++ developer.
Please compute standard error as well.
I have agreed to accept the function if it compiles under gcc 2.96 (I'm using Redhat 7.2). I.e., if you cannot test it under VC++ that is not necessary.
Just to clarify the spec: The function must fill in the variables std_error, a, b, and t_stat in addition to returning r-squared.
Here is a test data set:
y x1 x2 x3
1 2 4 1
2 2 2 3
3 2 3 1
4 1 2 4
5 1 2 5
R2 = .82
Standard Error = 1.34
a = 11.1
b1 = [url removed, login to view]
b2 = [url removed, login to view]
b3 = [url removed, login to view]
t1 = [url removed, login to view]
t2 = [url removed, login to view]
t3 = [url removed, login to view]
1) Source file as specified.
2) Unrestricted ownership and use rights of code.
Must compile under MS Visual C++ and Linux G++.