PaceMatrix Y = new
PaceMatrix( X.times( new PaceMatrix(beta) ).
plusEquals( randomNormal(n,1).times(sd) ) );
IntVector pvt = (IntVector) IntVector.seq(0, k1+k2);
/*System.out.println( "The OLS estimate (by jama.Matrix.solve()) is:\n\n" +
(new PaceMatrix(X.solve(Y))).getColumn(0) );*/
X.lsqrSelection( Y, pvt, 1 );
X.positiveDiagonal( Y, pvt );
PaceMatrix sol = (PaceMatrix) Y.clone();
X.rsolve( sol, pvt, pvt.size() );
DoubleVector betaHat = sol.getColumn(0).unpivoting( pvt, k );
System.out.println( "\nThe OLS estimate (through lsqr()) is: \n\n" +
betaHat );
System.out.println( "\nQuadratic loss of the OLS estimate (||X b - X bHat||^2) = " +
( new PaceMatrix( X.times( new
PaceMatrix(beta.minus(betaHat)) )))
.getColumn(0).sum2() );
System.out.println("=============================================" +
"==============");
System.out.println(" *** Pace estimation *** \n");
DoubleVector r = Y.getColumn( pvt.size(), n-1, 0);
double sde = Math.sqrt(r.sum2() / r.size());
System.out.println( "Estimated standard deviation = " + sde );
DoubleVector aHat = Y.getColumn( 0, pvt.size()-1, 0).times( 1./sde );
System.out.println("\naHat = \n" + aHat );
System.out.println("\n========= Based on chi-square mixture ============");
ChisqMixture d2 = new ChisqMixture();
int method = MixtureDistribution.NNMMethod;
DoubleVector AHat = aHat.square();
d2.fit( AHat, method );
System.out.println( "\nEstimated mixing distribution is:\n" + d2 );
DoubleVector ATilde = d2.pace2( AHat );
DoubleVector aTilde = ATilde.sqrt().times(aHat.sign());
PaceMatrix YTilde = new
PaceMatrix((new PaceMatrix(aTilde)).times( sde ));
X.rsolve( YTilde, pvt, pvt.size() );
DoubleVector betaTilde =
YTilde.getColumn(0).unpivoting( pvt, k );
System.out.println( "\nThe pace2 estimate of coefficients = \n" +
betaTilde );
System.out.println( "Quadratic loss = " +
( new PaceMatrix( X.times( new
PaceMatrix(beta.minus(betaTilde)) )))
.getColumn(0).sum2() );
ATilde = d2.pace4( AHat );
aTilde = ATilde.sqrt().times(aHat.sign());
YTilde = new PaceMatrix((new PaceMatrix(aTilde)).times( sde ));
X.rsolve( YTilde, pvt, pvt.size() );
betaTilde = YTilde.getColumn(0).unpivoting( pvt, k );
System.out.println( "\nThe pace4 estimate of coefficients = \n" +
betaTilde );
System.out.println( "Quadratic loss = " +
( new PaceMatrix( X.times( new
PaceMatrix(beta.minus(betaTilde)) )))
.getColumn(0).sum2() );
ATilde = d2.pace6( AHat );
aTilde = ATilde.sqrt().times(aHat.sign());
YTilde = new PaceMatrix((new PaceMatrix(aTilde)).times( sde ));
X.rsolve( YTilde, pvt, pvt.size() );
betaTilde = YTilde.getColumn(0).unpivoting( pvt, k );
System.out.println( "\nThe pace6 estimate of coefficients = \n" +
betaTilde );
System.out.println( "Quadratic loss = " +
( new PaceMatrix( X.times( new
PaceMatrix(beta.minus(betaTilde)) )))
.getColumn(0).sum2() );
System.out.println("\n========= Based on normal mixture ============");
NormalMixture d = new NormalMixture();
d.fit( aHat, method );
System.out.println( "\nEstimated mixing distribution is:\n" + d );
aTilde = d.nestedEstimate( aHat );
YTilde = new PaceMatrix((new PaceMatrix(aTilde)).times( sde ));
X.rsolve( YTilde, pvt, pvt.size() );
betaTilde = YTilde.getColumn(0).unpivoting( pvt, k );
System.out.println( "The nested estimate of coefficients = \n" +
betaTilde );
System.out.println( "Quadratic loss = " +
( new PaceMatrix( X.times( new
PaceMatrix(beta.minus(betaTilde)) )))
.getColumn(0).sum2() );
aTilde = d.subsetEstimate( aHat );
YTilde = new PaceMatrix((new PaceMatrix(aTilde)).times( sde ));
X.rsolve( YTilde, pvt, pvt.size() );
betaTilde =
YTilde.getColumn(0).unpivoting( pvt, k );
System.out.println( "\nThe subset estimate of coefficients = \n" +
betaTilde );
System.out.println( "Quadratic loss = " +
( new PaceMatrix( X.times( new
PaceMatrix(beta.minus(betaTilde)) )))
.getColumn(0).sum2() );
aTilde = d.empiricalBayesEstimate( aHat );
YTilde = new PaceMatrix((new PaceMatrix(aTilde)).times( sde ));
X.rsolve( YTilde, pvt, pvt.size() );
betaTilde = YTilde.getColumn(0).unpivoting( pvt, k );
System.out.println( "\nThe empirical Bayes estimate of coefficients = \n"+
betaTilde );
System.out.println( "Quadratic loss = " +