--- title: "TreeBUGS: Advanced MPT Modeling" author: "Daniel W. Heck, Nina R. Arnold, & Denis Arnold" date: "`r Sys.Date()`" number_section: true output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{TreeBUGS: Advanced MPT Modeling} %\VignetteEngine{knitr::rmarkdown} \usepackage[utf8]{inputenc} --- ## Advanced MPT Modeling ### A) Including Continuous Covariates It is possible to sample and estimate correlations of continuous covariates (e.g., age) with the individual MPT parameters. Note that this does not influence the model estimates - the estimated MPT parameters are only used repeatedly to compute a correlation. In contrast, in the latent-trait MPT model, variables can also be included as predictors to account for interindividual variance in MPT parameters, which influences the parameter estimates: $$\theta_{is} = \Phi(\mu_s + \delta_i + \gamma_i X_i)$$ The following arguments are used to specify the desired covariance structure: * `covData`: Either a data frame or the path to a .csv data file (columns separated by commas `,`) hat contains the covariates * Rows: The order of individuals must be identical to the order in the frequency data (`data`) * Columns: Covariates must habe column names different from the parameters * TreeBUGS automatically samples all correlations of the theta parameters with the (continuous) covariates in `covData`. * `corProbit`: whether to correlate MPT parameters on the probability scale (default for beta MPT) or on the latent probit scale (default for latent-trait MPT) * `predStructure`: Which MPT parameters are predicted by which variables (only for latent-trait MPT)? Either a list or path to a text file in which the assignment of MPT parameters to covariates is coded as follows: * Syntax: `list("MPT parameter(s) ; covariate label(s)")` * For instance: `list("Do Dn ; IQ", "g ; age extraversion")` * Multiple combinations are included by separate entries in the list or by separate lines in the text file (redundant combinations are removed automatically) * No correlations are sampled for variables that serve as predictor Overall, the code could look like this: ```{r, eval=F} fitMPT <- traitMPT( eqnfile = "2htm.txt", data = "data_ind.csv", restrictions = list("Dn=Do", "g=.5"), covData = "data_covariates.csv", corProbit = TRUE, predStructure = list("Do ; IQ"), # IQ as predictor for Do=Dn ... ) ``` After fitting the model, the results are summarized by `summary(fitMPT)`. ### B) Including Discrete Factors in a Latent-Trait MPT Model In the latent-trait model, it is possible to include discrete factors as predictor variables, similar as in the general linear model formulation of an ANOVA. Compared to continuous covariates only the following changes: * New argument `predType`, which is a character vector that assignes each column in `covData` a specific type (i.e., how it is used in `predStructure`). Specifically, predictor variables can be set as * continuous (`"c"`) * discrete fixed effect (`"f"`) * discrete random effect (`"r"`) * `covData` can have columns with character or factor variables (numeric columns can be specified as factors using `predType`) * By default, character variables in `covData` are included as fixed effects * The order of `predType` has to match the column order of `covData` Note that the same parameter covariance structure is assumed in each group. Given that this assumtion holds, it might result in more reliable parameter estimates than specifying a separate MPT tree for each condition (and thus assuming a separate parameter covariance matrix in each group). An example might be: ```{r, eval = FALSE} fitMPT <- traitMPT( eqnfile = "2htm.txt", data = "data_ind.csv", covData = "data_covariates.csv", predStructure = list( "Do ; factor1", "Dn ; factor2" ), # discrete factors predType = c("c", "c", "f", "r") ) ``` Estimated group estimates for each parameter can be obtained by ```{r, eval=F} getGroupMeans(fitMPT) ``` Multiple factors can in principle be included, but currently it is not possible to include interactions. For an introduction to Bayesian ANOVA, see Rouder et al. (2012). ### C) Sampling Transformed Parameters The argument `transformedParameters` allows to sample parameters that result as some determinstic function of the estimated MPT parameters. This is helpful to test differences between two core MPT parameters or obtain reparameterized versions of the parameters (e.g., for testing order constraints). For instance, the difference between two MPT parameters can be computed using ```{r, eval=FALSE} transformedParameters <- list( "deltaG = G_1-G_2", # difference of parameters "G1_larger = G_1>G_2" ) # Bayesian p-value / testing order constraints ``` If the parameters are different, the 95% posterior interval of the parameter `deltaG` should exclude zero. Transformed parameters are also helpful if the model contains reparameterizations of order constraints. For instance, if $a