def optimal_reroot(self, force_positive=True, slope=None):
best_root = self.find_best_root(force_positive=force_positive, slope=slope)<EOL>best_node = best_root["<STR_LIT>"]<EOL>x = best_root["<STR_LIT>"]<EOL>if x<<NUM_LIT>:<EOL><INDENT>new_node = best_node<EOL><DEDENT>elif x><NUM_LIT:1.0>-<NUM_LIT>:<EOL><INDENT>new_node = best_node.up<EOL><DEDENT>else:<EOL><INDENT>new_node = Phylo.BaseTree.Clade()<EOL>new_node.branch_length = best_node.branch_length*(<NUM_LIT:1>-x)<EOL>new_node.up = best_node.up<EOL>new_node.clades = [best_node]<EOL>new_node.up.clades = [k if k!=best_node else new_node<EOL>for k in best_node.up.clades]<EOL>best_node.branch_length *= x<EOL>best_node.up = new_node<EOL><DEDENT>new_node.rtt_regression = best_root<EOL>self.tree.root_with_outgroup(new_node)<EOL>self.tree.ladderize()<EOL>for n in self.tree.get_nonterminals(order='<STR_LIT>'):<EOL><INDENT>for c in n:<EOL><INDENT>c.up=n<EOL><DEDENT><DEDENT>return best_root<EOL>
determine the best root and reroot the tree to this value.
Note that this can change the parent child relations of the tree
and values associated with branches rather than nodes
(e.g. confidence) might need to be re-evaluated afterwards

Parameters
----------
force_positive : bool, optional
    if True, the search for a root will only consider positive rate estimates

slope : float, optional
    if given, it will find the optimal root given a fixed rate. If slope==0, this
    corresponds to minimal root-to-tip variance rooting (min_dev)

Returns
-------
dict
    regression parameters