Skip to content

Instantly share code, notes, and snippets.

View benwhalley's full-sized avatar

Ben Whalley benwhalley

  • Plymouth University
View GitHub Profile
mysim <- function(){
des <- expand.grid(
congruence=c(1,0),
cuedresp=c("L", "R", "None"),
trial=1:5,
block=1:10,
participant=1:20
)
samp <- des %>% rowwise() %>% mutate(y=rbinom(1,1,.03*congruence))
// simulated data
// y = depression, t=timepoint (1 to 3), therapist=therapistcluster, id=patient
// 3 level model: observations nested in people in therapists
mixed y t || therapist: t, nocons || id:, stddev
// same model (???) using stata bayesian model fit
bayesmh y i.id i.therapist i.therapist#c.t, likelihood(normal({var_residual})) noconstant ///
prior({y:_cons}, normal(0,100)) ///
prior({var_therapist}, igamma(.001, .001)) ///
participant__username | N
----------------------+----------
Alex_Fowke | 5
Carolyn_Hinds | 3
Donna_Rutherford | 4
Ellie_Campbell | 3
Hannah_Wilson | 0
Laura_Brummer | 5
Sandy_Waite | 5
Sara_Clark | 5
clear all
set seed 123
* recruit subjects (if only this easy...)
set obs 2000
* assign to groups
gen mbct = mod(_n, 2)
* depression baseline score