11 #define WANT_STREAM // include.h will get stream fns 12 #define WANT_MATH // include.h will get math fns 20 using namespace NEWMAT;
29 cout <<
"\n\nTest 1 - traditional, bad\n";
69 cout <<
"\nEstimates and their standard errors\n\n";
73 for (
int i=1; i<=npred1; i++) SE(i) = sqrt(V(i)*ResVar);
76 cout << setw(11) << setprecision(5) << (A | SE) << endl;
78 cout <<
"\nObservations, fitted value, residual value, hat value\n";
81 cout << setw(9) << setprecision(3) <<
88 cout <<
"\n\nTest 2 - traditional, OK\n";
116 Real m =
sum(Y) / nobs; YC = Y - Ones *
m;
129 Real a = m - (M * A).as_scalar();
135 Real v = 1.0/nobs + (M * ISSQ * M.t()).as_scalar();
139 int npred1 = npred+1;
149 cout <<
"\nEstimates and their standard errors\n\n";
150 cout.setf(ios::fixed, ios::floatfield);
151 cout << setw(11) << setprecision(5) << a <<
" ";
152 cout << setw(11) << setprecision(5) << sqrt(v*ResVar) << endl;
155 for (
int i=1; i<=npred; i++) SE(i) = sqrt(V(i)*ResVar);
158 cout << setw(11) << setprecision(5) << (A | SE) << endl;
159 cout <<
"\nObservations, fitted value, residual value, hat value\n";
160 cout << setw(9) << setprecision(3) <<
161 (X | Y | Fitted | Residual | Hat.
as_column());
167 cout <<
"\n\nTest 3 - Cholesky\n";
180 Real m =
sum(Y) / nobs; YC = Y - Ones *
m;
190 Real a = m - (M * A).AsScalar();
198 int npred1 = npred+1;
208 cout <<
"\nEstimates and their standard errors\n\n";
209 cout.setf(ios::fixed, ios::floatfield);
210 cout << setw(11) << setprecision(5) << a <<
" ";
211 cout << setw(11) << setprecision(5) << sqrt(v*ResVar) << endl;
213 for (
int i=1; i<=npred; i++) SE(i) = sqrt(V(i)*ResVar);
214 cout << setw(11) << setprecision(5) << (A | SE) << endl;
215 cout <<
"\nObservations, fitted value, residual value, hat value\n";
216 cout << setw(9) << setprecision(3) <<
217 (X | Y | Fitted | Residual | Hat.
as_column());
223 cout <<
"\n\nTest 4 - QR triangularisation\n";
228 int npred1 = npred+1;
237 QRZ(X1, U);
QRZ(X1, Y1, M);
249 cout <<
"\nEstimates and their standard errors\n\n";
251 for (
int i=1; i<=npred1; i++) SE(i) = sqrt(D(i)*ResVar);
252 cout << setw(11) << setprecision(5) << (A | SE) << endl;
253 cout <<
"\nObservations, fitted value, residual value, hat value\n";
254 cout << setw(9) << setprecision(3) <<
261 cout <<
"\n\nTest 5 - singular value\n";
266 int npred1 = npred+1;
280 D << V * (D * D).i() * V.
t();
286 cout <<
"\nEstimates and their standard errors\n\n";
288 for (
int i=1; i<=npred1; i++) SE(i) = sqrt(D(i)*ResVar);
289 cout << setw(11) << setprecision(5) << (A | SE) << endl;
290 cout <<
"\nObservations, fitted value, residual value, hat value\n";
291 cout << setw(9) << setprecision(3) <<
298 cout <<
"\nDemonstration of Matrix package\n";
299 cout <<
"\nPrint a real number (may help lost memory test): " << 3.14159265 <<
"\n";
307 Real y[] = { 8.3, 5.5, 8.0, 8.5, 5.7, 4.4, 6.3, 7.9, 9.1 };
308 Real x1[] = { 2.4, 1.8, 2.4, 3.0, 2.0, 1.2, 2.0, 2.7, 3.6 };
309 Real x2[] = { 1.7, 0.9, 1.6, 1.9, 0.5, 0.6, 1.1, 1.0, 0.5 };
323 test1(y, x1, x2, nobs, npred);
324 test2(y, x1, x2, nobs, npred);
325 test3(y, x1, x2, nobs, npred);
326 test4(y, x1, x2, nobs, npred);
327 test5(y, x1, x2, nobs, npred);
336 cout <<
"\n\nThe following test does not work with all compilers - see documentation\n";
337 cout <<
"Checking for lost memory: " 338 << (
unsigned long)s1 <<
" " << (
unsigned long)s2 <<
" ";
339 if (s1 != s2) cout <<
" - see section 2.8\n";
else cout <<
" - ok\n";
void test3(Real *y, Real *x1, Real *x2, int nobs, int npred)
GetSubMatrix columns(int, int) const
void test1(Real *y, Real *x1, Real *x2, int nobs, int npred)
void test4(Real *y, Real *x1, Real *x2, int nobs, int npred)
GetSubMatrix column(int) const
ReturnMatrix sum_columns() const
void test2(Real *y, Real *x1, Real *x2, int nobs, int npred)
TransposedMatrix t() const
void SVD(const Matrix &, DiagonalMatrix &, Matrix &, Matrix &, bool=true, bool=true)
Real sum_square(const BaseMatrix &B)
The usual rectangular matrix.
ReturnMatrix Cholesky(const SymmetricMatrix &S)
FloatVector FloatVector * a
void QRZ(Matrix &X, UpperTriangularMatrix &U)
static const char * what()
Real sum(const BaseMatrix &B)
ColedMatrix AsColumn() const
ColedMatrix as_column() const
void test5(Real *y, Real *x1, Real *x2, int nobs, int npred)