// initialize arrays and analyse original data
if(!this.initializationDone)this.initialize();
// Shift data to ensure all values are greater than zero
this.lambdaTwo = 0.1*this.standardizedOriginalRange - this.standardizedOriginalMinimum;
ArrayMaths st1 = this.sod.plus(this.lambdaTwo);
this.shiftedStandardizedOriginalData = st1.getArray_as_double();
// Create an instance of the BoxCoxFunction for Maximization
BoxCoxFunction bcf = new BoxCoxFunction();
bcf.shiftedData = this.shiftedStandardizedOriginalData;
bcf.nData = this.nData;
bcf.yTransform = new double[this.nData];
bcf.gaussianOrderMedians = this.gaussianOrderMedians;
// Create an instance of Maximization
Maximization max = new Maximization();
// Initial estimate of lambdaOne
double[] start = {1.0};
// Initial step size in maximization search
double[] step = {0.3};
// Tolerance for maximization search termination
double maxzTol = 1e-9;
// Maximiztaion of the Gaussian probabilty plot correlation coefficient varying lambdaOne
max.nelderMead(bcf, start, step, maxzTol);
// coeff[0] = value of lambdaOne for a maximum Gaussian probabilty plot correlation coefficient
double[] coeff = max.getParamValues();
double lambda1 = coeff[0];
//maximum Gaussian probabilty plot correlation coefficient
double sampleR1 = max.getMaximum();
// Repeat maximization starting equidistant from the final value of lambdaOne on the opposite side from the starting estimate
start[0] = lambda1 - (start[0] - lambda1);
max.nelderMead(bcf, start, step, maxzTol);
coeff = max.getParamValues();
this.lambdaOne = coeff[0];
this.transformedSampleR = max.getMaximum();
// Choose solution with the largest Gaussian probabilty plot correlation coefficient
if(sampleR1>this.transformedSampleR){
this.transformedSampleR = sampleR1;
this.lambdaOne = lambda1;
}
// Store transformed data
this.transformedData = new double[this.nData];
if(this.lambdaOne==0.0){
for(int i=0; i<this.nData; i++){
this.transformedData[i] = Math.exp(this.shiftedStandardizedOriginalData[i]);
}
}
else{
for(int i=0; i<this.nData; i++){
this.transformedData[i] = (Math.pow(this.shiftedStandardizedOriginalData[i], this.lambdaOne) - 1.0)/this.lambdaOne;
}
}
// Standardize transformed data
this.standardizedTransformedData = (new Stat(this.transformedData)).standardize();
// Calculate standardized transformed data statistics
this.standardizedTransformedDataStatistics(this.standardizedTransformedData);
// Obtain the intercept and gradient of the Gaussian probabilty plot
ArrayMaths st4 = new ArrayMaths(this.standardizedTransformedData);
st4 = st4.sort();
double[] ordered = st4.array();
Regression reg = new Regression(this.gaussianOrderMedians, ordered);
reg.linear();
coeff = reg.getBestEstimates();
this.transformedIntercept = coeff[0];
this.transformedGradient = coeff[1];