/* * Application: CronbachAnalysis * * USAGE: An application performing a basic Cronbach alpha analysis. * This application illustrates the class, Cronbach. * * WRITTEN BY: Dr Michael Thomas Flanagan * * DATE: December 2010 * * DOCUMENTATION: * See Michael Thomas Flanagan's Java library on-line web pages: * http://www.ee.ucl.ac.uk/~mflanaga/java/CronbachAnalysis.html * http://www.ee.ucl.ac.uk/~mflanaga/java/Cronbach.html * * Copyright (c) 2010 - 2014 * * 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. * * Public listing of the source codes on the internet is not permitted. * * Redistribution of the source codes or of the flanagan.jar file is not permitted. * * Redistribution in binary form of all or parts of these classes is not permitted. * * 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. * ***************************************************************************************/ import flanagan.math.Fmath; import flanagan.io.Db; import flanagan.analysis.Cronbach; import javax.swing.JOptionPane; public class CronbachAnalysis{ public static void main(String[] arg){ // Create an instance of Cronbach Cronbach cr = new Cronbach(); cr.letterToNumeral(); cr.numberOfDecimalPlacesAll(6); // Introductory message String message = "This program performs a Cronbach alpha analysis. It accepts the scores from a text file\n"; message += "and requests information about the scores through a series of dialogue boxes.\n\n"; message += "Please select the scores data file from the file select window and respond to each dialogue box\n"; message += "that appears on closing this message (by clicking on the OK button)"; JOptionPane.showMessageDialog(null, message, "Program CronbachAnalysis: Introduction", JOptionPane.INFORMATION_MESSAGE); // Select order of scores input String headerComment = "Is the scores data file organized as"; String[] comments = {"scores on each row corresponding to an individual\n", "scores on each row corresponding to an item\n"}; String[] boxTitles = {"row per individual", "row per item"}; int defaultBox = 1; int readOption = Db.optionBox(headerComment, comments, boxTitles, defaultBox); // Set missing response replacement headerComment = "Which Missing Response Replacement Method do you require?"; String[] comments3 = {"the missing response is replaced by zero\n", "the missing response is replaced by that person's mean\n", "the missing response is replaced by that item's mean (default option)\n", "the missing response is replaced by the overall mean\n", "the missing response is replaced by a user supplied score for each missing response. A value will be requested, \n via a dialog box, each time a missing response is encounterd as the data is processed\n"}; String[] boxTitles3 = {"zero", "person's mean", "item's mean", "overall mean", "user supplied value"}; defaultBox = 3; int replacementOption = Db.optionBox(headerComment, comments3, boxTitles3, defaultBox); cr.setMissingDataOption(replacementOption); // Set person deletion percentage Db.setTypeInfoOption(2); message = "Program CronbachAnalysis [See documentation: Box Four]:\n\nEnter the person deletion percentage (pdpc)\n"; message += " Example pdpc values:\n"; message += " pdpc = 0: a person is deleted after missing one response\n"; message += " pdpc = 50: a person is deleted after missing more than 50% of the response\n"; message += " pdpc = 100: a person is only deleted if they miss all responses\n"; double pdpc = Db.readDouble(message, 100.0); if(pdpc<0.0){ message = "Person deletion percentage, " + pdpc + ", must be greater than or equal to zero.\nIt has been reset to zero"; JOptionPane.showMessageDialog(null, message, "Program CronbachAnalysis: Warning", JOptionPane.WARNING_MESSAGE); pdpc = 0; } if(pdpc>100){ message = "Person deletion percentage, " + pdpc + ", must be less than or equal to 100.0\nIt has been reset to 100.0"; JOptionPane.showMessageDialog(null, message, "Program CronbachAnalysis: Warning", JOptionPane.WARNING_MESSAGE); pdpc = 100.0; } cr.setPersonDeletionPercentage(pdpc); // Set item deletion percentage message = "Program Cronbach [See documentation: Box Five]:\n\nEnter the item deletion percentage (idpc)\n"; message += " Example idpc values:\n"; message += " idpc = 0: an item is deleted after a single response to that item has been missed\n"; message += " idpc = 50: an item is deleted after more than 50% of the responses to that item are missed\n"; message += " idpc = 100: an item is only deleted if no person responds to that item\n"; double idpc = Db.readDouble(message, 100.0); if(idpc<0.0){ message = "Item deletion percentage, " + idpc + ", must be greater than or equal to zero.\nIt has been reset to zero"; JOptionPane.showMessageDialog(null, message, "Program CronbachAnalysis: Warning", JOptionPane.WARNING_MESSAGE); idpc = 0; } if(idpc>100){ message = "Item deletion percentage, " + idpc + ", must be less than or equal to 100.0\nIt has been reset to 100.0"; JOptionPane.showMessageDialog(null, message, "Program CronbachAnalysis: Warning", JOptionPane.WARNING_MESSAGE); idpc = 100.0; } cr.setItemDeletionPercentage(pdpc); if(readOption==1){ cr.readScoresAsRowPerPerson(); } else{ cr.readScoresAsRowPerItem(); } // Calculate Cronbach Alpha double alphaStandard = cr.standardizedAlpha(); double alphaRaw = cr.rawAlpha(); // Select type of output file headerComment = "Which Analysis Output File type do you require?"; String[] comments2 = {"Output as a text file (.txt)\n", "Output as an Excel readable file (.xls) .\n"}; String[] boxTitles2 = {"text File (.txt)", "Excel File (.xls)"}; defaultBox = 1; int fileOption = Db.optionBox(headerComment, comments2, boxTitles2, defaultBox); cr.setOutputFileType(fileOption); String extn = ".txt"; if(fileOption==2)extn = ".xls"; // Create output file name String inputName = cr.getInputFileName(); String outputName = null; String outputNameD = null; int pos = inputName.lastIndexOf('.'); if(pos==-1){ outputNameD = inputName+"Analysis"+extn; } else{ outputNameD = inputName.substring(0,pos)+ "Analysis" + extn; } boolean checkExt = false; outputName = Db.readLine("Program CronbachAnalysis:\n\nEnter the Analysis Output File name\n", outputNameD); if(!outputName.equals(outputNameD)){ String outputNameHold = outputName; pos = outputName.lastIndexOf('.'); if(pos==-1){ outputName += extn; checkExt = true; } else{ if(fileOption==1){ if(!(outputName.substring(pos)).equals(".txt")){ outputName = outputName.substring(0,pos) + extn; checkExt = true; } } else{ if(!(outputName.substring(pos)).equals(".xls")){ outputName = outputName.substring(0,pos) + extn; checkExt = true; } } } if(checkExt){ if(fileOption==1){ message = "You chose a text file (.txt) as the output file type\n"; } else{ message = "You chose an Excel readable file (.xls) as the output file type\n"; } message += "consequently your file name, '" + outputNameHold + "', has been\n"; message += "changed to '" + outputName + "'\n"; JOptionPane.showMessageDialog(null, message, "Program Cronbach: Output File", JOptionPane.WARNING_MESSAGE); } } // Perform analysis cr.analysis(outputName); message = "Input File Name = '" + inputName + "'\n\n"; message += "Cronbach's alpha (raw data) = " + Fmath.truncate(alphaRaw, 4) + "\n"; message += "Cronbach's alpha (standardized data) = " + Fmath.truncate(alphaStandard, 4) + "\n\n"; message += "The analysis has been written to the output file '" + outputName + "'\n\n"; message += "The least consistent item is " + cr.getLeastConsistentItemName() + "\n"; message += "A new data input file, with this item deleted, has been written to '" + cr.getDeletionFileName() + "'\n\n"; JOptionPane.showMessageDialog(null, message, "Program Cronbach: Results", JOptionPane.INFORMATION_MESSAGE); // Scatter plots String question = "Do you wish to display scatter plots of the standardized response scores?\n\n"; question += "If you answer YES the program must then be terminated later by clicking on the\nclose icon (white cross on red background in the top right hand corner) on any of the plots\n"; boolean answer = Db.noYes(question); if(answer){ int nItems = cr.usedNumberOfItems(); for(int i=1; i<=nItems; i++){ cr.standardizedItemMeansPlot(i); } for(int i=1; i<=nItems; i++){ for(int j=i+1; j<=nItems; j++){ cr.standardizedItemItemPlot(i, j); } } } } }