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 formula: a symbolic description of the model to be fitted.

data_ctrl

An object of class data.frame (or one that can be coerced to that class) containing data of all variables used in the model for the control group.

data_sc

An object of class data.frame (or one that can be coerced to that class) containing data of all variables used in the model for the Single Case

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.

normal

a normal distribution with \mu = 0 and \sigma = 10

cauchy

a cauchy distribution with \mu = 0 and scale \sqrt{2}/2

student

a Student's T distribution, with \mu = 0, \nu = 3 and \sigma = 10

The normal distribution is the default.

The \sigma or scale parameters of the prior distributions can be modified by setting the dispersion parameter s.

s

is the dispersion parameter (standard deviation or scale) for the prior distribution.

If NULL (the default) and typeprior = "normal" or typeprior = "student" s = 10, otherwise, if typeprior = "cauchy" s = sqrt(2)/2.

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.

gaussian

the dependent variable is distributed along a Gaussian distribution, with identity link function

binomial

the dependent variable is distributed along a Binomial distribution, with logit link function

...

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)



[Package bmscstan version 1.2.1.0 Index]