class_docstr: Nested Multinomial Logit with Random Utility 2 parameterization
  
      
docstr: walking a tree bottom-up based on dictionary
          
docstr_tok: ["walking","a","tree","bottom-up","based","on","dictionary"]
code: def calc_prob(self, tree, keys=None):
      """walking a tree bottom-up based on dictionary"""
      endog = self.endog
      datadict = self.datadict
      paramsind = self.paramsind
      branchsum = self.branchsum
  
      if isinstance(
          tree, tuple
      ):  # assumes leaves are int for choice index
          name, subtree = tree
          print(name, datadict[name])
          print("subtree", subtree)
          keys = []
          if testxb:
              branchsum = datadict[name]
          else:
              branchsum = name  # 0
          for b in subtree:
              print(b)
              # branchsum += branch2(b)
              branchsum = branchsum + self.calc_prob(b, keys)
          print("branchsum", branchsum, keys)
          for k in keys:
              self.probs[k] = self.probs[k] + ["*" + name + "-prob"]
  
      else:
          keys.append(tree)
          self.probs[tree] = [
              tree + "-prob" + "(%s)" % ", ".join(self.paramsind[tree])
          ]
          if testxb:
              leavessum = sum(datadict[bi] for bi in tree)
              print(
                  "final branch with", tree, "".join(tree), leavessum
              )  # sum(tree)
              return leavessum  # sum(xb[tree])
          else:
              return "".join(tree)  # sum(tree)
  
      print("working on branch", tree, branchsum)
      return branchsum
  
file_path: statsmodels/statsmodels/sandbox/regression/runmnl.py
imports: import numpy
  import numpy.lib.recfunctions
  from scipy import optimize
label_desc: Use image node_id 2 for calling the RU2NMNL obj's underlying member method code with example usage: obj.calc_prob(tree, keys) and returns: branchsum, leavessum, str