JAVA#confidenceInterval‘札记

/**
 * Created by Schwinn on 18/9/14.
 */
public class ConfidenceIntervals {
   public static void main(String[] args) {
       //set the length
System.out.println("Please input the shuzu.length:"); int changdu= new Scanner(System.in).nextInt(); //make the arraylist
double[] shuzu=new double[changdu];
       //Repeat this 11 times.
       for(int iverson=0;iverson<11;iverson++) {
          //give the number to the array
          for (int i = 0; i < shuzu.length; i++) {
double element = Math.random();
             shuzu[i] = element;
          }
          double he = 0;
          for (int i = 0; i < shuzu.length; i++) {
             he += shuzu[i];
          }
//average
          double average = he / shuzu.length;
          double varianceSum = 0;
          for (int i = 0; i < shuzu.length; i++) {
             varianceSum += (shuzu[i] - average) * (shuzu[i] - average);
          }
double variance = varianceSum / shuzu.length - 1; double realvariance = Math.abs(variance);
double standardError = Math.sqrt(realvariance); double Ur = 2.23 * standardError /
java.lang.Math.sqrt(shuzu.length);
double boundleft = average - Ur;
          double boundright = average + Ur;
System.out.println("This is the "+(iverson+1)+" time operation and the confidenceInterval as the follow:");
System.out.println("ConfidenceTnterval of 10 observations is:" +"["+boundleft+" ,"+boundright+"]");
} }
}
Please input the shuzu.length:
10
This is the 1 time operation and the confidenceInterval as the follow:
When E[X]=0.4102910595669112 # ConfidenceInterval of 10 observations is:[-0.2838469848863118   ,1.1044291040201342]
This is the 2 time operation and the confidenceInterval as the follow:
When E[X]=0.5814793965200894 # ConfidenceInterval of 10 observations is:[-0.0932515203521802   ,1.256210313392359]
This is the 3 time operation and the confidenceInterval as the follow:
When E[X]=0.31257617996324666 # ConfidenceInterval of 10 observations is:[-0.35798103227223116   ,0.9831333921987244]
This is the 4 time operation and the confidenceInterval as the follow:
When E[X]=0.5445981023091173 # ConfidenceInterval of 10 observations is:[-0.13174905975357276   ,1.2209452643718075]
This is the 5 time operation and the confidenceInterval as the follow:
When E[X]=0.4305572189051241 # ConfidenceInterval of 10 observations is:[-0.239772308637082   ,1.1008867464473302]
This is the 6 time operation and the confidenceInterval as the follow:
When E[X]=0.5630967068675956 # ConfidenceInterval of 10 observations is:[-0.11750341986664192   ,1.2436968336018333]
This is the 7 time operation and the confidenceInterval as the follow:
When E[X]=0.5158181512436347 # ConfidenceInterval of 10 observations is:[-0.16252976842477262   ,1.194166070912042]
This is the 8 time operation and the confidenceInterval as the follow:
When E[X]=0.4012432020270246 # ConfidenceInterval of 10 observations is:[-0.2879612191473873   ,1.0904476232014366]
This is the 9 time operation and the confidenceInterval as the follow:
When E[X]=0.4108473016359386 # ConfidenceInterval of 10 observations is:[-0.26835364239664455   ,1.0900482456685217]
This is the 10 time operation and the confidenceInterval as the follow:
When E[X]=0.4703343306439759 # ConfidenceInterval of 10 observations is:[-0.1964759878089184   ,1.1371446490968702]
This is the 11 time operation and the confidenceInterval as the follow:
When E[X]=0.6383599078950759 # ConfidenceInterval of 10 observations is:[-0.038885930384014555   ,1.3156057461741664]
Please input the shuzu.length:
100
This is the 1 time operation and the confidenceInterval as the follow:
When E[X]=0.49558114342884546 # ConfidenceInterval of 100 observations is:[0.28084612596061426   ,0.7103161608970767]
This is the 2 time operation and the confidenceInterval as the follow:
When E[X]=0.5244138695538091 # ConfidenceInterval of 100 observations is:[0.3105197558667573   ,0.7383079832408609]
This is the 3 time operation and the confidenceInterval as the follow:
When E[X]=0.4645553852407482 # ConfidenceInterval of 100 observations is:[0.251068750883761   ,0.6780420195977354]
This is the 4 time operation and the confidenceInterval as the follow:
When E[X]=0.4271564004082635 # ConfidenceInterval of 100 observations is:[0.21298003120804504   ,0.6413327696084821]
This is the 5 time operation and the confidenceInterval as the follow:
When E[X]=0.518217938983341 # ConfidenceInterval of 100 observations is:[0.30482994981367595   ,0.7316059281530061]
This is the 6 time operation and the confidenceInterval as the follow:
When E[X]=0.4757394546493962 # ConfidenceInterval of 100 observations is:[0.2616882369148946   ,0.6897906723838978]
This is the 7 time operation and the confidenceInterval as the follow:
When E[X]=0.4958808085893789 # ConfidenceInterval of 100 observations is:[0.2824597811778087   ,0.7093018360009491]
This is the 8 time operation and the confidenceInterval as the follow:
When E[X]=0.5044137537262745 # ConfidenceInterval of 100 observations is:[0.29008975828509753   ,0.7187377491674515]
This is the 9 time operation and the confidenceInterval as the follow:
When E[X]=0.5011838618630506 # ConfidenceInterval of 100 observations is:[0.2882262185116792   ,0.7141415052144221]
This is the 10 time operation and the confidenceInterval as the follow:
When E[X]=0.43299914066892015 # ConfidenceInterval of 100 observations is:[0.22039320849744548   ,0.6456050728403948]
This is the 11 time operation and the confidenceInterval as the follow:
When E[X]=0.5443069513683579 # ConfidenceInterval of 100 observations is:[0.3295690837600554   ,0.7590448189766605]
Please input the shuzu.length:
1000
This is the 1 time operation and the confidenceInterval as the follow:
When E[X]=0.517675161562533 # ConfidenceInterval of 1000 observations is:[0.4501872052484712   ,0.5851631178765948]
This is the 2 time operation and the confidenceInterval as the follow:
When E[X]=0.5061116093817477 # ConfidenceInterval of 1000 observations is:[0.4384128535274353   ,0.5738103652360601]
This is the 3 time operation and the confidenceInterval as the follow:
When E[X]=0.4923760100866844 # ConfidenceInterval of 1000 observations is:[0.4246742626222265   ,0.5600777575511423]
This is the 4 time operation and the confidenceInterval as the follow:
When E[X]=0.4866810171687631 # ConfidenceInterval of 1000 observations is:[0.4191739139512139   ,0.5541881203863124]
This is the 5 time operation and the confidenceInterval as the follow:
When E[X]=0.4897767674188088 # ConfidenceInterval of 1000 observations is:[0.4222049342380247   ,0.557348600599593]
This is the 6 time operation and the confidenceInterval as the follow:
When E[X]=0.5029586692201288 # ConfidenceInterval of 1000 observations is:[0.4353489506908943   ,0.5705683877493632]
This is the 7 time operation and the confidenceInterval as the follow:
When E[X]=0.4963647431921164 # ConfidenceInterval of 1000 observations is:[0.42878401349366946   ,0.5639454728905633]
This is the 8 time operation and the confidenceInterval as the follow:
When E[X]=0.48821876356802846 # ConfidenceInterval of 1000 observations is:[0.42071994837182397   ,0.555717578764233]
This is the 9 time operation and the confidenceInterval as the follow:
When E[X]=0.5046754507768226 # ConfidenceInterval of 1000 observations is:[0.43696693474926607   ,0.5723839668043792]
This is the 10 time operation and the confidenceInterval as the follow:
When E[X]=0.4759239624951531 # ConfidenceInterval of 1000 observations is:[0.4082856368158372   ,0.543562288174469]
This is the 11 time operation and the confidenceInterval as the follow:
When E[X]=0.5032059384524271 # ConfidenceInterval of 1000 observations is:[0.43561886298166225   ,0.5707930139231919]
Please input the shuzu.length:
100000
This is the 1 time operation and the confidenceInterval as the follow:
When E[X]=0.5012844826998153 # ConfidenceInterval of 100000 observations is:[0.49453408859327086   ,0.5080348768063597]
This is the 2 time operation and the confidenceInterval as the follow:
When E[X]=0.4995245829983922 # ConfidenceInterval of 100000 observations is:[0.49277294715241815   ,0.5062762188443662]
This is the 3 time operation and the confidenceInterval as the follow:
When E[X]=0.49928275355648843 # ConfidenceInterval of 100000 observations is:[0.492530435346614   ,0.5060350717663629]
This is the 4 time operation and the confidenceInterval as the follow:
When E[X]=0.49986074142100784 # ConfidenceInterval of 100000 observations is:[0.49310965641158666   ,0.506611826430429]
This is the 5 time operation and the confidenceInterval as the follow:
When E[X]=0.499506329811044 # ConfidenceInterval of 100000 observations is:[0.49275373221970664   ,0.5062589274023813]
This is the 6 time operation and the confidenceInterval as the follow:
When E[X]=0.4984574011776487 # ConfidenceInterval of 100000 observations is:[0.4917064322071108   ,0.5052083701481866]
This is the 7 time operation and the confidenceInterval as the follow:
When E[X]=0.4997359990259886 # ConfidenceInterval of 100000 observations is:[0.49298410765020906   ,0.5064878904017681]
This is the 8 time operation and the confidenceInterval as the follow:
When E[X]=0.49931239086289797 # ConfidenceInterval of 100000 observations is:[0.4925610746221829   ,0.506063707103613]
This is the 9 time operation and the confidenceInterval as the follow:
When E[X]=0.4991691306666236 # ConfidenceInterval of 100000 observations is:[0.49241711084544376   ,0.5059211504878035]
This is the 10 time operation and the confidenceInterval as the follow:
When E[X]=0.4999751211644627 # ConfidenceInterval of 100000 observations is:[0.4932234799986626   ,0.5067267623302628]
This is the 11 time operation and the confidenceInterval as the follow:
When E[X]=0.5004296764179508 # ConfidenceInterval of 100000 observations is:[0.49367871587767553   ,0.507180636958226]
Please input the shuzu.length:
100000000
This is the 1 time operation and the confidenceInterval as the follow:
When E[X]=0.4999967495310354 # ConfidenceInterval of 100000000 observations is:[0.49978324271534513   ,0.5002102563467257]
This is the 2 time operation and the confidenceInterval as the follow:
When E[X]=0.5000236811731126 # ConfidenceInterval of 100000000 observations is:[0.4998101754137667   ,0.5002371869324584]
This is the 3 time operation and the confidenceInterval as the follow:
When E[X]=0.5000289670165912 # ConfidenceInterval of 100000000 observations is:[0.4998154620907854   ,0.5002424719423969]
This is the 4 time operation and the confidenceInterval as the follow:
When E[X]=0.500024339344336 # ConfidenceInterval of 100000000 observations is:[0.49981083165772533   ,0.5002378470309466]
This is the 5 time operation and the confidenceInterval as the follow:
When E[X]=0.49995038044215334 # ConfidenceInterval of 100000000 observations is:[0.4997368753018254   ,0.5001638855824813]
This is the 6 time operation and the confidenceInterval as the follow:
When E[X]=0.49999031259649607 # ConfidenceInterval of 100000000 observations is:[0.4997768072256581   ,0.500203817967334]
This is the 7 time operation and the confidenceInterval as the follow:
When E[X]=0.49996951808972656 # ConfidenceInterval of 100000000 observations is:[0.49975601137771414   ,0.500183024801739]
This is the 8 time operation and the confidenceInterval as the follow:
When E[X]=0.5000561992097947 # ConfidenceInterval of 100000000 observations is:[0.4998426948950049   ,0.5002697035245846]
This is the 9 time operation and the confidenceInterval as the follow:
When E[X]=0.4999722882410121 # ConfidenceInterval of 100000000 observations is:[0.4997587823361901   ,0.5001857941458341]
This is the 10 time operation and the confidenceInterval as the follow:
When E[X]=0.4999593774683983 # ConfidenceInterval of 100000000 observations is:[0.4997458705894554   ,0.5001728843473412]
This is the 11 time operation and the confidenceInterval as the follow:
When E[X]=0.4999859591759634 # ConfidenceInterval of 100000000 observations is:[0.49977245347698596   ,0.5001994648749408]

猜你喜欢

转载自blog.csdn.net/Iverson941112/article/details/82731120