BTIME.RmdThe package BICAM uses
Bayesian hierarchical models to model abundance data for cell
populations with a predictor variable. This models each cell type
simultaneously while incorporating potential relationships between the
cell populations. The relationship utilized in this model is user
dependent based on the function inputs for setting up the covariance
structure. This package utilizes rjags and runjags
packages to run Gibbs sampling for posterior estimation.
Back to BTIME Repo: https://github.com/FridleyLab/BTIME
Before running this package, the JAGS (Just Another Gibbs Sampler) program needs to be installed. You can download from https://sourceforge.net/projects/mcmc-jags/files/.
library(BTIME)
dfmif <- read.csv('~/mIF_Test_Data.csv', check.names = FALSE) # Load in data
dat <- dfmif |> select(suid,total,stage,M1,M2,M3) # Construct data to match setup of image belowFor setting up your data, you will want to set your data into a data frame. The setup should be as follows:
1st column: Subject IDs
2nd column: Total Cell Counts
3rd column: Predictor Variable
Last M columns: Parameters of Interest Counts
Example:
Below we have “Sub. IDs” in the first column, “Total Cell Count” in the
second column,the stage of cancer (0 = “Low” (1 or 2), & 1 = “High”
(3 or 4)) as the predictor variable in the third column, and markers M1,
M2, and M3 in the last 3 columns (3 markers/parameters of interest).
Required inputs:
dat - Data frame containing data set constructed as shown
above
M - Number of parameters/markers of interest
adapt - Number of adaptation iterations for initializing JAGS
model (iterations removed from analysis)
burn - Number of burn-in iterations (iterations removed from
analysis)
it - Number of sampling iterations used for posterior
analysis
Optional inputs:
thin - Thinning Interval (default = 1)
ran_eff - 0 for NO repeated measurements, 1 FOR repeated
measurements (default = 1)
chains - Number of chains to run in the JAGS model (default =
4)
cores - Number of cores to use to run the JAGS model (default =
4) (must be
chains for maximum efficiency)
v0_mu_logit - Predicted proportion of the parameters of
interest (default = 0.01 —> 1%)
model - Covariance structure used in Bayesian model (default =
“Unstr”)
dis - Distance matrix used for exponential decay model
(required if using exp. decay model) (default = NULL)
tree - Tree-structured covariance matrix used for tree model
(required if using tree or scaled tree model) (default = NULL)
##################### Unstructured Model #####################
# posterior_unstr <- BICAM(dat = dat,
# M = 3,
# adapt = 2000,
# burn = 100,
# it = 100)
##################### Exponential Decay Model #####################
# WILL GET ERROR IF 'dis' MATRIX IS NOT SUPPLIED. 'dis' MUST ALSO BE INVERTIBLE.
# dis <- matrix(c(0,1,1,
# 1,0,2,
# 1,2,0),nrow = 3)
# posterior_expdecay <- BICAM(dat = dat,
# M = 3,
# adapt = 2000,
# burn = 100,
# it = 100,
# model = "ExpDecay",
# dis = dis)
##################### Tree Covariance Structure Model #####################
# WILL GET ERROR IF 'tree' MATRIX IS NOT SUPPLIED. 'tree' MUST ALSO BE INVERTIBLE.
# tree <- matrix(c(1,1,1,
# 1,2,1,
# 1,1,2),nrow = 3)
# posterior_tree <- BICAM(dat = dat,
# M = 3,
# adapt = 2000,
# burn = 100,
# it = 100,
# model = "Tree",
# tree = tree)
### Scaled Tree
# posterior_treescaled <- BICAM(dat = dat,
# M = 3,
# adapt = 2000,
# burn = 100,
# it = 100,
# model = "TreeScaled",
# tree = tree)The BTIME function returns a list of 6 items:
1 - Posterior samples for each monitored variable
2 - Computation time of entire function (not just sampling)
3 - String of the JAGS model based on function inputs
4 - Lists of initial values for each chain for each variable
5 - Data that was input into the JAGS model
6 - List of variables monitored by the JAGS model