//Title: Experience Sensation and Perception: Media Classes //Name: Normal.java //Version: 0.1 //Copyright: Copyright (c) 2001 //Author: John Krantz //Company: Hanover College //Description: This is a package that deals with the normal distribution package model.compute; public class Normal { // the proportion of the curve in the tail starting from the [0] is the // middle of the distribution. the values are porportion of the curve not // percentage. // index = z*100 from mean // z's range from 0 to 3.25 private final double NORMALTAIL [] = {0.5000,.4960,.4920,.4880,.4840, 0.4801,.4761,.4721,.4681,.4641, 0.4602,.4562,.4522,.4483,.4443, 0.4404,.4364,.4325,.4286,.4247, 0.4207,.4168,.4129,.4090,.4052, 0.4013,.3974,.3936,.3897,.3859, 0.3821,.3783,.3745,.3707,.3669, 0.3632,.3594,.3557,.3520,.3483, 0.3446,.3409,.3372,.3336,.3300, 0.3264,.3228,.3192,.3156,.3121, 0.3085,.3050,.3015,.2981,.2946, 0.2912,.2877,.2843,.2810,.2776, 0.2743,.2709,.2676,.2643,.2611, 0.2578,.2546,.2514,.2483,.2451, 0.2420,.2389,.2358,.2327,.2296, 0.2266,.2236,.2206,.2177,.2148, 0.2119,.2090,.2061,.2033,.2005, 0.1977,.1949,.1922,.1894,.1867, 0.1841,.1814,.1788,.1762,.1736, 0.1711,.1685,.1660,.1635,.1611, 0.1587,.1562,.1539,.1515,.1492, 0.1469,.1446,.1423,.1401,.1379, 0.1357,.1335,.1314,.1292,.1271, 0.1251,.1230,.1210,.1190,.1170, 0.1151,.1131,.1112,.1093,.1075, 0.1056,.1038,.1020,.1003,.0985, 0.0968,.0951,.0934,.0918,.0901, 0.0885,.0869,.0853,.0838,.0823, 0.0808,.0793,.0778,.0764,.0749, 0.0735,.0721,.0708,.0694,.0681, 0.0668,.0655,.0643,.0630,.0618, 0.0606,.0594,.0582,.0571,.0559, 0.0548,.0537,.0526,.0516,.0505, 0.0495,.0485,.0475,.0465,.0455, 0.0446,.0436,.0427,.0418,.0409, 0.0401,.0392,.0384,.0375,.0367, 0.0359,.0351,.0344,.0336,.0329, 0.0322,.0314,.0307,.0301,.0294, 0.0287,.0281,.0274,.0268,.0262, 0.0256,.0250,.0244,.0239,.0233, 0.0228,.0222,.0217,.0212,.0207, 0.0202,.0197,.0192,.0188,.0183, 0.0179,.0174,.0170,.0166,.0162, 0.0158,.0154,.0150,.0146,.0143, 0.0139,.0136,.0132,.0129,.0125, 0.0122,.0119,.0116,.0113,.0110, 0.0107,.0104,.0102,.0099,.0096, 0.0094,.0091,.0089,.0087,.0084, 0.0082,.0080,.0078,.0075,.0073, 0.0071,.0069,.0068,.0066,.0064, 0.0062,.0060,.0059,.0057,.0055, 0.0054,.0052,.0051,.0049,.0048, 0.0047,.0045,.0044,.0043,.0041, 0.0040,.0039,.0038,.0037,.0036, 0.0035,.0034,.0033,.0032,.0031, 0.0030,.0029,.0028,.0027,.0026, 0.0026,.0025,.0024,.0023,.0023, 0.0022,.0021,.0021,.0020,.0019, 0.0019,.0018,.0018,.0017,.0016, 0.0016,.0015,.0015,.0014,.0014, 0.0013,.0013,.0013,.0012,.0012, 0.0011,.0011,.0011,.0010,.0010, 0.0010,.0009,.0009,.0009,.0008, 0.0008,.0008,.0008,.0007,.0007, 0.0007,.0007,.0006,.0006,.0006, 0.0006}; // parameters of the curve private double mean = 0; private double stdDev = 1; // Constructors public Normal() {} public Normal(double m, double s) { setMean(m); setStdDev(s); } // set methods public void setMean(double m) { mean = m; } public void setStdDev(double s) { stdDev = s; } // get methods public double getMean() { return mean; } public double getStdDev() { return stdDev; } // get area under curve for any region (in terms of percentage) public int getAreaUnderPct(double z1, double z2) {return (int)(getAreaUnderCurve(z1,z2)*100);} // get area under curve for any region (in terms of probablity) public double getAreaUnderCurve (double z1, double z2) { if ((z1 >=0 && z2 >= 0) || (z1<0 && z2 < 0)) return Math.abs(getTail(z1)-getTail(z2)); else return (getMiddle(z1) + getMiddle(z2)); }// end method getAreaUnderCurve // return the percentage of the region between the mean and the // z value public int getMiddlePct (double z) {return (int)(getMiddle(z)*100);} // return the probability for the region between the mean and the // z value public double getMiddle (double z) {return (0.5 - getTail(z));} // return the percentage of the curve beyond the z value public int getTailPct (double z) {return (int)(getTail(z)*100);} // return the probability for the regions beyond the z value public double getTail(double z) {return ((Math.abs(z)>=0 && Math.abs(z) <= 3.25) ? (double)(NORMALTAIL[(int)(Math.abs(z*100))]) : 0);} public double convertToZ (double m, double s, double x) { setMean(m); setStdDev(s); return (x - mean)/stdDev; } public double convertToZ (double x) { return (x-mean)/stdDev; } public double normalHeight(double m, double s, double x) { setMean(m); setStdDev(s); return (Math.exp(-(((x-mean)*(x-mean)) / (2 * (stdDev*stdDev)))) / (stdDev * Math.sqrt(2 * Math.PI))); }// end method normalHeight public double normalHeight(double x) { return (Math.exp(-(((x-mean)*(x-mean)) / (2 * (stdDev*stdDev)))) / (stdDev * Math.sqrt(2 * Math.PI))); } public double normalHeight(double z, boolean isZ) { return (Math.exp(-(((z)*(z)) / (2 * (1*1)))) / (1 * Math.sqrt(2 * Math.PI))); } // return the height of a curve in cumulative normal distribution // Ogive. public double getCumNormalHeight(double z){ double hgt = 0; // if z < 0 height = tail outside z value if (z < 0){ hgt = getTail(z); } // if z == 0, height = 0.5 if (z == 0){ hgt = 0.50; } // if z > 0 height is 1-tail proportion. if (z > 0){ hgt = 1.0-getTail(z); } return hgt; } }