Пример #1
0
def all_steps():
    print time.asctime()
    iterations = 20000
    sum_rc = 0
    for i in range(iterations):
        # Sampling Error
        bs1 = svmp.bootstrap(frw_sitedata)
        bs1m = svmp.bootstrap(frw_y1matchdata)
        bs2m = svmp.match_sites(bs1m,frw_y2matchdata)
        # Measurement Error
        me1 = svmp.measurement_error(bs1,i,"y1",outFileSiteMC)
        me1m = svmp.measurement_error(bs1m,i,"y1match",outFileSiteMC)
        me2m = svmp.measurement_error(bs2m,i,"y2match",outFileSiteMC)
        #me1 = svmp.measurement_error(bs1,i,"y1")
        #me1m = svmp.measurement_error(bs1m,i,"y1match")
        #me2m = svmp.measurement_error(bs2m,i,"y2match")
        # Calculate Change Analysis stats with Simulated Data
        yr1Samp  = svmp.SampleStats(me1,frwStratum,unit_convert)
        yr1mSamp = svmp.SampleStats(me1m,frwStratum,unit_convert)
        yr2mSamp = svmp.SampleStats(me2m,frwStratum,unit_convert)  
        frwChange = svmp.ChangeStats(yr1mSamp,yr2mSamp,yr1Samp)
        rc = frwChange.change_prop
        #print "Relative Change %r" % rc
        rcString = "%i,%r\n" % (i,rc)
        #print rcString
        rel_changes.append(rc)
        #sum_rc = sum_rc + rc
        outFileRC.write(rcString)
        
    mean_rc = sum(rel_changes)/ iterations
    print "Mean Relative Change %r" % mean_rc
    conf95pct = svmp.conf_int(rel_changes,0.95)
    print "95 percent confidence interval %r" % conf95pct
    print time.asctime()
Пример #2
0
                if outFile:
                    out_string = "%i,%r\n" % (i,rc)
                    output.write(out_string) 
                
            if outFile:
                output.close()
                
            return rel_changes

        
        msg("Calculating Monte Carlo Confidence Intervals.  This may take a couple minutes...")
        # Calculate Relative Change list - 20,000 iterations
        #rel_changes = mc_relative_change(20000,outFileRC)
        rel_changes = mc_relative_change(20000)
        # Calculate Monte Carlo 95% confidence interval
        mc_ci = svmp.conf_int(rel_changes,0.95)
                
        #------------------------------ End MONTE CARLO CI -----------------------------
        #-------------------------------------------------------------------------------
        
        
        #-----------------------------------   OUTPUT ----------------------------------
        #-------------------------------------------------------------------------------
        
        def output_strata(label,changeObj):
            msg("******  %s *********" % label)
            msg("Year 1 Area: %r" % changeObj.y1.zm_area)
            msg("Year 1 Variance: %r" % changeObj.y1.zm_area_var)
            msg("Matching Sites")
            for site in sorted(changeObj.y1m.site_ids):
                msg("  %s" % site)