Skip to content

Instantly share code, notes, and snippets.

@puterleat
Created September 30, 2013 10:15
Show Gist options
  • Save puterleat/6761837 to your computer and use it in GitHub Desktop.
Save puterleat/6761837 to your computer and use it in GitHub Desktop.
analysis v.3
title make version
Analysis for ipod craving study
worksheet
3

Analysis for ipod craving study

Data structure

Craving strength data were structured such that each measurement represented a row in the dataset. For participants in the tetris condition, two measurements were taken after each prompt---before and after the game task. Control participants provided a single measure. Indulgence was also measured at each prompt for both groups,i.e. whether the participant had indulged a craving reported at the previous prompt.

Statistical methods

Craving strength data were analysed by mixed-effects regression, where craving scores were nested within individuals. In our primary analyses of data from the tetris group, fixed effects estimated the difference in craving strength before and after game completion. Secondary analyses i) included random effects for the game completion parameter, ii) explicitly modelled the covariance between the random intercept and this random slope; iii) stratified the effect of game completion as a function of craving type. In a final analysis we used multilevel growth curve models to estimate changes in baseline craving strength during the week as a function of group allocation: We compared craving strength immediately after each prompt between participants in the tetris and control conditions, estimating the effect of group allocation at day 1 and day 7.

Indulgence data---a binary variable indicating whether or not the participant had indulged their last-reported craving---were also analysed by mixed-effects regression, but using a logit-link function. All analyses were conditioned on current alcohol state self reports. Probability of indulgence was modelled as a function of game group assigment and, as before, growth-curve models estimated changes indulgence as a function of group over the week of treatment. For all analyses, marginal means and group-differences were computed using the delta-method; for logit models marginal probabilities were computed from the fixed effects only.

Data coding:

The following cleans up and codes data for analysis from the raw excel file:

import excel using "Full Data including cravings coded.xlsx", clear firstrow
renvars *, lower

* drop what we don't need
keep pno torq daycoded indulged alcohol strength cravingstrength secondarycoding timeslotnumber

* rename and label some variables
rename secondarycoding cravingcats
rename  pno  person
rename torq tetris
rename daycoded day
rename timeslotnu timeslot
rename strength strength_0
rename cravingstrength strength_1
lab def cravingcats 0   "not craving" 1   "addictive substances" 2   "food/drink" 3   "other"
lab values cravingcats cravingcats

sencode indulged, gen(_ind)
gen indulgednextime = .
replace indulgednextime = 1 if indulged == "Y"
replace indulgednextime = 0 if indulged == "N"


* patch up missing values and string codings of outcome
replace strength_0 = "0" if strength_0 == "Q6"
destring strength_*, force replace

gen STARTEDCRAVING = strength_0 == 0 & (strength_1 > 0 & strength_1 < .)
gen WASCRAVING = strength_0 != 0
gen COMPLETE = WASCRAVING if  strength_1 >= 0  & strength_1 < .


* have a look at the missing values:
tab2 WASCRAVING COMPLETE STARTEDCRAVING




bysort person day: gen n = _n
reshape long strength_ , i(person day n) j(after)
save for_analysis, replace

Results

Did playing tetris reduce momentary craving strength?

Multilevel regression of occasions where participants indicated they were craving indicated that game completion reduced craving strength by 12.4 points (95% CI = -20.125 to -4.724; see model 1 output). Followup analyses (see model 2) included a random slope for the effect of game completion, and the covariance of this variation in the treatment effect and participant-level residuals. The fixed effect of game completion was unchanged but we found significant variation in the effect of game completion between individuals (SD=12.516, 95% CI= 7.827 to 20.015) but no relationship between random slopes and intercepts (r=-0.327, 95% CI = -0.752 to 0.290). This indicates that the effect of game completion on craving strength did differ significantly between participants, and this variation is unlikely to be due to floor-effects whereby participants, whereby those with low mean craving strength experience diminishing returns from the intervention.

use for_analysis.dta, clear
keep if COMPLETE==1 & WASCRAVING==1 & STARTEDCRAVING == 0 & tetris == 1
xtmixed strength i.after  || person: ,
cap: use for_analysis.dta
keep if COMPLETE==1 & WASCRAVING==1 & STARTEDCRAVING == 0 & tetris == 1
xtmixed strength_ i.after  || person: after , cov(uns)

\clearpage

Did playing tetris reduce the propensity to indulge cravings?

Multilevel logistic regression (see model 3) indicated a trend for participants in the tetris group to indulge cravings less frequently than those in the control group (62% vs. 42%; $\delta=0.199$, 95% CI = -0.416 to 0.018; OR = 0.436). Current alcohol state was a significant risk for increased indulgence in this analysis (OR=2.409, 95% CI = 1.592 to 3.646).

use for_analysis.dta, replace
* note... use all the observations we can
xtmelogit indulgednextime i.tetris alcohol || person: , or
margins, dydx(tetris) predict(mu fixedonly)
margins tetris,  predict(mu fixedonly)

gen anyalcohol = alcohol > 1
xtmelogit indulgednextime i.tetris anyalcohol || person: , or

\clearpage

Was completing the game equally effective at reducing all craving types?

Adding indicators for which type of craving the participant was experiencing on each occasion to model one brought only a marginal improvement in model fit ($\chi^2(2) = 5.53$, $p = 0.0631$), but a post-hoc comparison indicated that cravings for addictive substances (nicotine, alcohol, caffeine) were reported as significantly stronger than cravings for food or drink ($\delta=6.245$, $p = 0.039$); however addictive cravings were not stronger than cravings for the 'other' category ($\delta=0.650$, $p = 0.864$).

Allowing for an interaction between craving type and the indicator for game completion did not significantly improve the model, $\chi^2(4)=6.51$, $p = 0.1642$, indicating that the effect of game completion did not differ between cravings for addictive substances, food and drink, or other cravings (e.g. sex or exercise).

cap: use for_analysis.dta, replace
keep if COMPLETE==1 & WASCRAVING==1 & STARTEDCRAVING == 0 & tetris == 1

* run a baseline model and store the estimates
xtmixed strength_  i.after  || person: ,
est store base

* add the main effect
xtmixed strength_  i.after i.cravingcats  || person: ,
est store maineffect
* run the pairwise comparisons of interest
contrast r.cravingcats
contrast a.cravingcats

* add the interaction and store again
xtmixed strength_  i.after##i.cravingcats  || person: ,
est store inter

* run the likelihood ratio tests to check for changes in model fit
lrtest base maineffect
lrtest base inter
lrtest maineffect inter

\clearpage

Did playing tetris reduce pre-game craving strength during the week of treatment?

Selecting only initial observations from each measurment occasion, for participants in both the tetris and control group, we compared strength of cravings across the week between groups. Results are plotted in Figure \ref{effectoftetrisonbaselinecravingsbyday}, and indicate that the groups did not differ in the strength of their initial craving ratings across the week.

Changes in strength of initial craving ratings across the study week, by group.\label{effectoftetrisonbaselinecravingsbyday}

use for_analysis.dta, replace
* only use the pre-game scores
keep if after == 0
xtmixed strength_  i.tetris i.day  || person: ,
est store maineffect
xtmixed strength_  i.tetris##i.day  || person: ,
lrtest maineffect .
margins day#tetris
marginsplot
graph export effectoftetrisonbaselinecravingsbyday.eps, replace
* we don't see an improvement adding categorical interactions

* Also, we can uncomment this line in advance of this analysis:
* keep if WASCRAVING==1
* but get a very similar result

\clearpage

Did the of the effect of game completion remain constant across the week of treatment?

Yes, although the SE for the estimate on day 7 was larger and the treatment efect failed to reach significance on this day; see Figure \ref{effectofgamecompletionacrosstheweek}.

Effect of game completion across the week.\label{effectofgamecompletionacrosstheweek}

use for_analysis.dta, replace
keep if COMPLETE==1 & WASCRAVING==1 & STARTEDCRAVING == 0 & tetris == 1
xtmixed strength_  i.after i.day  || person: ,
est store maineffect
xtmixed strength_  i.after##i.day  || person: ,
lrtest maineffect .

margins day, dydx(after)
marginsplot, yline(0)
graph export effectofgamecompletionacrosstheweek.eps, replace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment