--- title: "Getting started with the PCMBaseCpp R-package" date: '`r Sys.Date()`' output: rmarkdown::html_vignette: fig_caption: yes toc: true toc_depth: 3 vignette: > %\VignetteIndexEntry{Getting started} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set(echo = TRUE) ``` # How to use the package? There are two ways to use PCMBaseCpp: ## Passing the function `PCMInfoCpp` as a `metaI` argument of `PCMLik` and/or `PCMCreateLikelihood` ```{r} library(PCMBase) library(PCMBaseCpp) system.time(llR <- PCMLik( X = PCMBaseTestObjects$traits.ab.123, tree = PCMBaseTestObjects$tree.ab, model = PCMBaseTestObjects$model_MixedGaussian_ab)) system.time(llCpp <- PCMLik( X = PCMBaseTestObjects$traits.ab.123, tree = PCMBaseTestObjects$tree.ab, model = PCMBaseTestObjects$model_MixedGaussian_ab, metaI = PCMInfoCpp)) print(llR) print(llCpp) ``` ```{r} logLikFunR <- PCMCreateLikelihood( X = PCMBaseTestObjects$traits.ab.123, tree = PCMBaseTestObjects$tree.ab, model = PCMBaseTestObjects$model_MixedGaussian_ab) logLikFunCpp <- PCMCreateLikelihood( X = PCMBaseTestObjects$traits.ab.123, tree = PCMBaseTestObjects$tree.ab, model = PCMBaseTestObjects$model_MixedGaussian_ab, metaI = PCMInfoCpp) metaICpp <- PCMInfoCpp( X = PCMBaseTestObjects$traits.ab.123, tree = PCMBaseTestObjects$tree.ab, model = PCMBaseTestObjects$model_MixedGaussian_ab) logLikFunCpp2 <- PCMCreateLikelihood( X = PCMBaseTestObjects$traits.ab.123, tree = PCMBaseTestObjects$tree.ab, model = PCMBaseTestObjects$model_MixedGaussian_ab, metaI = metaICpp) set.seed(1, kind = "Mersenne-Twister", normal.kind = "Inversion") randParam <- PCMParamRandomVecParams(PCMBaseTestObjects$model_MixedGaussian_ab) system.time(llR <- logLikFunR(randParam)) system.time(llCpp <- logLikFunCpp(randParam)) system.time(llCpp2 <- logLikFunCpp2(randParam)) print(llR) print(llCpp) print(llCpp2) ``` ## Passing the meta-information object returned by `PCMInfoCpp` as a `metaI` argument of `PCMLik` and `PCMCreateLikelihood` This is the recommended usage in the case of multiple likelihood evaluations, e.g. during model inference: ```{r} metaIR <- PCMInfo( X = PCMBaseTestObjects$traits.ab.123, tree = PCMBaseTestObjects$tree.ab, model = PCMBaseTestObjects$model_MixedGaussian_ab) metaICpp <- PCMInfoCpp( X = PCMBaseTestObjects$traits.ab.123, tree = PCMBaseTestObjects$tree.ab, model = PCMBaseTestObjects$model_MixedGaussian_ab) system.time(llR <- PCMLik( X = PCMBaseTestObjects$traits.ab.123, tree = PCMBaseTestObjects$tree.ab, model = PCMBaseTestObjects$model_MixedGaussian_ab, metaI = metaIR)) system.time(llCpp <- PCMLik( X = PCMBaseTestObjects$traits.ab.123, tree = PCMBaseTestObjects$tree.ab, model = PCMBaseTestObjects$model_MixedGaussian_ab, metaI = metaICpp)) print(llR) print(llCpp) ``` ```{r} logLikFunR <- PCMCreateLikelihood( X = PCMBaseTestObjects$traits.ab.123, tree = PCMBaseTestObjects$tree.ab, model = PCMBaseTestObjects$model_MixedGaussian_ab, metaI = metaIR) logLikFunCpp <- PCMCreateLikelihood( X = PCMBaseTestObjects$traits.ab.123, tree = PCMBaseTestObjects$tree.ab, model = PCMBaseTestObjects$model_MixedGaussian_ab, metaI = metaICpp) system.time(llR <- PCMLik( X = PCMBaseTestObjects$traits.ab.123, tree = PCMBaseTestObjects$tree.ab, model = PCMBaseTestObjects$model_MixedGaussian_ab, metaI = metaIR)) system.time(llCpp <- PCMLik( X = PCMBaseTestObjects$traits.ab.123, tree = PCMBaseTestObjects$tree.ab, model = PCMBaseTestObjects$model_MixedGaussian_ab, metaI = metaICpp)) print(llR) print(llCpp) ```