[R-sig-phylo] How to set state frequencies in ape: rTraitDisc

Alexandre Antonelli alexandre.antonelli at systbot.uzh.ch
Mon Feb 22 12:16:45 CET 2010

```Thanks Emmanuel for telling about the new ape function rTraitDisc. I
just cannot figure out how to set the frequencies of each state, so
that the simulated character eventually contains a fixed proportion of
each state. I would appreciate an example with four states.

q<-matrix(rbind(c(0, 0.2, 0.2, 0.2),
c(0, 0,   0.8, 0.2),
c(0, 0.8, 0,   0.2),
c(0, 0.2, 0.2, 0  )), 4);

rTraitDisc(tree, model=q, states=c("1","2","3","4"),root.value=1,
freq=???)

Thanks!

Alex

On 3 Feb 2010, at 18:39, Emmanuel Paradis wrote:

>  ape 2.5 (available on CRAN since yesterday) has a function
> rTraitDisc that does the same job. The diagonal of the rate matrix,
> if given, is always ignored. It's possible to specify Alexandre's
> model as:
>
> rTraitDisc(tree, k = 4, rate = 0.5)
>
> It's also possible to specify the equilibrium frequencies (assumed
> balanced by default). And if you're not happy with the traditional
> Markovian models, you can make your own model with an R function.
>
> Emmanuel
>
>>> Hi,
>>>
>>>   I am trying to use the function sim.char in geiger without
>>> success.  I would like to let a character (in this case 'species
>>> distribution',  with four states) evolve along a tree, and try
>>> different transition  costs in the matrix.
>>>
>>>  However, I don't manage to get more than one character with 2
>>> states. Any ideas what I am doing wrong? It is very unclear to me
>>> how  the transition matrix should be compiled (if columns/rows
>>> have to sum  up to one, etc). The manual indicated that the number
>>> of states per  character would be dependent on the size of the
>>> matrix, but that does  not seem to be the case.
>>>
>>>  These are the commands I used, and the transition matrix I
>>> intended  to apply:
>>>
>>> ## 0: Area A, 1:Area B, 2:Area C, 3:Area D
>>> ##
>>> ##        From     0    1    2    3
>>> ## To    0        -.5    .5    .5    .5
>>> ##        1        .5    -.5    .5    .5
>>> ##        2        .5    .5    -.5    .5   ##        3        .
>>> 5    .5    .5    -.5
>>>
>>>
>>> require (geiger)
>>>
>>>
>>> q<-list (rbind(    c(-.5, .5, .5, .5),
>>>        c(.5, -.5, .5, .5),
>>>        c(.5, .5, -.5, .5),
>>>        c(.5, .5, .5, -.5)))
>>>
>>> results<-sim.char(tree, q, model="discrete",n=2)
>>>
>>> ------
>>> Thanks for any help!
>>>
>>> Best wishes,
>>>
>>> Alex

Dr Alexandre Antonelli
Institute of Systematic Botany
Zollikerstrasse 107
CH 8008  Zürich
Switzerland
Phone: +41 (0)44 634 8416
Mobile: + 41 (0) 76 7345116
alexandre.antonelli at systbot.uzh.ch
http://www.systbot.uzh.ch/Personen/PostdoktorandInnen/AlexandreAntonelli.html

```