write.morpho( M, filename, c, R, method, A, names, ages ) --> Writes an alignment file ready to be used in MCMCTree. It requires a matrix to be passed to M with the morphological continuous characters, either simulated or from real data (previously aligned with a PS analysis). The name for the output file needs to be specified in filename. If it is needed to correct for population variance, state the vector of population variances in c. Use R if M needs to be corrected for correlation (note that R needs to be invertible), and select the method ("chol" or "eigen") to decompose it. If the user has already decomposed R and has matrix A (the one used to transform M), then it can be used. Optional arguments are names and ages, in case the user has them.
sim.morpho( tree, n, c, R, ... ) --> Simulates n morphological continuous characters for a phylogeny given in tree. It wraps around rTraitCont to simulate the characters and the user can change the default values for rTraitCont inside sim.morpho by passing the corresponding arguments to be modified. The user can add population variance through c and correlation through R. Returns an object of class matrix with the n morphological continuous characters for the species specified in tree.
Added extra functions we discussed that would be good to have:
sim.pop( psample, n, c, R) --> Simulates a population matrix. Takes as arguments psample (number of specimens to include in the population), n (number of characters to be simulated), c (population variance to use in rnorm as), and R (optional adding correlation matrix).
calc.pop.cor( P, delta ) --> Estimates the shrunk correlation matrix from a population matrix. Takes as argument P (population matrix) and delta (shrinkage value). It returns a list with two items: (i) estimate of shrunk correlation matrix, (ii) population variance. These are the two objects needed in write.morpho when the user wants the alignment written in MCMCTree format.
NOTE: I thought that if the user generates a shrunk matrix that cannot be invertible (hence not used in write.morpho), something should be done to inform him/here. Therefore, this function throws a warning in this case suggesting the user to change the delta value. However, the R.shrunk matrix is generated.
Functions array2matrix and matrix2array were already defined, have not been implemented.
NEW DATA FILES
Directory data
All rda files that have been generated to be called in the examples sections and can be used by the user to test the functions.
Directory data-raw
All R files describing the process followed to generate the rda files from raw data so the users can understand how to process their raw data.
Directory inst
Updated raw data for canids (19 specimens) and Vulpes vulpes (21, remember Vulpes_5 was deleted as it caused problem).
Added a REFERENCES.bib file so all references that are going to be cited in the functions can be added there and then called in the roxygen comments.
Directory man
Files automatically generated by roxygen2. Contains manual for all the new created objects
Directory R
All R files to describe the objects saved in the data directory. The updated morpho.R is also here.
ADDED TESTS
The directory tests has been created with the tests I have thought that are interesting to have for the functions in morpho.R.
ADDED LINES IN DESCRIPTION
I added lines from 12 to 18 in the DESCRIPTION file. These lines define what needs to be imported (only ape and Rdpack, the latter is for references), suggested (testthat, for the tests), RdMacros (apparently Rdpack needs to load a macro), and dependency (I added R (>= 3.3.2), you can modify this if you want to).
CONSIDERATION FOR NAMESPACE
The NAMESPACE file in your morpho branch was generated with roxygen so I cannot modify it. I have the following lines in mine (good to know in case there is a problem when installing the package with the new functions)
FUNCTIONS IN R
Finished main functions inside
morpho.R
:write.morpho( M, filename, c, R, method, A, names, ages )
--> Writes an alignment file ready to be used in MCMCTree. It requires a matrix to be passed toM
with the morphological continuous characters, either simulated or from real data (previously aligned with a PS analysis). The name for the output file needs to be specified infilename
. If it is needed to correct for population variance, state the vector of population variances inc
. UseR
ifM
needs to be corrected for correlation (note that R needs to be invertible), and select themethod
("chol" or "eigen") to decompose it. If the user has already decomposedR
and has matrixA
(the one used to transformM
), then it can be used. Optional arguments arenames
andages
, in case the user has them.sim.morpho( tree, n, c, R, ... )
--> Simulatesn
morphological continuous characters for a phylogeny given intree
. It wraps aroundrTraitCont
to simulate the characters and the user can change the default values for rTraitCont inside sim.morpho by passing the corresponding arguments to be modified. The user can add population variance throughc
and correlation throughR
. Returns an object of class matrix with then
morphological continuous characters for the species specified intree
.Added extra functions we discussed that would be good to have:
sim.pop( psample, n, c, R)
--> Simulates a population matrix. Takes as argumentspsample
(number of specimens to include in the population),n
(number of characters to be simulated),c
(population variance to use inrnorm
as), andR
(optional adding correlation matrix).calc.pop.cor( P, delta )
--> Estimates the shrunk correlation matrix from a population matrix. Takes as argumentP
(population matrix) anddelta
(shrinkage value). It returns a list with two items: (i) estimate of shrunk correlation matrix, (ii) population variance. These are the two objects needed inwrite.morpho
when the user wants the alignment written in MCMCTree format. NOTE: I thought that if the user generates a shrunk matrix that cannot be invertible (hence not used inwrite.morpho
), something should be done to inform him/here. Therefore, this function throws a warning in this case suggesting the user to change thedelta
value. However, theR.shrunk
matrix is generated.Functions
array2matrix
andmatrix2array
were already defined, have not been implemented.NEW DATA FILES
Directory
data
All
rda
files that have been generated to be called in the examples sections and can be used by the user to test the functions.Directory
data-raw
All
R
files describing the process followed to generate therda
files from raw data so the users can understand how to process their raw data.Directory
inst
Updated raw data for canids (19 specimens) and Vulpes vulpes (21, remember Vulpes_5 was deleted as it caused problem). Added a
REFERENCES.bib
file so all references that are going to be cited in the functions can be added there and then called in the roxygen comments.Directory
man
Files automatically generated by roxygen2. Contains manual for all the new created objects
Directory
R
All
R
files to describe the objects saved in thedata
directory. The updatedmorpho.R
is also here.ADDED TESTS
The directory
tests
has been created with the tests I have thought that are interesting to have for the functions inmorpho.R
.ADDED LINES IN
DESCRIPTION
I added lines from 12 to 18 in the
DESCRIPTION
file. These lines define what needs to be imported (onlyape
andRdpack
, the latter is for references), suggested (testthat
, for the tests),RdMacros
(apparentlyRdpack
needs to load a macro), and dependency (I addedR (>= 3.3.2)
, you can modify this if you want to).CONSIDERATION FOR
NAMESPACE
The
NAMESPACE
file in yourmorpho
branch was generated with roxygen so I cannot modify it. I have the following lines in mine (good to know in case there is a problem when installing the package with the new functions)TO-DO
I am now working on vignettes, so people can do some examples with the
rda
objects already created. Hope you find this useful!