/*
*   CLASS:      Cronbach
*
*   USAGE:      Cronbach raw data alpha reliability
*               Cronbach standardized data alpha reliability
*               Correlation between items
*               Deletion of items
*
*   This is a subclass of the superclass Scores
*
*
*   WRITTEN BY: Dr Michael Thomas Flanagan
*
*   DATE:       July and Agust 2008
*   AMENDED:    22 August 2008, 29 August 2008, 1-8 October 2008, 1-4 November 2010, 12 December 2011
*
*   DOCUMENTATION:
*   See Michael Thomas Flanagan's Java library on-line web pages:
*   http://www.ee.ucl.ac.uk/~mflanaga/java/
*   http://www.ee.ucl.ac.uk/~mflanaga/java/Cronbach.html
*
*   Copyright (c) 2008 - 2011 Michael Thomas Flanagan
*
*   PERMISSION TO COPY:
*
* Permission to use, copy and modify this software and its documentation for NON-COMMERCIAL purposes is granted, without fee,
* provided that an acknowledgement to the author, Dr Michael Thomas Flanagan at www.ee.ucl.ac.uk/~mflanaga, appears in all copies
* and associated documentation or publications.
*
* Redistributions of the source code of this source code, or parts of the source codes, must retain the above copyright notice, this list of conditions
* and the following disclaimer and requires written permission from the Michael Thomas Flanagan:
*
* Redistribution in binary form of all or parts of this class must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution and requires written permission from the Michael Thomas Flanagan:
*
* Dr Michael Thomas Flanagan makes no representations about the suitability or fitness of the software for any or for a particular purpose.
* Dr Michael Thomas Flanagan shall not be liable for any damages suffered as a result of using, modifying or distributing this software
* or its derivatives.
*
***************************************************************************************/


package flanagan.analysis;

import java.util.*;
import java.text.*;

import flanagan.math.Fmath;
import flanagan.math.ArrayMaths;
import flanagan.io.Db;
import flanagan.io.FileOutput;
import flanagan.analysis.Scores;
import flanagan.analysis.Stat;
import flanagan.plot.PlotGraph;
import flanagan.plot.Plot;


public class Cronbach extends Scores{

    private double rawAlpha = Double.NaN;                               // Cronbach raw data alpha reliability coefficient
    private boolean rawAlphaCalculated = false;                         // = true when raw data alpha reliability coefficient calculated
    private double standardizedAlpha = Double.NaN;                      // Cronbach standardized data alpha reliability coefficient
    private boolean standardizedAlphaCalculated = false;                // = true when standardized alpha reliability coefficient calculated

    private int deletedItemIndex = -1;                                  // the index of the least consistent item
    private String deletedFilename = null;                              // File name of new data file with least consistent item deleted


    // CONSTRUCTOR
    public Cronbach(){
        super();
    }

    // CRONBACH RAW DATA ALPHA
    public double rawAlpha(){

        if(!this.rawAlphaCalculated){

            if(this.nItems==1){
                System.out.println("Method rawAlpha: only one item - alpha cannot be calculated - NaN returned");
                this.rawAlpha = Double.NaN;
            }
            else{

                // Check that data is preprocessed
                if(!this.dataPreprocessed)this.preprocessData();

                // (Sum of scores1) squared
                double rawAllResponsesTotalAllSquared = this.rawAllResponsesTotal*this.rawAllResponsesTotal;

                // Sum of (scores1 squared)
                double sumOfEachScoreSquared = 0.0;
                for(int i=0;ifieldItemName)fieldItemName = this.itemNames[i].length();
        int fieldItemNumber = fieldItemName;
        if(len>fieldItemNumber)fieldItemNumber = len;
        fieldItemName++;
        fieldItemNumber++;

        fout.println("CORRELATION COEFFICIENTS");
        fout.println("Correlation coefficients between items  -  raw data");
        fout.print("    ", fieldItemName);

        for(int i=0; i<=this.nItems; i++)fout.print(this.itemNames[i], fieldItemNumber);
        fout.println();
        for(int i=0; i<=this.nItems; i++){
            fout.print(this.itemNames[i], fieldItemName);
            for(int j=0; j<=this.nItems; j++)fout.print(Fmath.truncate(this.rawCorrelationCoefficients[i][j], this.trunc), fieldItemNumber);
            fout.println();
        }
        fout.println();

        fout.print("Average inter-item correlation coefficient (excluding total) ", 80);
        fout.println(Fmath.truncate(this.rawMeanRhoWithoutTotals, this.trunc));
        fout.print("Standard deviation of the inter-item correlation coefficient (excluding total) ", 80);
        fout.println(Fmath.truncate(this.rawStandardDeviationRhoWithoutTotals, this.trunc));
        fout.print("Average inter-item correlation coefficient (including total) ", 80);
        fout.println(Fmath.truncate(this.rawMeanRhoWithTotals, this.trunc));
        fout.print("Standard deviation of the inter-item correlation coefficient (including total) ", 80);
        fout.println(Fmath.truncate(this.rawStandardDeviationRhoWithTotals, this.trunc));

        fout.println();


        fout.println("Correlation coefficients between items  -  standardized data");
        fout.print("    ", fieldItemName);
        for(int i=0; i<=this.nItems; i++)fout.print(this.itemNames[i], fieldItemNumber);
        fout.println();
        for(int i=0; i<=this.nItems; i++){
            fout.print(this.itemNames[i], fieldItemName);
            for(int j=0; j<=this.nItems; j++)fout.print(Fmath.truncate(this.standardizedCorrelationCoefficients[i][j], this.trunc), fieldItemNumber);
            fout.println();
        }
        fout.println();

        fout.print("Average inter-item correlation coefficient (excluding total) ", 80);
        fout.println(Fmath.truncate(this.standardizedMeanRhoWithoutTotals, this.trunc));
        fout.print("Standard deviation of the inter-item correlation coefficient (excluding total) ", 80);
        fout.println(Fmath.truncate(this.standardizedStandardDeviationRhoWithoutTotals, this.trunc));
        fout.print("Average inter-item correlation coefficient (including total) ", 80);
        fout.println(Fmath.truncate(this.standardizedMeanRhoWithTotals, this.trunc));
        fout.print("Standard deviation of the inter-item correlation coefficient (including total) ", 80);
        fout.println(Fmath.truncate(this.standardizedStandardDeviationRhoWithTotals, this.trunc));
        fout.println();

        // item statistics
        if(fieldItemNumber<12)fieldItemNumber = 12;

        fout.println("ITEMS: MEANS, STANDARD DEVIATIONS, SKEWNESS AND KURTOSIS");
        fout.println("Raw data");
        fout.print("item ", fieldItemName);
        fout.print("mean", fieldItemNumber);
        fout.print("standard", fieldItemNumber);
        fout.print("moment", fieldItemNumber);
        fout.print("median", fieldItemNumber);
        fout.print("quartile", fieldItemNumber);
        fout.print("kurtosis", fieldItemNumber);
        fout.println("dichotomous");

        fout.print("    ", fieldItemName);
        fout.print("    ", fieldItemNumber);
        fout.print("deviation", fieldItemNumber);
        fout.print("skewness", fieldItemNumber);
        fout.print("skewness", fieldItemNumber);
        fout.print("skewness", fieldItemNumber);
        fout.print("excess  ", fieldItemNumber);
        fout.println("percentage");

        for(int i=0; ifieldDitem)fieldDitem=fieldItemName;

        fout.print("   ", fieldDitem);
        fout.print("Raw data", fieldItemNumber);
        fout.print("   ", fieldItemNumber);
        fout.print("   ", fieldItemNumber);
        fout.print("   ", fieldItemNumber);
        fout.println("Standardized data");

        fout.print("Deleted item", fieldDitem);
        fout.print("Alpha", fieldItemNumber);
        fout.print("Correlation", fieldItemNumber);
        fout.print("Average", fieldItemNumber);
        fout.print("Average", fieldItemNumber);

        fout.print("Alpha", fieldItemNumber);
        fout.print("Correlation", fieldItemNumber);
        fout.print("Average", fieldItemNumber);
        fout.println("Average");


        fout.print("       ", fieldDitem);
        fout.print("       ", fieldItemNumber);
        fout.print("coefficient", fieldItemNumber);
        fout.print("inter-item", fieldItemNumber);
        fout.print("inter-item", fieldItemNumber);

        fout.print("      ", fieldItemNumber);
        fout.print("coefficient", fieldItemNumber);
        fout.print("inter-item", fieldItemNumber);
        fout.println("inter-item");


        fout.print("       ", fieldDitem);
        fout.print("       ", fieldItemNumber);
        fout.print("with total", fieldItemNumber);
        fout.print("correlation", fieldItemNumber);
        fout.print("correlation", fieldItemNumber);

        fout.print("      ", fieldItemNumber);
        fout.print("with total", fieldItemNumber);
        fout.print("correlation", fieldItemNumber);
        fout.println("correlation");


        fout.print("       ", fieldDitem);
        fout.print("       ", fieldItemNumber);
        fout.print("       ", fieldItemNumber);
        fout.print("coefficient", fieldItemNumber);
        fout.print("coefficient", fieldItemNumber);

        fout.print("        ", fieldItemNumber);
        fout.print("        ", fieldItemNumber);
        fout.print("coefficient", fieldItemNumber);
        fout.println("coefficient");


        fout.print("       ", fieldDitem);
        fout.print("       ", fieldItemNumber);
        fout.print("       ", fieldItemNumber);
        fout.print("without totals", fieldItemNumber);
        fout.print("with totals", fieldItemNumber);

        fout.print("        ", fieldItemNumber);
        fout.print("        ", fieldItemNumber);
        fout.print("without totals", fieldItemNumber);
        fout.println("with totals");

        double[] newRawAlpha = new double[this.nItems];
        double[] newStandardizedAlpha = new double[this.nItems];
        double[] newRawRho = new double[this.nItems];
        double[] newStandardizedRho = new double[this.nItems];
        for(int i=0; ifieldScore)fieldScore = sl;
            }
        }
        fieldScore++;
        if(fieldScore 

Ads help maintain this website.