Creates an external pointer to an object of class aphylo_pruner. This is mostly used to compute the model's likelihood function faster by reusing underlying C++ class objects to store probability matrices and data. This is intended for internal use only.

dist2root(ptr)

get_postorder(ptr)

new_aphylo_pruner(x, ...)

Arguments

ptr

An object of class aphylo_pruner.

x

An object of class aphylo or multiAphylo.

...

Further arguments passed to the method

Value

dist2root: An integer vector with the number of steps from each node (internal or not) to the root node.

get_postorder: An integer vector with the postorder sequence for pruning the tree (indexed from 0).

The function new_aphylo_pruner returns an object of class aphylo_pruner or multiAphylo_pruner, depending on the class of x.

Details

The underlying implementation of the pruning function is based on the pruner C++ library that implements Felsenstein's tree pruning algorithm. See https://github.com/USCbiostats/pruner.

Examples

set.seed(1)
x  <- raphylo(20) 
pruner <- new_aphylo_pruner(x)

# Computing loglike
LogLike(
  pruner,
  psi  = c(.10, .20),
  mu_d = c(.90, .80),
  mu_s = c(.10, .05),
  Pi   = .05,
  eta  = c(.90, .80)
  )
#> $Pr
#> $Pr[[1]]
#>               [,1]         [,2]
#>  [1,] 8.000000e-02 6.400000e-01
#>  [2,] 8.100000e-01 1.800000e-01
#>  [3,] 8.000000e-02 6.400000e-01
#>  [4,] 8.000000e-02 6.400000e-01
#>  [5,] 8.100000e-01 1.800000e-01
#>  [6,] 8.100000e-01 1.800000e-01
#>  [7,] 8.100000e-01 1.800000e-01
#>  [8,] 8.000000e-02 6.400000e-01
#>  [9,] 8.000000e-02 6.400000e-01
#> [10,] 8.100000e-01 1.800000e-01
#> [11,] 8.000000e-02 6.400000e-01
#> [12,] 8.100000e-01 1.800000e-01
#> [13,] 8.100000e-01 1.800000e-01
#> [14,] 8.100000e-01 1.800000e-01
#> [15,] 8.100000e-01 1.800000e-01
#> [16,] 8.100000e-01 1.800000e-01
#> [17,] 8.100000e-01 1.800000e-01
#> [18,] 8.000000e-02 6.400000e-01
#> [19,] 8.000000e-02 6.400000e-01
#> [20,] 8.100000e-01 1.800000e-01
#> [21,] 1.495230e-06 1.370841e-07
#> [22,] 7.294213e-03 5.605371e-05
#> [23,] 2.157576e-04 3.338891e-04
#> [24,] 3.483204e-02 1.529906e-03
#> [25,] 2.498196e-02 8.095460e-04
#> [26,] 2.203039e-03 7.404912e-02
#> [27,] 5.126401e-02 4.916208e-03
#> [28,] 3.692722e-02 2.085558e-03
#> [29,] 5.580090e-01 4.473225e-02
#> [30,] 2.567260e-01 4.955609e-03
#> [31,] 5.580090e-01 4.473225e-02
#> [32,] 7.796932e-02 2.708167e-02
#> [33,] 5.580090e-01 4.473225e-02
#> [34,] 7.396559e-02 2.057495e-02
#> [35,] 3.869815e-03 1.271598e-01
#> [36,] 7.357709e-03 2.183259e-01
#> [37,] 1.015920e-01 1.294380e-01
#> [38,] 1.849600e-02 3.745440e-01
#> [39,] 1.015920e-01 1.294380e-01
#> 
#> 
#> $ll
#> [1] -13.45971
#> 
  
dist2root(pruner)
#>  [1] 4 5 5 6 4 6 3 3 6 4 6 4 3 5 4 5 6 6 5 4
get_postorder(pruner)
#>  [1]  0 18 10 17 37 35 34  7 25 12 15  5  8 38 31 13  1 28 27 24 22  3 16 36  2
#> [26] 33 14 26  6 23  9  4 32 19 11 30 29 21 20