nodes: 0, module; 1, function_definition; 2, function_name:comparison_table; 3, parameters; 4, comment:# pragma: no cover; 5, block; 6, identifier:self; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, default_parameter; 14, default_parameter; 15, expression_statement; 16, if_statement; 17, if_statement; 18, if_statement; 19, if_statement; 20, if_statement; 21, expression_statement; 22, expression_statement; 23, expression_statement; 24, expression_statement; 25, expression_statement; 26, expression_statement; 27, if_statement; 28, expression_statement; 29, if_statement; 30, if_statement; 31, if_statement; 32, if_statement; 33, if_statement; 34, expression_statement; 35, expression_statement; 36, expression_statement; 37, expression_statement; 38, expression_statement; 39, expression_statement; 40, if_statement; 41, for_statement; 42, if_statement; 43, return_statement; 44, identifier:caption; 45, None; 46, identifier:label; 47, string:"tab:model_comp"; 48, identifier:hlines; 49, True; 50, identifier:aic; 51, True; 52, identifier:bic; 53, True; 54, identifier:dic; 55, True; 56, identifier:sort; 57, string:"bic"; 58, identifier:descending; 59, True; 60, comment:"""
          Return a LaTeX ready table of model comparisons.
  
          Parameters
          ----------
          caption : str, optional
              The table caption to insert.
          label : str, optional
              The table label to insert.
          hlines : bool, optional
              Whether to insert hlines in the table or not.
          aic : bool, optional
              Whether to include a column for AICc or not.
          bic : bool, optional
              Whether to include a column for BIC or not.
          dic : bool, optional
              Whether to include a column for DIC or not.
          sort : str, optional
              How to sort the models. Should be one of "bic", "aic" or "dic".
          descending : bool, optional
              The sort order.
  
          Returns
          -------
          str
              A LaTeX table to be copied into your document.
          """; 61, comparison_operator:sort == "bic"; 62, block; 63, comparison_operator:sort == "aic"; 64, block; 65, comparison_operator:sort == "dic"; 66, block; 67, comparison_operator:caption is None; 68, block; 69, comparison_operator:label is None; 70, block; 71, assignment; 72, assignment; 73, assignment; 74, assignment; 75, assignment; 76, assignment; 77, identifier:hlines; 78, block; 79, augmented_assignment; 80, identifier:hlines; 81, block; 82, identifier:aic; 83, block; 84, else_clause; 85, identifier:bic; 86, block; 87, else_clause; 88, identifier:dic; 89, block; 90, else_clause; 91, comparison_operator:sort == "bic"; 92, block; 93, elif_clause; 94, elif_clause; 95, else_clause; 96, assignment; 97, assignment; 98, assignment; 99, assignment; 100, assignment; 101, assignment; 102, identifier:descending; 103, block; 104, identifier:i; 105, identifier:indexes; 106, block; 107, identifier:hlines; 108, block; 109, binary_operator:base_string % (column_text, center_text); 110, identifier:sort; 111, string:"bic"; 112, assert_statement; 113, identifier:sort; 114, string:"aic"; 115, assert_statement; 116, identifier:sort; 117, string:"dic"; 118, assert_statement; 119, identifier:caption; 120, None; 121, expression_statement; 122, identifier:label; 123, None; 124, expression_statement; 125, identifier:base_string; 126, call; 127, identifier:end_text; 128, string:" \\\\ \n"; 129, identifier:num_cols; 130, binary_operator:1 + (1 if aic else 0) + (1 if bic else 0); 131, identifier:column_text; 132, binary_operator:"c" * (num_cols + 1); 133, identifier:center_text; 134, string:""; 135, identifier:hline_text; 136, string:"\\hline\n"; 137, expression_statement; 138, identifier:center_text; 139, binary_operator:"\tModel" + (" & AIC" if aic else "") + (" & BIC " if bic else "") \
                         + (" & DIC " if dic else "") + end_text; 140, expression_statement; 141, expression_statement; 142, block; 143, expression_statement; 144, block; 145, expression_statement; 146, block; 147, identifier:sort; 148, string:"bic"; 149, expression_statement; 150, comparison_operator:sort == "aic"; 151, block; 152, comparison_operator:sort == "dic"; 153, block; 154, block; 155, identifier:good; 156, list_comprehension; 157, identifier:names; 158, list_comprehension; 159, identifier:aics; 160, list_comprehension; 161, identifier:bics; 162, list_comprehension; 163, identifier:to_sort; 164, conditional_expression:bics if sort == "bic" else aics; 165, identifier:indexes; 166, call; 167, expression_statement; 168, expression_statement; 169, if_statement; 170, if_statement; 171, if_statement; 172, expression_statement; 173, expression_statement; 174, expression_statement; 175, identifier:base_string; 176, tuple; 177, identifier:bic; 178, string:"You cannot sort by BIC if you turn it off"; 179, identifier:aic; 180, string:"You cannot sort by AIC if you turn it off"; 181, identifier:dic; 182, string:"You cannot sort by DIC if you turn it off"; 183, assignment; 184, assignment; 185, identifier:get_latex_table_frame; 186, argument_list; 187, binary_operator:1 + (1 if aic else 0); 188, parenthesized_expression; 189, string:"c"; 190, parenthesized_expression; 191, augmented_assignment; 192, binary_operator:"\tModel" + (" & AIC" if aic else "") + (" & BIC " if bic else "") \
                         + (" & DIC " if dic else ""); 193, identifier:end_text; 194, augmented_assignment; 195, assignment; 196, expression_statement; 197, assignment; 198, expression_statement; 199, assignment; 200, expression_statement; 201, assignment; 202, identifier:sort; 203, string:"aic"; 204, expression_statement; 205, identifier:sort; 206, string:"dic"; 207, expression_statement; 208, raise_statement; 209, identifier:i; 210, for_in_clause; 211, if_clause; 212, attribute; 213, for_in_clause; 214, subscript; 215, for_in_clause; 216, subscript; 217, for_in_clause; 218, identifier:bics; 219, comparison_operator:sort == "bic"; 220, identifier:aics; 221, attribute; 222, argument_list; 223, assignment; 224, assignment; 225, identifier:aic; 226, block; 227, identifier:bic; 228, block; 229, identifier:dic; 230, block; 231, augmented_assignment; 232, augmented_assignment; 233, augmented_assignment; 234, identifier:column_text; 235, identifier:center_text; 236, identifier:caption; 237, string:""; 238, identifier:label; 239, string:""; 240, identifier:caption; 241, identifier:label; 242, integer:1; 243, parenthesized_expression; 244, conditional_expression:1 if bic else 0; 245, binary_operator:num_cols + 1; 246, identifier:center_text; 247, identifier:hline_text; 248, binary_operator:"\tModel" + (" & AIC" if aic else "") + (" & BIC " if bic else ""); 249, line_continuation:\; 250, parenthesized_expression; 251, identifier:center_text; 252, binary_operator:"\t" + hline_text; 253, identifier:aics; 254, call; 255, assignment; 256, identifier:bics; 257, call; 258, assignment; 259, identifier:dics; 260, call; 261, assignment; 262, identifier:to_sort; 263, identifier:bics; 264, assignment; 265, assignment; 266, call; 267, pattern_list; 268, call; 269, comparison_operator:t is not None; 270, subscript; 271, identifier:name; 272, identifier:g; 273, identifier:good; 274, identifier:aics; 275, identifier:g; 276, identifier:g; 277, identifier:good; 278, identifier:bics; 279, identifier:g; 280, identifier:g; 281, identifier:good; 282, identifier:sort; 283, string:"bic"; 284, identifier:np; 285, identifier:argsort; 286, identifier:to_sort; 287, identifier:indexes; 288, subscript; 289, identifier:line; 290, binary_operator:"\t" + names[i]; 291, expression_statement; 292, expression_statement; 293, expression_statement; 294, identifier:line; 295, identifier:end_text; 296, identifier:center_text; 297, identifier:line; 298, identifier:center_text; 299, binary_operator:"\t" + hline_text; 300, conditional_expression:1 if aic else 0; 301, integer:1; 302, identifier:bic; 303, integer:0; 304, identifier:num_cols; 305, integer:1; 306, binary_operator:"\tModel" + (" & AIC" if aic else ""); 307, parenthesized_expression; 308, conditional_expression:" & DIC " if dic else ""; 309, string:"\t"; 310, identifier:hline_text; 311, attribute; 312, argument_list; 313, identifier:aics; 314, call; 315, attribute; 316, argument_list; 317, identifier:bics; 318, call; 319, attribute; 320, argument_list; 321, identifier:dics; 322, call; 323, identifier:to_sort; 324, identifier:aics; 325, identifier:to_sort; 326, identifier:dics; 327, identifier:ValueError; 328, argument_list; 329, identifier:i; 330, identifier:t; 331, identifier:enumerate; 332, argument_list; 333, identifier:t; 334, None; 335, attribute; 336, identifier:g; 337, identifier:indexes; 338, slice; 339, string:"\t"; 340, subscript; 341, augmented_assignment; 342, augmented_assignment; 343, augmented_assignment; 344, string:"\t"; 345, identifier:hline_text; 346, integer:1; 347, identifier:aic; 348, integer:0; 349, string:"\tModel"; 350, parenthesized_expression; 351, conditional_expression:" & BIC " if bic else ""; 352, string:" & DIC "; 353, identifier:dic; 354, string:""; 355, identifier:self; 356, identifier:aic; 357, attribute; 358, argument_list; 359, identifier:self; 360, identifier:bic; 361, attribute; 362, argument_list; 363, identifier:self; 364, identifier:dic; 365, attribute; 366, argument_list; 367, binary_operator:"sort %s not recognised, must be dic, aic or dic" % sort; 368, identifier:to_sort; 369, attribute; 370, identifier:chains; 371, unary_operator; 372, identifier:names; 373, identifier:i; 374, identifier:line; 375, binary_operator:"  &  %5.1f  " % aics[i]; 376, identifier:line; 377, binary_operator:"  &  %5.1f  " % bics[i]; 378, identifier:line; 379, binary_operator:"  &  %5.1f  " % dics[i]; 380, conditional_expression:" & AIC" if aic else ""; 381, string:" & BIC "; 382, identifier:bic; 383, string:""; 384, identifier:np; 385, identifier:zeros; 386, call; 387, identifier:np; 388, identifier:zeros; 389, call; 390, identifier:np; 391, identifier:zeros; 392, call; 393, string:"sort %s not recognised, must be dic, aic or dic"; 394, identifier:sort; 395, identifier:self; 396, identifier:parent; 397, integer:1; 398, string:"  &  %5.1f  "; 399, subscript; 400, string:"  &  %5.1f  "; 401, subscript; 402, string:"  &  %5.1f  "; 403, subscript; 404, string:" & AIC"; 405, identifier:aic; 406, string:""; 407, identifier:len; 408, argument_list; 409, identifier:len; 410, argument_list; 411, identifier:len; 412, argument_list; 413, identifier:aics; 414, identifier:i; 415, identifier:bics; 416, identifier:i; 417, identifier:dics; 418, identifier:i; 419, attribute; 420, attribute; 421, attribute; 422, attribute; 423, identifier:chains; 424, attribute; 425, identifier:chains; 426, attribute; 427, identifier:chains; 428, identifier:self; 429, identifier:parent; 430, identifier:self; 431, identifier:parent; 432, identifier:self; 433, identifier:parent
code: def comparison_table(self, caption=None, label="tab:model_comp", hlines=True,
                           aic=True, bic=True, dic=True, sort="bic", descending=True):  # pragma: no cover
          """
          Return a LaTeX ready table of model comparisons.
  
          Parameters
          ----------
          caption : str, optional
              The table caption to insert.
          label : str, optional
              The table label to insert.
          hlines : bool, optional
              Whether to insert hlines in the table or not.
          aic : bool, optional
              Whether to include a column for AICc or not.
          bic : bool, optional
              Whether to include a column for BIC or not.
          dic : bool, optional
              Whether to include a column for DIC or not.
          sort : str, optional
              How to sort the models. Should be one of "bic", "aic" or "dic".
          descending : bool, optional
              The sort order.
  
          Returns
          -------
          str
              A LaTeX table to be copied into your document.
          """
  
          if sort == "bic":
              assert bic, "You cannot sort by BIC if you turn it off"
          if sort == "aic":
              assert aic, "You cannot sort by AIC if you turn it off"
          if sort == "dic":
              assert dic, "You cannot sort by DIC if you turn it off"
  
          if caption is None:
              caption = ""
          if label is None:
              label = ""
  
          base_string = get_latex_table_frame(caption, label)
          end_text = " \\\\ \n"
          num_cols = 1 + (1 if aic else 0) + (1 if bic else 0)
          column_text = "c" * (num_cols + 1)
          center_text = ""
          hline_text = "\\hline\n"
          if hlines:
              center_text += hline_text
          center_text += "\tModel" + (" & AIC" if aic else "") + (" & BIC " if bic else "") \
                         + (" & DIC " if dic else "") + end_text
          if hlines:
              center_text += "\t" + hline_text
          if aic:
              aics = self.aic()
          else:
              aics = np.zeros(len(self.parent.chains))
          if bic:
              bics = self.bic()
          else:
              bics = np.zeros(len(self.parent.chains))
          if dic:
              dics = self.dic()
          else:
              dics = np.zeros(len(self.parent.chains))
  
          if sort == "bic":
              to_sort = bics
          elif sort == "aic":
              to_sort = aics
          elif sort == "dic":
              to_sort = dics
          else:
              raise ValueError("sort %s not recognised, must be dic, aic or dic" % sort)
  
          good = [i for i, t in enumerate(to_sort) if t is not None]
          names = [self.parent.chains[g].name for g in good]
          aics = [aics[g] for g in good]
          bics = [bics[g] for g in good]
          to_sort = bics if sort == "bic" else aics
  
          indexes = np.argsort(to_sort)
  
          if descending:
              indexes = indexes[::-1]
  
          for i in indexes:
              line = "\t" + names[i]
              if aic:
                  line += "  &  %5.1f  " % aics[i]
              if bic:
                  line += "  &  %5.1f  " % bics[i]
              if dic:
                  line += "  &  %5.1f  " % dics[i]
              line += end_text
              center_text += line
          if hlines:
              center_text += "\t" + hline_text
  
          return base_string % (column_text, center_text)