| Title: | Symbolic Central and Noncentral Moments of the Multivariate Normal Distribution |
|---|---|
| Description: | Symbolic central and non-central moments of the multivariate normal distribution. Computes a standard representation, LateX code, and values at specified mean and covariance matrices. |
| Authors: | Kem Phillips [aut], Florian Schuberth [aut, cre] (ORCID: <https://orcid.org/0000-0002-2110-9086>) |
| Maintainer: | Florian Schuberth <[email protected]> |
| License: | GPL |
| Version: | 1.2.2.9000 |
| Built: | 2026-05-28 06:56:29 UTC |
| Source: | https://github.com/floschuberth/symmoments |
Computes a multivariate normal moment by initializing variables, calling
multmoments, and constructing output.
callmultmoments(moment)callmultmoments(moment)
moment |
A vector |
Each row of the representation gives the exponents for a single
product of covariance terms. For example, (1, 2, 0) represents
, where the are the covariances.
The full moment is the sum of these terms multiplied by their respective
coefficients. If the sum of the exponents is odd, the moment is 0.
An object of class 'moment', which is a list with three
components:
moment: The input moment vector.
representation: A matrix containing the representation in
terms of upper-triangular matrices.
coefficients: The coefficients corresponding to the rows of
the representation.
If the sum of the exponents is odd, returns -1 and prints
"Sum of powers is odd. Moment is 0."
If any exponent is negative, returns -2 and prints
"All components of the moment must be non-negative."
If any exponent is not an integer, returns -3 and prints
"All components of the moment must be integers."
Kem Phillips [email protected]
Phillips K (2010). “R Functions to Symbolically Compute the Central Moments of the Multivariate Normal Distribution.” Journal of Statistical Software, 33(1), 1–14. doi:10.18637/jss.v033.c01.
multmoments, and the methods toLatex,
evaluate, and simulate in the symmoments
package.
# Compute the moment for the 4-dimensional moment c(1,2,3,4): m.1234 <- callmultmoments(c(1, 2, 3, 4))# Compute the moment for the 4-dimensional moment c(1,2,3,4): m.1234 <- callmultmoments(c(1, 2, 3, 4))
Converts an mpoly object to a simple list representation, or converts
a simple list representation back to an mpoly object.
convert.mpoly(poly)convert.mpoly(poly)
poly |
An |
The list representation consists of 2 components:
powers: A matrix where each row represents the exponents/powers
of for a single term in the multivariate polynomial.
coeff: A numeric vector where each element is the coefficient
for the corresponding row/term in powers.
If poly is of class 'mpoly', returns a list with two
components (powers and coeff). If poly is a list of this
form, returns the corresponding mpoly object.
Kem Phillips [email protected]
Phillips K (2010). “R Functions to Symbolically Compute the Central Moments of the Multivariate Normal Distribution.” Journal of Statistical Software, 33(1), 1–14. doi:10.18637/jss.v033.c01.
convert.multipol,
evaluate_expected.polynomial,
integrate.polynomial
## Not run: library(mpoly) # Create an mpoly object t0 <- mpoly::mpoly(list( c(coef = 3, x1 = 2), c(coef = 2, x1 = 1, x2 = 3), c(coef = -4, z = 2), c(coef = 1, x1 = 1, x2 = 2, z = 1) )) # Convert from mpoly to list representation t1 <- convert.mpoly(t0) # Convert from list representation back to an mpoly object t2 <- convert.mpoly(t1) ## End(Not run)## Not run: library(mpoly) # Create an mpoly object t0 <- mpoly::mpoly(list( c(coef = 3, x1 = 2), c(coef = 2, x1 = 1, x2 = 3), c(coef = -4, z = 2), c(coef = 1, x1 = 1, x2 = 2, z = 1) )) # Convert from mpoly to list representation t1 <- convert.mpoly(t0) # Convert from list representation back to an mpoly object t2 <- convert.mpoly(t1) ## End(Not run)
Converts a multipol object to a simple list representation, or converts
a simple list representation back to a multipol object.
convert.multipol(poly)convert.multipol(poly)
poly |
A |
The list representation consists of 2 components:
powers: A matrix where each row represents the exponents/powers
of for a single term in the multivariate polynomial.
coeff: A numeric vector where each element is the coefficient
for the corresponding row/term in powers.
If poly is of class 'multipol', returns a list with two
components (powers and coeff). If poly is a list of this
form, returns the corresponding multipol object.
Kem Phillips [email protected]
Phillips K (2010). “R Functions to Symbolically Compute the Central Moments of the Multivariate Normal Distribution.” Journal of Statistical Software, 33(1), 1–14. doi:10.18637/jss.v033.c01.
convert.mpoly,
evaluate_expected.polynomial,
integrate.polynomial
## Not run: library(mpoly) library(multipol) # Create an mpoly object to work with t0 <- mpoly::mpoly(list( c(coef = 3, x1 = 2), c(coef = 2, x1 = 1, x2 = 3), c(coef = -4, z = 2), c(coef = 1, x1 = 1, x2 = 2, z = 1) )) # Convert from mpoly to list representation t1 <- convert.mpoly(t0) # Convert from list representation to a multipol object t2 <- convert.multipol(t1) # Convert back to a list representation t3 <- convert.multipol(t2) ## End(Not run)## Not run: library(mpoly) library(multipol) # Create an mpoly object to work with t0 <- mpoly::mpoly(list( c(coef = 3, x1 = 2), c(coef = 2, x1 = 1, x2 = 3), c(coef = -4, z = 2), c(coef = 1, x1 = 1, x2 = 2, z = 1) )) # Convert from mpoly to list representation t1 <- convert.mpoly(t0) # Convert from list representation to a multipol object t2 <- convert.multipol(t1) # Convert back to a list representation t3 <- convert.multipol(t2) ## End(Not run)
Evaluate a Moment or Polynomial
evaluate(object, sigma)evaluate(object, sigma)
object |
An object of class |
sigma |
A numeric matrix representing the covariance matrix. |
The evaluated result.
Evaluates the expected value of a multivariate polynomial assuming a specified non-central multivariate normal distribution.
evaluate_expected.polynomial(poly, mu, sigma, envir = "symmoments")evaluate_expected.polynomial(poly, mu, sigma, envir = "symmoments")
poly |
An object of class |
mu |
A vector of real numbers representing the mean vector |
sigma |
A vector giving an upper-triangular matrix, stacked by row, representing the covariance matrix of the multivariate distribution. |
envir |
A character string specifying the environment containing the
central moments needed for the calculation. Defaults to |
This function searches the environment specified in the envir
argument for the central moments required to complete the expected value expansion.
The default is the symmoments environment. The computation will stop
with an error message if any required central moment is missing from envir.
The expected value of the multivariate polynomial evaluated at the specified multivariate normal mean and covariance matrix.
Kem Phillips [email protected]
Phillips K (2010). “R Functions to Symbolically Compute the Central Moments of the Multivariate Normal Distribution.” Journal of Statistical Software, 33(1), 1–14. doi:10.18637/jss.v033.c01.
evaluate_noncentral, make.all.moments
## Not run: library(mpoly) # Define an mpoly object for a multivariate polynomial and determine # its expected value at a specified mean and covariance matrix: # Note: All moments up to c(2,3,2) must exist in the symmoments environment. # Run make.all.moments(c(2,3,2)) beforehand if necessary. t0 <- mpoly(list( c(coef = 3, x1 = 2), c(coef = 2, x1 = 1, x2 = 3), c(coef = -4, z = 2), c(coef = 1, x1 = 1, x2 = 2, z = 1) )) evaluate_expected.polynomial(t0, c(1, 2, 3), c(1, 0, 0, 1, 0, 1)) ## End(Not run)## Not run: library(mpoly) # Define an mpoly object for a multivariate polynomial and determine # its expected value at a specified mean and covariance matrix: # Note: All moments up to c(2,3,2) must exist in the symmoments environment. # Run make.all.moments(c(2,3,2)) beforehand if necessary. t0 <- mpoly(list( c(coef = 3, x1 = 2), c(coef = 2, x1 = 1, x2 = 3), c(coef = -4, z = 2), c(coef = 1, x1 = 1, x2 = 2, z = 1) )) evaluate_expected.polynomial(t0, c(1, 2, 3), c(1, 0, 0, 1, 0, 1)) ## End(Not run)
Computes the numerical value of a non-central moment at a specified mean and specified covariance matrix.
evaluate_noncentral(moment, mu, sigma, envir = "symmoments")evaluate_noncentral(moment, mu, sigma, envir = "symmoments")
moment |
A vector of non-negative integers representing the
non-central moment to be evaluated: |
mu |
A vector of real numbers representing the mean vector |
sigma |
An upper-triangular matrix of covariance terms for the multivariate normal distribution, expressed as a vector stacked by row, at which the moment is to be evaluated. |
envir |
A character string specifying the environment containing the
central moments needed for the calculation. Defaults to |
This function searches the environment specified in the envir
argument for the central moments required to complete the non-central expansion.
The default is the symmoments environment. All even central moments
less than or equal to the requested moment vector must be present.
The computation will stop with an error message if any required central moment
is missing from envir.
The numeric value of the non-central moment evaluated at the specified mean and covariance matrix.
Kem Phillips [email protected]
Phillips K (2010). “R Functions to Symbolically Compute the Central Moments of the Multivariate Normal Distribution.” Journal of Statistical Software, 33(1), 1–14. doi:10.18637/jss.v033.c01.
evaluate.moment, make.all.moments
## Not run: # Evaluates the expected value of X1^3 X2 X3^2 at mean c(3,4,1) # and at the following covariance matrix: # 4 2 1 # 2 3 1 # 1 1 2 # Note: requires all central moments up to c(3,1,2) to exist in 'symmoments'. # If needed, run: make.all.moments(c(3,1,2)) evaluate_noncentral(c(3, 1, 2), c(3, 4, 1), c(4, 2, 1, 3, 1, 2)) # Using central moments stored instead in the global environment: evaluate_noncentral(c(3, 1, 2), c(3, 4, 1), c(4, 2, 1, 3, 1, 2), '.GlobalEnv') ## End(Not run)## Not run: # Evaluates the expected value of X1^3 X2 X3^2 at mean c(3,4,1) # and at the following covariance matrix: # 4 2 1 # 2 3 1 # 1 1 2 # Note: requires all central moments up to c(3,1,2) to exist in 'symmoments'. # If needed, run: make.all.moments(c(3,1,2)) evaluate_noncentral(c(3, 1, 2), c(3, 4, 1), c(4, 2, 1, 3, 1, 2)) # Using central moments stored instead in the global environment: evaluate_noncentral(c(3, 1, 2), c(3, 4, 1), c(4, 2, 1, 3, 1, 2), '.GlobalEnv') ## End(Not run)
Generic method for class moment to compute the numerical value of a
moment at a specified covariance matrix from the output of
callmultmoments.
## S3 method for class 'moment' evaluate(object, sigma)## S3 method for class 'moment' evaluate(object, sigma)
object |
An object of class |
sigma |
An upper-triangular matrix of covariance terms expressed as a vector at which the moment is to be evaluated. |
object is normally the output of a call to
callmultmoments. This is a list with the first component being
the moment itself, the second component being the set of upper-triangular
matrices representing the moment, and the third component containing their
corresponding coefficients. This is an object of class 'moment'.
The numeric value of the moment evaluated at the specified covariance matrix.
Kem Phillips [email protected]
Phillips K (2010). “R Functions to Symbolically Compute the Central Moments of the Multivariate Normal Distribution.” Journal of Statistical Software, 33(1), 1–14. doi:10.18637/jss.v033.c01.
callmultmoments, and the methods simulate
and toLatex from the symmoments package.
# Evaluates the moment at c(1,2,3,4) at the following covariance matrix: # 4 2 1 1 # 2 3 1 1 # 1 1 2 1 # 1 1 1 2 evaluate(callmultmoments(c(1, 2, 3, 4)), c(4, 2, 1, 1, 3, 1, 1, 2, 1, 2))# Evaluates the moment at c(1,2,3,4) at the following covariance matrix: # 4 2 1 1 # 2 3 1 1 # 1 1 2 1 # 1 1 1 2 evaluate(callmultmoments(c(1, 2, 3, 4)), c(4, 2, 1, 1, 3, 1, 1, 2, 1, 2))
Integrates a multivariate polynomial against a specified non-central
multivariate normal distribution using ordinary numerical integration via
the adaptIntegrate function from the cubature package.
integrate.polynomial(poly, mu, sigma, lower = NULL, upper = NULL)integrate.polynomial(poly, mu, sigma, lower = NULL, upper = NULL)
poly |
An object of class |
mu |
A numeric vector giving the mean vector |
sigma |
A square matrix specifying the covariance matrix of the multivariate normal distribution. |
lower |
A numeric vector of the lower limits of integration, containing
one element for each dimension. If |
upper |
A numeric vector of the upper limits of integration, containing
one element for each dimension. If |
Defaults for lower and upper boundaries are set to
times the standard deviations (the square roots of the diagonal
elements of the covariance matrix sigma).
If the polynomial is defined by a simple list, it must contain two components:
powers: A matrix where each row represents the exponents/powers
for a single term in the polynomial.
coeff: A numeric vector where each element is the coefficient
of the corresponding row in powers.
For example, the list structure equivalent to the polynomial in the examples section is:
list(coeff = c(3, 2, -4, 1), powers = matrix(c(2,0,0, 1,3,0, 0,0,2, 1,2,1), ncol = 3, byrow = TRUE))
The expected value of the polynomial numerically integrated against the specified multivariate normal distribution.
Kem Phillips [email protected]
Phillips K (2010). “R Functions to Symbolically Compute the Central Moments of the Multivariate Normal Distribution.” Journal of Statistical Software, 33(1), 1–14. doi:10.18637/jss.v033.c01.
evaluate_expected.polynomial, multmoments,
evaluate, simulate
## Not run: library(mpoly) # Define an mpoly object for a multivariate polynomial t0 <- mpoly(list( c(coef = 3, x1 = 2), c(coef = 2, x1 = 1, x2 = 3), c(coef = -4, z = 2), c(coef = 1, x1 = 1, x2 = 2, z = 1) )) # Numerically integrate against a specified mean and covariance identity matrix integrate.polynomial(t0, c(1, 2, 3), matrix(c(1,0,0, 0,1,0, 0,0,1), nrow = 3, byrow = TRUE)) ## End(Not run)## Not run: library(mpoly) # Define an mpoly object for a multivariate polynomial t0 <- mpoly(list( c(coef = 3, x1 = 2), c(coef = 2, x1 = 1, x2 = 3), c(coef = -4, z = 2), c(coef = 1, x1 = 1, x2 = 2, z = 1) )) # Numerically integrate against a specified mean and covariance identity matrix integrate.polynomial(t0, c(1, 2, 3), matrix(c(1,0,0, 0,1,0, 0,0,1), nrow = 3, byrow = TRUE)) ## End(Not run)
Create all central moment objects of a specified or smaller size in the
symmoments environment.
make.all.moments(moment, verbose = TRUE)make.all.moments(moment, verbose = TRUE)
moment |
A vector |
verbose |
If |
Unsorted moments (those whose exponents are not in numeric order)
are created in the symmoments environment using the
tounsorted function to transform them from their sorted counterpart.
If the symmoments environment does not exist, the user is prompted to
create it using symmoments <- new.env().
If a sorted moment does not exist, it is automatically created.
Moments of lower dimension are not created; for example, if c(2, 4) is
input, m20 is created, but m2 is not.
Naming Conventions:
Moments are named using the structure mij..l, e.g., m136.
If any exponent is greater than 9, lowercase letters, and then
uppercase letters are used. For example, m3bA represents the
moment c(3, 11, 36).
The largest single exponent allowed by this alphanumeric encoding
scheme is .
If an object with a name of this form already exists in the target environment
but is not an object of class "moment", it will be silently overwritten
by the new moment object.
All objects of class 'moment' up to the value given in
moment are created in the environment symmoments.
Kem Phillips [email protected]
Phillips K (2010). “R Functions to Symbolically Compute the Central Moments of the Multivariate Normal Distribution.” Journal of Statistical Software, 33(1), 1–14. doi:10.18637/jss.v033.c01.
## Not run: # Create the symmoments environment if it does not exist symmoments <- new.env() # Compute all moments up to c(3,3) make.all.moments(c(3, 3)) ## End(Not run)## Not run: # Create the symmoments environment if it does not exist symmoments <- new.env() # Compute all moments up to c(3,3) make.all.moments(c(3, 3)) ## End(Not run)
Prints an object of class 'moment'.
## S3 method for class 'moment' print(x, ...)## S3 method for class 'moment' print(x, ...)
x |
An object of class |
... |
Included only for consistency with the generic function. |
Prints the moment as E[X1**k1 X2**k2 ...]: followed by
the lines of the representation matrix with the corresponding coefficient
attached to each row.
Kem Phillips [email protected]
Phillips K (2010). “R Functions to Symbolically Compute the Central Moments of the Multivariate Normal Distribution.” Journal of Statistical Software, 33(1), 1–14. doi:10.18637/jss.v033.c01.
print(callmultmoments(c(1, 2, 3)))print(callmultmoments(c(1, 2, 3)))
Computes a multivariate normal moment by Monte Carlo integration.
## S3 method for class 'moment' simulate(object, nsim, seed = NULL, Mean, Sigma, ...)## S3 method for class 'moment' simulate(object, nsim, seed = NULL, Mean, Sigma, ...)
object |
An object of class |
nsim |
The number of samples to generate in computing the integral. |
seed |
An integer for the random number generator ( |
Mean |
The mean vector of |
Sigma |
Covariance matrix of |
... |
Included only for consistency with the generic function. |
An approximate numerical value of the specified moment.
Non-central moments can be approximated by specifying Mean.
For central moments, set Mean to a vector of zeros.
The mvtnorm package must be installed for this function to utilize
rmvnorm.
Kem Phillips [email protected]
Rizzo ML (2008). Statistical Computing with R, 1st edition. Chapman & Hall/CRC, Boca Raton.
callmultmoments, and the methods toLatex
and evaluate.
# Using 10000 samples, estimate the central moment for the moment c(2,4) # at the specified covariance matrix and mean (0,0): library(mvtnorm) simulate(callmultmoments(c(2, 4)), 10000, NULL, c(0, 0), c(2, 1, 1, 4))# Using 10000 samples, estimate the central moment for the moment c(2,4) # at the specified covariance matrix and mean (0,0): library(mvtnorm) simulate(callmultmoments(c(2, 4)), 10000, NULL, c(0, 0), c(2, 1, 1, 4))
Computes a LaTeX expression for a non-central multivariate normal moment.
toLatex_noncentral(moment, envir = "symmoments")toLatex_noncentral(moment, envir = "symmoments")
moment |
A vector |
envir |
A character string specifying the environment that contains
the required central moments. Defaults to |
All required central moment objects must already exist in the
specified environment (the default is 'symmoments'). However, if only
the sorted version of an unsorted moment exists in that environment, the
tounsorted function will automatically be called to transform
and obtain it.
A character string giving the LaTeX representation of the non-central
moment where follows a multivariate normal distribution.
Kem Phillips [email protected]
Phillips K (2010). “R Functions to Symbolically Compute the Central Moments of the Multivariate Normal Distribution.” Journal of Statistical Software, 33(1), 1–14. doi:10.18637/jss.v033.c01.
make.all.moments, tounsorted,
callmultmoments, and the method toLatex.
## Not run: # Compute the LaTeX representation of the 2-dimensional non-central moment c(1,3). # Note: This requires that all central moments up to c(1,3) have already been # generated in the symmoments environment using make.all.moments. toLatex_noncentral(c(1, 3)) ## End(Not run)## Not run: # Compute the LaTeX representation of the 2-dimensional non-central moment c(1,3). # Note: This requires that all central moments up to c(1,3) have already been # generated in the symmoments environment using make.all.moments. toLatex_noncentral(c(1, 3)) ## End(Not run)
Computes a LaTeX representation sorted lexicographically of an object of
class 'moment'.
## S3 method for class 'moment' toLatex(object, ...)## S3 method for class 'moment' toLatex(object, ...)
object |
An object of class |
... |
Included only for consistency with the generic function. |
The first element of the result is the moment expressed as an
expected value (E[...] =). The remaining lines are the LaTeX
representation broken at appropriate intervals for printing. (Individual
terms for high dimensions will still overrun a printed line.)
Double backslashes (\\) are inserted where LaTeX requires a
backslash. These can be reset to single backslashes by writing the output
to a file using the standard R function writeLines.
A character vector giving the LaTeX code for the symbolic moment.
Kem Phillips [email protected]
Phillips K (2010). “R Functions to Symbolically Compute the Central Moments of the Multivariate Normal Distribution.” Journal of Statistical Software, 33(1), 1–14. doi:10.18637/jss.v033.c01.
callmultmoments, and the evaluate method.
toLatex(callmultmoments(c(1, 2, 3)))toLatex(callmultmoments(c(1, 2, 3)))
Converts a tree structure represented in a moment format into an ape
matching format structure.
toMatching(L, type = NULL, tip.label = NULL)toMatching(L, type = NULL, tip.label = NULL)
L |
The input tree structure. This can be an |
type |
A character string, either |
tip.label |
A character vector containing custom labels for the tips. If |
An L-matrix object is a list containing the following 5 components:
L: The L-matrix in full square form.
L.ut: The L-matrix in reduced upper-triangular form.
Newick: The Newick string representation of the tree structure.
tip.label: A character vector of the tip labels.
tip.label.n: An integer specifying the total number of tips.
A matching representation of the phylogenetic tree corresponding to the input.
The output list is assigned the class 'L-matching', which contains 5 components
including the tree in matching format.
Kem Phillips [email protected]
Phillips K (2010).
“R Functions to Symbolically Compute the Central Moments of the Multivariate Normal Distribution.”
Journal of Statistical Software, 33(1), 1–14.
doi:10.18637/jss.v033.c01.
Diaconis PW, Holmes SP (1998).
“Matchings and phylogenetic trees.”
Proceedings of the National Academy of Sciences, 95(25), 14600–14602.
doi:10.1073/pnas.95.25.14600.
# Create a Newick character string exam.Newick <- "(((a,b),c),d);" # Convert to a moment L-matrix exam.moment <- toMoment(exam.Newick) # Convert to matching format exam.matching <- toMatching(exam.moment)# Create a Newick character string exam.Newick <- "(((a,b),c),d);" # Convert to a moment L-matrix exam.moment <- toMoment(exam.Newick) # Convert to matching format exam.matching <- toMatching(exam.moment)
Converts a phylogenetic tree from a Newick character string or an ape
matching matrix into a moment L-matrix object.
toMoment(inputobject, tip.label = NULL)toMoment(inputobject, tip.label = NULL)
inputobject |
A tree structure represented as a Newick format character
string, or a |
tip.label |
A character vector specifying rearranged labels for the
tips. If provided, these must be the original tip labels. Defaults to |
The returned L-matrix class object consists of 5 internal components:
L: The L-matrix represented in full square form.
L.ut: The L-matrix represented in upper-triangular form.
Newick: The Newick string representation of the tree structure.
tip.label: A character vector holding the labels of the tips.
tip.label.n: An integer specifying the total number of tips.
A moment L-matrix object corresponding to the input phylogenetic tree object.
Kem Phillips [email protected]
Phillips K (2010).
“R Functions to Symbolically Compute the Central Moments of the Multivariate Normal Distribution.”
Journal of Statistical Software, 33(1), 1–14.
doi:10.18637/jss.v033.c01.
Felsenstein, J. (1990). The Newick tree format.
http://evolution.genetics.washington.edu/phylip/newicktree.html
Diaconis PW, Holmes SP (1998).
“Matchings and phylogenetic trees.”
Proceedings of the National Academy of Sciences, 95(25), 14600–14602.
doi:10.1073/pnas.95.25.14600.
# Create a Newick character string exam.Newick <- "(((a,b),c),d);" # Convert to a moment L-matrix exam.moment <- toMoment(exam.Newick) # Convert to a matching object exam.matching <- toMatching(exam.moment) # Convert back to a moment object backto.moment <- toMoment(exam.matching)# Create a Newick character string exam.Newick <- "(((a,b),c),d);" # Convert to a moment L-matrix exam.moment <- toMoment(exam.Newick) # Convert to a matching object exam.matching <- toMatching(exam.moment) # Convert back to a moment object backto.moment <- toMoment(exam.matching)
Converts a tree structure represented in a moment format back into a Newick format string.
toNewick(L, type = NULL, tip.label = NULL)toNewick(L, type = NULL, tip.label = NULL)
L |
The input tree structure. This can be an |
type |
A character string, either |
tip.label |
A character vector containing custom labels for the tips. If |
An L-matrix object is a list containing the following 5 components:
L: The L-matrix in full square form.
L.ut: The L-matrix in reduced upper-triangular form.
Newick: The Newick string representation of the tree structure.
tip.label: A character vector of the tip labels.
tip.label.n: An integer specifying the total number of tips.
A character string representing the Newick format of the phylogenetic tree corresponding
to the input. The output list is assigned the class 'L-Newick', which contains 5 components
including the tree string.
Kem Phillips [email protected]
Phillips K (2010).
“R Functions to Symbolically Compute the Central Moments of the Multivariate Normal Distribution.”
Journal of Statistical Software, 33(1), 1–14.
doi:10.18637/jss.v033.c01.
Felsenstein, J. (1990). The Newick tree format.
http://evolution.genetics.washington.edu/phylip/newicktree.html
Diaconis PW, Holmes SP (1998).
“Matchings and phylogenetic trees.”
Proceedings of the National Academy of Sciences, 95(25), 14600–14602.
doi:10.1073/pnas.95.25.14600.
# Create a Newick character string exam.Newick <- "(((a,b),c),d);" # Convert to a moment L-matrix exam.moment <- toMoment(exam.Newick) # Convert back to Newick format backto.Newick <- toNewick(exam.moment)# Create a Newick character string exam.Newick <- "(((a,b),c),d);" # Convert to a moment L-matrix exam.moment <- toMoment(exam.Newick) # Convert back to Newick format backto.Newick <- toNewick(exam.moment)
Produces an unsorted central moment object from a sorted object of class
'moment'.
tounsorted(moment, sorted.moment)tounsorted(moment, sorted.moment)
moment |
The unsorted target moment to obtain, specified in vector
form (e.g., |
sorted.moment |
A sorted object of class |
Unsorted moments are those whose exponents are not in sorted
numerical order (e.g., m312 vs m123). The unsorted moment's
representation is calculated by rearranging the rows and columns of the
sorted moment's matrices successively.
An object of class 'moment', which is a list containing the
following three components:
moment |
The input unsorted moment vector. |
representation |
A matrix containing the representation in terms of upper-triangular matrices, rearranged to match the target unsorted order. |
coefficients |
A numeric vector of the coefficients corresponding to the rows of the representation matrix. |
Kem Phillips [email protected]
#' Phillips K (2010). “R Functions to Symbolically Compute the Central Moments of the Multivariate Normal Distribution.” Journal of Statistical Software, 33(1), 1–14. doi:10.18637/jss.v033.c01.
# Obtain unsorted moment m312 from sorted base m123 tounsorted(c(3, 1, 2), callmultmoments(c(1, 2, 3)))# Obtain unsorted moment m312 from sorted base m123 tounsorted(c(3, 1, 2), callmultmoments(c(1, 2, 3)))