Description Usage Arguments Value Examples
View source: R/eefAnalyticPerm_modified_05_02_2016.R
crtBayes
performs analysis of cluster randomised trial using multilevel model within the Bayesian framework
assuming vague priors.
1 |
formula |
specifies the model to be analysed. It is of the form form y ~ x1+x2 +..., where y is the outcome variable and X's are the predictors. |
random |
a string variable specifying the "clustering" variable as contained in the data. This must be put between quotes. For example, "school". |
intervention |
specifies the name of the intervention variable as appeared in formula. This must be put between quotes. For example "intervention" or "treatment" or "group".. |
nSim |
number of MCMC simulations to generate samples from full conditional posterior distributions. A minimum of 10,000 is recommended. |
data |
specifies data frame containing the data to be analysed. |
S3 mcpi
object; a list consisting of
Beta
. Estimates and confidence intervals for the predictors specified in the model.
It will be a slope for a continuous predictor and a mean difference for a dummy variable or a categorical predictor.
ES
. Effect size for the intervention effect.
covParm
. A vector of variance decomposition into between-variance (Schools), within-variance (Pupils) and total variance.
It also contains the intra-cluster correlation (ICC).
ProbES
. A maxtrix containing the probability of observing ES greater than a pre-specified value. First column is for within-variance, second column for between-variance and the third column for total-variance.
SchEffects
. Individual school effects at baseline.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | data(iwq)
########################################################
## Bayesian analysis of cluster randomised trials ##
########################################################
output <- crtBayes(Posttest~ Intervention+Prettest,
random="School",intervention="Intervention",
nSim=10000,data=iwq)
### Fixed effects
beta <- output$Beta
beta
### Effect size
ES1 <- output$ES
ES1
## Covariance matrix
covParm <- output$covParm
covParm
### random effects for schools
randOut <- output$"SchEffects"
randOut <- randOut[order(randOut$Estimate),]
barplot(randOut$Estimate,ylab="Deviations from Overall Average",
names.arg=randOut$Schools,las=2)
### Posterior probability given a fixed threshold
probES <- output$ProbES
str(probES )
plot(probES[,1] ,probES[,2],ylim=c(0,max(probES)),
ylab="Probability",cex.lab=1,cex.axis=1,
type="n", xlab=expression("Effect size" >= "x"),
cex=1)
lines(probES[,1],probES[,2],col="chartreuse3",cex=1.5,
lwd=1.5,lty=2)
lines(probES[,1],probES[,3],col="violetred",cex=1.5,
lwd=1.5,lty=3)
lines(probES[,1],probES[,4],col="cornflowerblue",cex=1.5,
lwd=1.5,lty=1)
points(probES[,1],probES[,2],col="chartreuse3",cex=1.5,
lwd=1.5,pch=7)
points(probES[,1],probES[,3],col="violetred",cex=1.5,
lwd=1.5,pch=1)
points(probES[,1],probES[,4],col="cornflowerblue",
cex=1.5,lwd=1.5,pch=12)
legend(0,0.4,legend=c("Within ","Between ","Total "),
lty=c(2,3,1),cex=1.5, pch=c(7,1,12),
col=c("chartreuse3","violetred","cornflowerblue"),
title="Variance Type")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.