Description Usage Arguments Value Examples
View source: R/GuessInitVecParams.R
This is an S3 generic function that returns a
n
xPCMParamCount(o)
matrix of parameter vectors.
Implementations try to deduce parameter values based on the passed tree
and data, that should be suitable for starting points for likelihood
optimization or MCMC inference.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | GuessInitVecParams(
o,
regimes = as.character(PCMRegimes(o)),
oParent = o,
accessExpr = "",
n = 1L,
argsPCMParamLowerLimit = NULL,
argsPCMParamUpperLimit = NULL,
X = NULL,
tree = NULL,
SE = NULL,
tableAnc = NULL,
varyParams = FALSE,
returnWithinBoundsOnly = TRUE,
res = PCMParamRandomVecParams(o = oParent, k = PCMNumTraits(oParent), R =
PCMNumRegimes(oParent), n = n, argsPCMParamLowerLimit = argsPCMParamLowerLimit,
argsPCMParamUpperLimit = argsPCMParamUpperLimit),
...
)
|
o |
a PCM model object. |
regimes |
a vector of character strings denoting regimes in |
oParent |
a PCM model object. This argument has special usage in
S3 methods and should be left to its default setting ( |
accessExpr |
a character string. This argument has special usage in
S3 methods and should be left to its default setting ( |
n |
integer denoting the number of parameter vectors to generate. |
argsPCMParamLowerLimit, argsPCMParamUpperLimit |
lists of parameters
passed to |
X |
a |
tree |
a phylo object with N tips. |
SE |
a k x N matrix specifying the standard error for each measurement in
X. Alternatively, a k x k x N cube specifying an upper triangular k x k
factor of the variance covariance matrix for the measurement error
for each tip
Note that the above behavior is consistent with the treatment of the model
parameters |
tableAnc |
an ancestor table for tree. Default |
varyParams |
logical indicating if fixed (FALSE) or varying (TRUE)
parameter values should be returned for each of the |
returnWithinBoundsOnly |
logical indication if the returned parameter vectors should be within the lower and upper bound of the model. |
res |
an n x p matrix where p is the number of parameters in o. Internal use only. |
... |
additional arguments passed to implementations. Currently an N x N matrix argument named treeVCVMat can be passed which is equal to the phylogenetic covariance matrix for tree. |
an n x p matrix where p is the number of parameters in o.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | library(PCMBase)
library(PCMFit)
modelBM.ab <- modelBM.ab.Guess <- PCM(
PCMDefaultModelTypes()["B"], k = 2, regimes = c("a", "b"))
modelBM.ab$X0[] <- c(5, 2)
# in regime 'a' the traits evolve according to two independent BM
# processes (starting from the global vecto X0).
modelBM.ab$Sigma_x[,, "a"] <- rbind(c(1.6, 0.01),
c(0, 2.4))
# in regime 'b' there is a correlation between the traits
modelBM.ab$Sigma_x[,, "b"] <- rbind(c(2.4, 0.08),
c(0.0, 0.8))
modelOU.ab.Guess <- PCM(
PCMDefaultModelTypes()["F"], k = 2, regimes = c("a", "b"))
modelMG.ab.Guess <- MixedGaussian(
k = 2, modelTypes = MGPMDefaultModelTypes(),
mapping = c(
a = unname(MGPMDefaultModelTypes()["B"]),
b = unname(MGPMDefaultModelTypes()["F"])))
param <- double(PCMParamCount(modelBM.ab))
# load the current model parameters into param
PCMParamLoadOrStore(modelBM.ab, param, offset=0, load=FALSE)
print(param)
# make results reproducible
set.seed(2, kind = "Mersenne-Twister", normal.kind = "Inversion")
# number of regimes
R <- 2
# number of extant tips
N <- 100
tree.a <- PCMTree(ape::rtree(n=N))
PCMTreeSetLabels(tree.a)
PCMTreeSetPartRegimes(
tree.a, part.regime = c(`101` = "a"), setPartition = TRUE)
lstDesc <- PCMTreeListDescendants(tree.a)
splitNode <- names(lstDesc)[which(sapply(lstDesc, length) > N/2 &
sapply(lstDesc, length) < 2*N/3)][1]
tree.ab <- PCMTreeInsertSingletons(
tree.a, nodes = as.integer(splitNode),
positions = PCMTreeGetBranchLength(tree.a, as.integer(splitNode))/2)
PCMTreeSetPartRegimes(
tree.ab,
part.regime = structure(
c("a", "b"), names = as.character(c(N+1, splitNode))),
setPartition = TRUE)
traits <- PCMSim(tree.ab, modelBM.ab, modelBM.ab$X0)
likFunBM <- PCMCreateLikelihood(traits, tree.ab, modelBM.ab.Guess)
likFunOU <- PCMCreateLikelihood(traits, tree.ab, modelOU.ab.Guess)
likFunMG <- PCMCreateLikelihood(traits, tree.ab, modelMG.ab.Guess)
vecGuessBM <-
GuessInitVecParams(modelBM.ab.Guess, X = traits, tree = tree.ab)
vecGuessOU <-
GuessInitVecParams(modelOU.ab.Guess, X = traits, tree = tree.ab)
vecGuessMG <-
GuessInitVecParams(modelMG.ab.Guess, X = traits, tree = tree.ab)
# likelihood at true parameters used to generate the data
print(param)
likFunBM(param)
# likelihood at guessed parameter values for the BM model
print(vecGuessBM)
likFunBM(vecGuessBM)
# likelihood at guessed parameter values for the OU model
print(vecGuessOU)
likFunOU(vecGuessOU)
# likelihood at guessed parameter values for the BM model
print(vecGuessMG)
likFunMG(vecGuessMG)
# likelihood at completely random parameter values
vecRand <- PCMParamRandomVecParams(modelBM.ab.Guess, k = 2, R = 2)
likFunBM(vecRand)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.