* with this error structure. Then verify that GLS estimated coefficients,
* on average, perform better than OLS.
*/
@Test
public void testGLSEfficiency() throws Exception {
RandomGenerator rg = new JDKRandomGenerator();
rg.setSeed(200); // Seed has been selected to generate non-trivial covariance
// Assume model has 16 observations (will use Longley data). Start by generating
// non-constant variances for the 16 error terms.
final int nObs = 16;
double[] sigma = new double[nObs];
for (int i = 0; i < nObs; i++) {
sigma[i] = 10 * rg.nextDouble();
}
// Now generate 1000 error vectors to use to estimate the covariance matrix
// Columns are draws on N(0, sigma[col])
final int numSeeds = 1000;
RealMatrix errorSeeds = MatrixUtils.createRealMatrix(numSeeds, nObs);
for (int i = 0; i < numSeeds; i++) {
for (int j = 0; j < nObs; j++) {
errorSeeds.setEntry(i, j, rg.nextGaussian() * sigma[j]);
}
}
// Get covariance matrix for columns
RealMatrix cov = (new Covariance(errorSeeds)).getCovarianceMatrix();