Table of Contents

\tableofcontents

Phylogenetics R package

Phylogenetics R package


Phylogenetic Example

\footnotesize

library(aphylo)

# Loading and taking a look at the data
data("experiment")
head(experiment)
data("tree")
head(tree)

\normalsize


Phylogenetic Example (cont. 1)

\footnotesize

# Preparing the data 
O <- get_offspring(experiment, "LeafId", tree, "NodeId", "ParentId")
plot(O)

\normalsize


Phylogenetic Example (cont. 2)

\footnotesize

# Nice personalized plot
plot_LogLike(O, nlevels = 60, plotfun = persp, theta = -pi*20, 
  shade=.7, border="darkblue", phi=30, scale=TRUE, 
  par.args = list(mar=c(1, 1, 1, 1), oma=c(0,0,4,0)),
  ticktype = "detailed")

# Adding title
mtext(
  "LogLikelihood",
  side=3, outer=FALSE, line = 2, cex=1.25)

\normalsize


Phylogenetic Example (cont. 3)

\footnotesize

# Computing Estimating the parameters 
ans_nr  <- aphylo_mle(rep(.5,5), dat=O)
ans_abc <- aphylo_mle(rep(.5,5), dat=O, useABC = TRUE,
                     control = list(maxCycle = 50))
oldpar <- par(no.readonly = TRUE)
par(mfrow=c(1,2))
plot(ans_nr, main = "MLE using Newton-Raphson")
plot(ans_abc, main = "MLE using ABCoptim")
par(oldpar)

\normalsize


Phylogenetic Example (cont. 4)

\footnotesize

ans_w_prior <- aphylo_mle(rep(.5,5), dat=O, useABC = TRUE,
                     priors = function(pars) dbeta(pars[1:2], 2, 10),
                     control = list(maxCycle = 50))
plot(ans_w_prior, main = "MLE using Newton-Raphson\n With Beta(2,10) priors")

\normalsize

R Package to-do list

MCMC function

MCMC


MCMC example

\footnotesize

# Loading the package
library(aphylo)

# Simulating data
set.seed(1231)
n    <- 1e3
pars <- c(mean = 2.6, sd = 3)

# Generating data and writing the log likelihood function
D   <- rnorm(n, pars[1], pars[2])
fun <- function(pars) sum(log(dnorm(D, pars[1], pars[2])))

\normalsize


MCMC example (cont. 1)

\footnotesize

system.time(
ans <<- MCMC(
  fun     = fun,              # The log unormalized dens
  initial = c(mu=1, sigma=1), # Initial state (names are optional)
  nbatch  = 1e5,              # Number of steps
  burnin  = 1e3,              # Burn-in
  thin    = 20,               # Thinning
  scale   = .1,               # Scale of transition kernel
  ub      = 10,               # Upper bound (same for both params)
  lb      = c(-10, .5),       # Lower bound
  useCpp  = TRUE              # Request using the C++ version
  ))

\normalsize


MCMC example (cont. 2)

library(coda)
plot(ans)

MCMC example (cont. 3)

autocorr.plot(ans)

MCMC to-do list

\footnotesize

// Reflexion adjustment
for (int k=0; k<K; k++) {

  while( (ans[k] > ub[k]) | (ans[k] < lb[k]) ) {

    if (ans[k] > ub[k]) {
      ans[k] = 2.0*ub[k] - ans[k];
    } else {
      ans[k] = 2.0*lb[k] - ans[k];
    }  

  }

}

\normalsize



USCbiostats/aphylo documentation built on Oct. 28, 2023, 7:22 a.m.