BMSC {bmscstan} | R Documentation |
Fit Bayesian Multilevel Single Case models
Description
BMSC
fits the Bayesian Multilevel Single Case models.
Usage
BMSC(
formula,
data_ctrl,
data_sc,
cores = 1,
chains = 4,
iter = 4000,
warmup,
seed = NA,
typeprior = "normal",
s,
family = "gaussian",
...
)
Arguments
formula |
An object of class |
data_ctrl |
An object of class |
data_sc |
An object of class |
cores |
The number of cores to use when executing the Markov chains in parallel. The default is 1. |
chains |
Number of Markov chains (defaults to 4). |
iter |
Number of total iterations per chain (including warmup; defaults to 4000). |
warmup |
A positive integer specifying number of warmup (aka burnin) iterations. This also specifies the number of iterations used for stepsize adaptation, so warmup samples should not be used for inference. The number of warmup should not be larger than iter and the default is 2000. |
seed |
The seed for random number generation to make results reproducible. If NA (the default), Stan will set the seed randomly. |
typeprior |
Set the desired prior distribution for the fixed effects.
The normal distribution is the default. The |
s |
is the dispersion parameter (standard deviation or scale) for the prior distribution. If NULL (the default) and |
family |
a description of the response distribution to be used in this model. This is a character string naming the family. By default, a linear gaussian model is applied.
|
... |
further arguments to be passed to stan function. |
Value
a BMSC
object
Examples
# simulation of healthy controls data
Sigma.ctrl <- matrix(cbind(1, .7, .7, 1) ,nrow=2)
U <- t(chol(Sigma.ctrl))
numobs <- 100
set.seed(123)
random.normal <- matrix( rnorm( n = ncol(U) * numobs, mean = 3, sd = 1),
nrow = ncol(U), ncol = numobs)
X = U %*% random.normal
dat.ctrl <- as.data.frame(t(X))
names(dat.ctrl) <- c("y","x")
cor(dat.ctrl)
# simulation of patient data
Sigma.pt <- matrix(cbind(1, 0, 0, 1) ,nrow=2)
U <- t(chol(Sigma.pt))
numobs <- 20
set.seed(0)
random.normal <- matrix( rnorm( n = ncol(U) * numobs, mean = 3, sd = 1),
nrow = ncol(U), ncol = numobs)
X = U %*% random.normal
dat.pt <- as.data.frame(t(X))
names(dat.pt) <- c("y","x")
cor(dat.pt)
# fit the single case model
mdl.reg <- BMSC(y ~ x, data_ctrl = dat.ctrl, data_sc = dat.pt, seed = 10)
# posterior-predictive check of the model
pp_check(mdl.reg)
# summarize the results
summary(mdl.reg)
# plot the results
plot(mdl.reg)