-
Notifications
You must be signed in to change notification settings - Fork 0
/
strbee_cscript.do
121 lines (103 loc) · 3.34 KB
/
strbee_cscript.do
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
cd c:\ado\ian\strbee
cap log close
log using strbee_cscript, text replace
/*
cscript for strbee
was in trtchg\strbee\ado\update2011
moved 12feb2018 to C:\ado\ian\strbee & updated
30may2018: added check that `gen' variables are non-missing
*/
pda
set more off
set trace off
set tracedepth 3
progver strbee
cscript strbee
set linesize 99
* Comparision of different syntaxes in Jack's data
* what is correct answer?
use example_data, clear
stset T event
gen cens = 40
strbee R, xo0(Toff) xo1(Ton) endstudy(cens) trace
local true = r(psi)
replace Ton = cond(R, min(Ton,T), T-min(Toff,T))
replace Toff = T - Ton
strbee R, xo0(Toff) xo1(Ton) endstudy(cens) trace
assert abs(r(psi) - (`true')) < 1E-5
gen double ton = cond(R, Ton, T-Toff)
gen double toff = cond(R, T - Ton, Toff)
strbee R, ton(ton) toff(toff) endstudy(cens) trace
assert abs(r(psi) - (`true')) < 1E-5
* Now in immdef data
use immdef, clear
stset progyrs prog
set seed 46806
gen x = rnormal()
gen stratum = runiform()<0.5
save z, replace
* Different analyses
strbee imm, graph(title(ITT analysis) name(zgraph_itt, replace)) debug
strbee imm, xo0(xoyrs xo)
strbee imm, xo0(xoyrs xo)
strbee imm, xo0(xoyrs xo) endstudy(cens)
local true -0.18116
assert abs(r(psi) - (`true')) < 1E-5
* Different tests
foreach test in stcox logrank wilcoxon tware peto "fh(1 1)" ///
exponential gompertz loglogistic weibull lognormal { // gamma fails to converge
dicmd strbee imm, xo0(xoyrs xo) endstudy(cens) test(`test') strata(stratum)
assert r(psi)>-0.25 & r(psi)<-0.15
}
* Check strbee doesn't change the data
cf _all using z
* Different estimation methods
strbee imm, psimin(-4) psimax(2) psistep(0.1) xo0(xoyrs xo) ///
endstudy(cens) savedta(zz, replace)
strbee imm, psimin(2) psimax(4) psistep(0.1) xo0(xoyrs xo) ///
endstudy(cens) savedta(zz, append)
strbee imm, ipe psistart(-1) xo0(xoyrs xo) endstudy(cens)
strbee imm, ipe ipecens psistart(-1) xo0(xoyrs xo) endstudy(cens)
* Many options
strbee imm, xo0(xoyrs xo) savedta(zz,replace) endstudy(cens) gen(u3) ///
zgraph(ytitle(Z statistic) title("Crossover-adjusted analysis, no recensoring") ///
name(zgraph_zz, replace)) ///
level(99.5) debug hr tol(6) maxiter(50) test(weibull) adjvars(x) strata(stratum) ///
kmgraph(title(KM graph) name(KMgraph, replace) showall ///
lpattern(dash dot) lcolor(green red blue))
assert !mi(u3,du3,cu3)
ret list
local psi=r(psi)
* Check saved results
strbee
assert `psi'==r(psi)
strbee using zz, list graph(title("Crossover-adjusted analysis, no recensoring") ///
name(zgraph_zz2, replace))
assert `psi'==r(psi)
* Debugging
strbee imm, xo0(xoyrs xo) endstudy(cens) trace
strbee imm, xo0(xoyrs xo) endstudy(cens) debug
* Check HR etc.: added 31mar2016
strbee imm, xo0(xoyrs xo) endstudy(cens) hr
local hr_ITT = r(HR_ITT)
local hr = r(HR_adj)
strbee def, xo1(xoyrs xo) endstudy(cens) hr
assert abs(`hr' - 1/r(HR_adj)) < 1E-6
strbee imm, xo0(xoyrs xo) endstudy(cens) hr psimult(2)
assert abs(`hr_ITT' - r(HR_ITT)) < 1E-6
gen ton = progyrs if imm
replace ton = 0 if def & !xo
replace ton = progyrs - xoyrs if def & xo
strbee imm, ton(ton) endstudy(cens) hr
assert abs(`hr' - r(HR_adj)) < 1E-6
strbee, hr(full untr)
assert abs(`hr' - r(HR_user)) < 1E-6
* Check data haven't been changed
drop u du cu ton
cf _all using z
* Tidy up
erase z.dta
erase zz.dta
erase _strbee_savedta.dta
di "*** strbee_cscript has run successfully ***"
log close