def writeAnalysisSummaryData(self, numPerms, netKCalculations, outNetKLoc,
                                 outAnlFCName):
        # Analyze the network k results (generate plottable output).
        # No confidence intervals are computed if there are no random permutations.
        if numPerms != 0:
            netKAn_95 = NetworkKAnalysis(.95, netKCalculations)
            netKAn_90 = NetworkKAnalysis(.90, netKCalculations)

        # Write the analysis data to a table.
        outAnlFCFullPath = os.path.join(outNetKLoc, outAnlFCName)
        arcpy.CreateTable_management(outNetKLoc, outAnlFCName)
        arcpy.AddField_management(outAnlFCFullPath, "Description", "TEXT")
        arcpy.AddField_management(outAnlFCFullPath, "Distance_Band", "DOUBLE")
        arcpy.AddField_management(outAnlFCFullPath, "Point_Count", "DOUBLE")
        arcpy.AddField_management(outAnlFCFullPath, "K_Function", "DOUBLE")

        with arcpy.da.InsertCursor(
                outAnlFCFullPath,
            ["Description", "Distance_Band", "Point_Count", "K_Function"
             ]) as cursor:
            self._writeAnalysis(cursor, netKCalculations[0], "Observed")

            if numPerms != 0:
                self._writeAnalysis(cursor,
                                    netKAn_95.getLowerConfidenceEnvelope(),
                                    "2.5% Lower Bound")
                self._writeAnalysis(cursor,
                                    netKAn_95.getUpperConfidenceEnvelope(),
                                    "2.5% Upper Bound")
                self._writeAnalysis(cursor,
                                    netKAn_90.getLowerConfidenceEnvelope(),
                                    "5% Lower Bound")
                self._writeAnalysis(cursor,
                                    netKAn_90.getUpperConfidenceEnvelope(),
                                    "5% Upper Bound")
  def test_confidence_envelope(self):
    confInt          = .95
    netKCalculations = self.getRandNetK(1000)

    # There should be 25 below the confidence interval, and 25 above.
    # Envelope size = 999 * .95 = 949
    # 25 below the envelope, so the index of lower envelope should be 25.
    # 25 above the envelope, so the index of the upper envelope should be 973.
    # e.g. [25 - 973] are in the envelope, inclusive.
    netKAn = NetworkKAnalysis(confInt, netKCalculations)
    self.assertEqual(netKAn.getLowerConfidenceEnvelope()[0]["count"], 0)
    self.assertEqual(netKAn.getLowerConfidenceEnvelope()[1]["count"], 25)
    self.assertEqual(netKAn.getLowerConfidenceEnvelope()[2]["count"], 50)
    self.assertEqual(netKAn.getUpperConfidenceEnvelope()[0]["count"], 0)
    self.assertEqual(netKAn.getUpperConfidenceEnvelope()[1]["count"], 973)
    self.assertEqual(netKAn.getUpperConfidenceEnvelope()[2]["count"], 1946)

    # 948 - 50 + 1 = 899 = 999 * .90
    confInt          = .90
    netKCalculations = self.getRandNetK(1000)
    netKAn = NetworkKAnalysis(confInt, netKCalculations)
    self.assertEqual(netKAn.getEnvelopeSize(), 899)
    self.assertEqual(netKAn.getLowerConfidenceEnvelope()[1]["count"], 50)
    self.assertEqual(netKAn.getUpperConfidenceEnvelope()[1]["count"], 948)

    # 95 - 2 + 1 = 94 = 99 * .95
    # Note that the extra permuation is distributed above the envelope (2 below and 3 above).
    confInt          = .95
    netKCalculations = self.getRandNetK(100)
    netKAn = NetworkKAnalysis(confInt, netKCalculations)
    self.assertEqual(netKAn.getEnvelopeSize(), 94)
    self.assertEqual(netKAn.getLowerConfidenceEnvelope()[1]["count"], 2)
    self.assertEqual(netKAn.getUpperConfidenceEnvelope()[1]["count"], 95)

    confInt          = .90
    netKCalculations = self.getRandNetK(100)
    netKAn = NetworkKAnalysis(confInt, netKCalculations)
    self.assertEqual(netKAn.getEnvelopeSize(), 89)
    self.assertEqual(netKAn.getLowerConfidenceEnvelope()[1]["count"], 5)
    self.assertEqual(netKAn.getUpperConfidenceEnvelope()[1]["count"], 93)

    confInt          = .95
    netKCalculations = self.getRandNetK(10)
    netKAn = NetworkKAnalysis(confInt, netKCalculations)
    self.assertEqual(netKAn.getEnvelopeSize(), 9)
    self.assertEqual(netKAn.getLowerConfidenceEnvelope()[1]["count"], 0)
    self.assertEqual(netKAn.getUpperConfidenceEnvelope()[1]["count"], 8)

    confInt          = .90
    netKCalculations = self.getRandNetK(10)
    netKAn = NetworkKAnalysis(confInt, netKCalculations)
    self.assertEqual(netKAn.getEnvelopeSize(), 8)
    self.assertEqual(netKAn.getLowerConfidenceEnvelope()[1]["count"], 0)
    self.assertEqual(netKAn.getUpperConfidenceEnvelope()[1]["count"], 7)
Beispiel #3
0
    def test_confidence_envelope(self):
        confInt = .95
        netKCalculations = self.getRandNetK(1000)

        # There should be 25 below the confidence interval, and 25 above.
        # Envelope size = 999 * .95 = 949
        # 25 below the envelope, so the index of lower envelope should be 25.
        # 25 above the envelope, so the index of the upper envelope should be 973.
        # e.g. [25 - 973] are in the envelope, inclusive.
        netKAn = NetworkKAnalysis(confInt, netKCalculations)
        self.assertEqual(netKAn.getLowerConfidenceEnvelope()[0]["count"], 0)
        self.assertEqual(netKAn.getLowerConfidenceEnvelope()[1]["count"], 25)
        self.assertEqual(netKAn.getLowerConfidenceEnvelope()[2]["count"], 50)
        self.assertEqual(netKAn.getUpperConfidenceEnvelope()[0]["count"], 0)
        self.assertEqual(netKAn.getUpperConfidenceEnvelope()[1]["count"], 973)
        self.assertEqual(netKAn.getUpperConfidenceEnvelope()[2]["count"], 1946)

        # 948 - 50 + 1 = 899 = 999 * .90
        confInt = .90
        netKCalculations = self.getRandNetK(1000)
        netKAn = NetworkKAnalysis(confInt, netKCalculations)
        self.assertEqual(netKAn.getEnvelopeSize(), 899)
        self.assertEqual(netKAn.getLowerConfidenceEnvelope()[1]["count"], 50)
        self.assertEqual(netKAn.getUpperConfidenceEnvelope()[1]["count"], 948)

        # 95 - 2 + 1 = 94 = 99 * .95
        # Note that the extra permuation is distributed above the envelope (2 below and 3 above).
        confInt = .95
        netKCalculations = self.getRandNetK(100)
        netKAn = NetworkKAnalysis(confInt, netKCalculations)
        self.assertEqual(netKAn.getEnvelopeSize(), 94)
        self.assertEqual(netKAn.getLowerConfidenceEnvelope()[1]["count"], 2)
        self.assertEqual(netKAn.getUpperConfidenceEnvelope()[1]["count"], 95)

        confInt = .90
        netKCalculations = self.getRandNetK(100)
        netKAn = NetworkKAnalysis(confInt, netKCalculations)
        self.assertEqual(netKAn.getEnvelopeSize(), 89)
        self.assertEqual(netKAn.getLowerConfidenceEnvelope()[1]["count"], 5)
        self.assertEqual(netKAn.getUpperConfidenceEnvelope()[1]["count"], 93)

        confInt = .95
        netKCalculations = self.getRandNetK(10)
        netKAn = NetworkKAnalysis(confInt, netKCalculations)
        self.assertEqual(netKAn.getEnvelopeSize(), 9)
        self.assertEqual(netKAn.getLowerConfidenceEnvelope()[1]["count"], 0)
        self.assertEqual(netKAn.getUpperConfidenceEnvelope()[1]["count"], 8)

        confInt = .90
        netKCalculations = self.getRandNetK(10)
        netKAn = NetworkKAnalysis(confInt, netKCalculations)
        self.assertEqual(netKAn.getEnvelopeSize(), 8)
        self.assertEqual(netKAn.getLowerConfidenceEnvelope()[1]["count"], 0)
        self.assertEqual(netKAn.getUpperConfidenceEnvelope()[1]["count"], 7)
  def writeAnalysisSummaryData(self, numPerms, netKCalculations, outNetKLoc, outAnlFCName):
    # Analyze the network k results (generate plottable output).
    # No confidence intervals are computed if there are no random permutations.
    if numPerms != 0:
      netKAn_95 = NetworkKAnalysis(.95, netKCalculations)
      netKAn_90 = NetworkKAnalysis(.90, netKCalculations)

    # Write the analysis data to a table.
    outAnlFCFullPath = os.path.join(outNetKLoc, outAnlFCName)
    arcpy.CreateTable_management(outNetKLoc, outAnlFCName)
    arcpy.AddField_management(outAnlFCFullPath, "Description",   "TEXT")
    arcpy.AddField_management(outAnlFCFullPath, "Distance_Band", "DOUBLE")
    arcpy.AddField_management(outAnlFCFullPath, "Point_Count",   "DOUBLE")
    arcpy.AddField_management(outAnlFCFullPath, "K_Function",    "DOUBLE")

    with arcpy.da.InsertCursor(outAnlFCFullPath,
      ["Description", "Distance_Band", "Point_Count", "K_Function"]) as cursor:
      self._writeAnalysis(cursor, netKCalculations[0], "Observed")

      if numPerms != 0:
        self._writeAnalysis(cursor, netKAn_95.getLowerConfidenceEnvelope(), "2.5% Lower Bound")
        self._writeAnalysis(cursor, netKAn_95.getUpperConfidenceEnvelope(), "2.5% Upper Bound")
        self._writeAnalysis(cursor, netKAn_90.getLowerConfidenceEnvelope(), "5% Lower Bound")
        self._writeAnalysis(cursor, netKAn_90.getUpperConfidenceEnvelope(), "5% Upper Bound")