Document 11612070

advertisement
---------------------------------------------------------------------------------------------------------------------log: F:\Courses\Stat_Epi\Korrelerte kategoriske data\Exercises, Answers.smcl
log type: smcl
opened on: 13 May 2008, 13:43:47
. * Correlated Categorical Data, Excercises, Answers
.
.
. * ----------------- Excercise 1 -----------------------------------------------------------------------------------.
. * Read in data (Note: the path must be changed)
. use "F:\Courses\Stat_Epi\Korrelerte kategoriske data\fat.dta", clear
.
. * General data description
. des
/* describe all variables */
Contains data from F:\Courses\Stat_Epi\Korrelerte kategoriske data\fat.dta
obs:
238
vars:
3
size:
6,664 (99.9% of memory free)
------------------------------------------------------------------------------storage display
value
variable name
type
format
label
variable label
------------------------------------------------------------------------------gender
double %10.0g
gender
Gender,
fatq
double %10.0g
Fat from questionnaire
fatd
double %10.0g
Fat from diary
------------------------------------------------------------------------------Sorted by:
. tab gender
/* table */
Gender, |
Freq.
Percent
Cum.
------------+----------------------------------Girl |
118
49.58
49.58
Boy |
120
50.42
100.00
------------+----------------------------------Total |
238
100.00
. sum fatq fatd
/* summarize */
Variable |
Obs
Mean
Std. Dev.
Min
Max
-------------+-------------------------------------------------------fatq |
238
.3033645
.055127
.1053155
.4391133
fatd |
238
.3003239
.0535598
.1622395
.4692187
. twoway (kdensity fatq, color(red))(kdensity fatd, color(blue)), xline(0.25 0.35)
com
> paring distributions */
. twoway (scatter fatq fatd) (function y=x, range(0.1 0.5)), legend(off)ytitle("fatq")xtitle("fatd")
values */
.
. * a) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
. * Make categorical variables: 2 categories coded 0 and 1
. gen fatq2=(fatq>=0.25 & fatq<=0.35)
/* generate 2 categories */
. gen fatd2=(fatd>=0.25 & fatd<=0.35)
. tab1 fatq2 fatd2
-> tabulation of fatq2
fatq2 |
Freq.
Percent
Cum.
------------+----------------------------------0 |
80
33.61
33.61
1 |
158
66.39
100.00
------------+----------------------------------Total |
238
100.00
-> tabulation of fatd2
fatd2 |
Freq.
Percent
Cum.
------------+----------------------------------0 |
90
37.82
37.82
1 |
148
62.18
100.00
------------+----------------------------------Total |
238
100.00
.
/* one way table */
/*
/* comparing
. * Do the methods measure the same?
. symmetry fatq2 fatd2 if gender==1
/* McNemar for boys */
------------------------------|
fatd2
fatq2 |
0
1
Total
----------+-------------------0 |
11
27
38
1 |
34
46
80
|
Total |
45
73
118
------------------------------chi2
df
Prob>chi2
-----------------------------------------------------------------------Symmetry (asymptotic)
|
0.80
1
0.3701
Marginal homogeneity (Stuart-Maxwell) |
0.80
1
0.3701
-----------------------------------------------------------------------. symmetry fatq2 fatd2 if gender==2
/* McNemar for girls */
------------------------------|
fatd2
fatq2 |
0
1
Total
----------+-------------------0 |
13
29
42
1 |
32
46
78
|
Total |
45
75
120
------------------------------chi2
df
Prob>chi2
-----------------------------------------------------------------------Symmetry (asymptotic)
|
0.15
1
0.7009
Marginal homogeneity (Stuart-Maxwell) |
0.15
1
0.7009
-----------------------------------------------------------------------.
.
. * b) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
.
. * Make categorical variables: 3 categories coded 0, 1 and 2
. gen fatq3=(fatq>=0.25) + (fatq>0.35)
/* generate 3 categories, coded 0, 1, 2 */
. gen fatd3=(fatd>=0.25) + (fatd>0.35)
. tab1 fatq3 fatd3
-> tabulation of fatq3
fatq3 |
Freq.
Percent
Cum.
------------+----------------------------------0 |
31
13.03
13.03
1 |
158
66.39
79.41
2 |
49
20.59
100.00
------------+----------------------------------Total |
238
100.00
-> tabulation of fatd3
fatd3 |
Freq.
Percent
Cum.
------------+----------------------------------0 |
45
18.91
18.91
1 |
148
62.18
81.09
2 |
45
18.91
100.00
------------+----------------------------------Total |
238
100.00
.
. * Do the methods measure the same?
. symmetry fatq3 fatd3 if gender==1
/* McNemar for boys */
-------------------------------------|
fatd3
fatq3 |
0
1
2
Total
----------+--------------------------0 |
2
11
1
14
1 |
20
46
14
80
2 |
3
16
5
24
|
Total |
25
73
20
118
-------------------------------------chi2
df
Prob>chi2
-----------------------------------------------------------------------Symmetry (asymptotic)
|
3.75
3
0.2902
Marginal homogeneity (Stuart-Maxwell) |
3.68
2
0.1587
-----------------------------------------------------------------------. symmetry fatq3 fatd3 if gender==2
/* McNemar for girls */
-------------------------------------|
fatd3
fatq3 |
0
1
2
Total
----------+--------------------------0 |
6
9
2
17
1 |
14
46
18
78
2 |
0
20
5
25
|
Total |
20
75
25
120
-------------------------------------chi2
df
Prob>chi2
-----------------------------------------------------------------------Symmetry (asymptotic)
|
3.19
3
0.3629
Marginal homogeneity (Stuart-Maxwell) |
0.36
2
0.8347
-----------------------------------------------------------------------.
.
.
. * ----------------- Excercise 2 -----------------------------------------------------------------------------------. * Read in data (Note: the path must be changed)
. use "F:\Courses\Stat_Epi\Korrelerte kategoriske data\spytt.dta", clear
. des
Contains data from F:\Courses\Stat_Epi\Korrelerte kategoriske data\spytt.dta
obs:
50
vars:
3
size:
1,400 (99.9% of memory free)
------------------------------------------------------------------------------storage display
value
variable name
type
format
label
variable label
------------------------------------------------------------------------------ID
double %10.0g
A
double %10.0g
B
double %10.0g
------------------------------------------------------------------------------Sorted by:
.
. * a) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
. tab1 A B
/* One-way tables */
-> tabulation of A
A |
Freq.
Percent
Cum.
------------+----------------------------------0 |
18
36.00
36.00
1 |
32
64.00
100.00
------------+----------------------------------Total |
50
100.00
-> tabulation of B
B |
Freq.
Percent
Cum.
------------+----------------------------------0 |
28
56.00
56.00
1 |
22
44.00
100.00
------------+----------------------------------Total |
50
100.00
. scalar p1=0.64
. scalar p2=0.44
. scalar dp=p1-p2
/* difference in proportion */
. scalar n1=50
. scalar n2=50
.
. * Standard error for the difference in proportion assuming independence between A and B
. scalar se1=sqrt(p1*(1-p1)/n1+p2*(1-p2)/n2)
. dis se1
/* display the standard error */
.09765244
. dis dp-1.96*se1
.00860121
/* lower confidence interval */
. dis dp+1.96*se1
.39139879
/* upper confidence interval */
.
.
. * b) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
. * Standard error for the difference in proportion taking dependence between A and B into account
. tab A B
/* crosstable */
|
B
A |
0
1 |
Total
-----------+----------------------+---------0 |
16
2 |
18
1 |
12
20 |
32
-----------+----------------------+---------Total |
28
22 |
50
. scalar n=50
. scalar se2=sqrt(p1*(1-p1)/n+p2*(1-p2)/n-2*(16*20-2*12)/n^3)
. dis se2
.06928203
/* display the standard error */
. dis dp-1.96*se2
.06420722
/* lower confidence interval */
. dis dp+1.96*se2
.33579278
/* upper confidence interval */
.
. symmetry A B
/* McNemar: proportion positive tests the same? */
------------------------------|
B
A |
0
1
Total
----------+-------------------0 |
16
2
18
1 |
12
20
32
|
Total |
28
22
50
------------------------------chi2
df
Prob>chi2
-----------------------------------------------------------------------Symmetry (asymptotic)
|
7.14
1
0.0075
Marginal homogeneity (Stuart-Maxwell) |
7.14
1
0.0075
-----------------------------------------------------------------------.
.
. * ----------------- Excercise 3 -----------------------------------------------------------------------------------. * Read in data (Note: the path must be changed)
. use "F:\Courses\Stat_Epi\Korrelerte kategoriske data\bbd11.dta", clear
. des
/* describe all variables */
Contains data from F:\Courses\Stat_Epi\Korrelerte kategoriske data\bbd11.dta
obs:
100
vars:
6
size:
5,200 (99.9% of memory free)
------------------------------------------------------------------------------storage display
value
variable name
type
format
label
variable label
------------------------------------------------------------------------------str
double %10.0g
case
double %10.0g
case
agmt
double %10.0g
higd
double %10.0g
exp
double %10.0g
exp
Går regelmessig til lege
agp
double %10.0g
------------------------------------------------------------------------------Sorted by:
.
.
.
.
. * a ) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
. * This analysis assumes wide data
. list if str<5, sepby(str)
/* data is in long format */
1.
2.
3.
4.
5.
6.
7.
8.
+------------------------------------------+
| str
case
agmt
higd
exp
agp |
|------------------------------------------|
|
1
kasus
39
9
nei
23 |
|
1
kontroll
39
11
ja
20 |
|------------------------------------------|
|
2
kasus
38
14
nei
. |
|
2
kontroll
38
9
ja
19 |
|------------------------------------------|
|
3
kasus
38
9
nei
22 |
|
3
kontroll
38
15
nei
19 |
|------------------------------------------|
|
4
kasus
38
15
nei
24 |
|
4
kontroll
38
12
ja
23 |
+------------------------------------------+
. reshape wide exp agmt higd agp, i(str) j(case)
(note: j = 0 1)
/* reshape to wide */
Data
long
->
wide
----------------------------------------------------------------------------Number of obs.
100
->
50
Number of variables
6
->
9
j variable (2 values)
case
->
(dropped)
xij variables:
exp
->
exp0 exp1
agmt
->
agmt0 agmt1
higd
->
higd0 higd1
agp
->
agp0 agp1
----------------------------------------------------------------------------. list if str<5
1.
2.
3.
4.
+-----------------------------------------------------------------+
| str
agmt0
higd0
exp0
agp0
agmt1
higd1
exp1
agp1 |
|-----------------------------------------------------------------|
|
1
39
11
ja
20
39
9
nei
23 |
|
2
38
9
ja
19
38
14
nei
. |
|
3
38
15
nei
19
38
9
nei
22 |
|
4
38
12
ja
23
38
15
nei
24 |
+-----------------------------------------------------------------+
. tab exp1 exp0
discordant pairs */
/* exposure of control versus exposure of case, count
|
0 exp
1 exp |
nei
ja |
Total
-----------+----------------------+---------nei |
16
25 |
41
ja |
6
3 |
9
-----------+----------------------+---------Total |
22
28 |
50
. dis 6/25
.24
/* "manual" Mantel-Haenszel-OR */
. mcc exp1 exp0
/* matched case-control OR */
| Controls
|
Cases
|
Exposed
Unexposed |
Total
-----------------+------------------------+-----------Exposed |
3
6 |
9
Unexposed |
25
16 |
41
-----------------+------------------------+-----------Total |
28
22 |
50
McNemar's chi2(1) =
11.65
Prob > chi2 = 0.0006
Exact McNemar significance probability
= 0.0009
Proportion with factor
Cases
.18
Controls
.56
--------difference
-.38
ratio
.3214286
rel. diff. -.8636364
odds ratio
.24
[95% Conf. Interval]
--------------------.5911543 -.1688457
.1616357
.6391925
-1.540789 -.1864833
.0805203
.5993146
(exact)
. mcci 3 6 25 16
immediate values */
/* matched case-control OR calculator. "i" stands for
| Controls
|
Cases
|
Exposed
Unexposed |
Total
-----------------+------------------------+-----------Exposed |
3
6 |
9
Unexposed |
25
16 |
41
-----------------+------------------------+-----------Total |
28
22 |
50
McNemar's chi2(1) =
11.65
Prob > chi2 = 0.0006
Exact McNemar significance probability
= 0.0009
Proportion with factor
Cases
.18
Controls
.56
--------difference
-.38
ratio
.3214286
rel. diff. -.8636364
odds ratio
[95% Conf. Interval]
--------------------.5911543 -.1688457
.1616357
.6391925
-1.540789 -.1864833
.24
.0805203
.5993146
(exact)
.
. * b) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
.
. * Transform back to long data
. reshape long exp agmt higd agp, i(str) j(case) /* reshape to long */
(note: j = 0 1)
Data
wide
->
long
----------------------------------------------------------------------------Number of obs.
50
->
100
Number of variables
9
->
6
j variable (2 values)
->
case
xij variables:
exp0 exp1
->
exp
agmt0 agmt1
->
agmt
higd0 higd1
->
higd
agp0 agp1
->
agp
----------------------------------------------------------------------------. cc case exp
matching */
/* OR, effect of exposure on disease ignoring
Proportion
|
Exposed
Unexposed |
Total
Exposed
-----------------+------------------------+-----------------------Cases |
9
41 |
50
0.1800
Controls |
28
22 |
50
0.5600
-----------------+------------------------+-----------------------Total |
37
63 |
100
0.3700
|
|
|
Point estimate
|
[95% Conf. Interval]
|------------------------+-----------------------Odds ratio |
.1724739
|
.0613496
.4652853 (exact)
Prev. frac. ex. |
.8275261
|
.5347147
.9386504 (exact)
Prev. frac. pop |
.4634146
|
+------------------------------------------------chi2(1) =
15.49 Pr>chi2 = 0.0001
. mhodds case exp str
/* OR, effect of exposure on disease stratified over str */
Mantel-Haenszel estimate of the odds ratio
Comparing exp==1 vs. exp==0, controlling for str
note: only 31 of the 50 strata formed in this analysis contribute
information about the effect of the explanatory variable
---------------------------------------------------------------Odds Ratio
chi2(1)
P>chi2
[95% Conf. Interval]
---------------------------------------------------------------0.240000
11.65
0.0006
0.098458
0.585023
---------------------------------------------------------------.
.
. * c) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
. clogit case exp, group(str) or
/* conditional logistic regression */
Iteration
Iteration
Iteration
Iteration
0:
1:
2:
3:
log
log
log
log
likelihood
likelihood
likelihood
likelihood
=
=
=
=
-28.647448
-28.404811
-28.400948
-28.400947
Conditional (fixed-effects) logistic regression
Log likelihood = -28.400947
Number of obs
LR chi2(1)
Prob > chi2
Pseudo R2
=
=
=
=
100
12.51
0.0004
0.1805
-----------------------------------------------------------------------------case | Odds Ratio
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------exp |
.24
.1091055
-3.14
0.002
.0984577
.5850226
-----------------------------------------------------------------------------.
.
. * d) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
. clogit case exp agmt, group(str) or
/* including age */
Iteration
Iteration
Iteration
Iteration
0:
1:
2:
3:
log
log
log
log
likelihood
likelihood
likelihood
likelihood
= -28.68888
= -28.289317
= -28.282481
= -28.28248
Conditional (fixed-effects) logistic regression
Log likelihood =
-28.28248
Number of obs
LR chi2(2)
Prob > chi2
Pseudo R2
=
=
=
=
100
12.75
0.0017
0.1839
-----------------------------------------------------------------------------case | Odds Ratio
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------exp |
.2389393
.1088361
-3.14
0.002
.0978516
.5834549
agmt |
.6206091
.6143581
-0.48
0.630
.0891641
4.319626
-----------------------------------------------------------------------------.
.
. * e) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
. clogit case exp agmt higd agp, group(str) or
/* including all counfounders */
note: 17 groups (17 obs) dropped due to all positive or
all negative outcomes.
Iteration
Iteration
Iteration
Iteration
Iteration
Iteration
0:
1:
2:
3:
4:
5:
log
log
log
log
log
log
likelihood
likelihood
likelihood
likelihood
likelihood
likelihood
=
=
=
=
=
=
-16.625249
-14.995893
-14.802182
-14.798964
-14.79896
-14.79896
Conditional (fixed-effects) logistic regression
Log likelihood =
-14.79896
Number of obs
LR chi2(4)
Prob > chi2
Pseudo R2
=
=
=
=
66
16.15
0.0028
0.3530
-----------------------------------------------------------------------------case | Odds Ratio
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------exp |
.2895346
.2023889
-1.77
0.076
.0735696
1.13947
agmt |
.0429981
.1097854
-1.23
0.218
.0002885
6.408996
higd |
.8505999
.1317478
-1.04
0.296
.6278911
1.152302
agp |
1.271245
.1240799
2.46
0.014
1.049899
1.539255
-----------------------------------------------------------------------------.
.
.
. * ----------------- Excercise 4 -----------------------------------------------------------------------------------. * Read in data
. use "F:\Courses\Stat_Epi\Korrelerte kategoriske data\respir.dta", clear
. des
/* describe all variables */
Contains data from F:\Courses\Stat_Epi\Korrelerte kategoriske data\respir.dta
obs:
111
vars:
10
size:
9,324 (99.9% of memory free)
------------------------------------------------------------------------------storage display
value
variable name
type
format
label
variable label
------------------------------------------------------------------------------center
double %10.0g
id
double %10.0g
treat
double %10.0g
treat
gender
double %10.0g
gender
age
double %10.0g
age in years at basline
visit0
double %10.0g
visit1
double %10.0g
visit2
double %10.0g
visit3
double %10.0g
visit4
double %10.0g
------------------------------------------------------------------------------Sorted by:
.
. list if id<5
1.
2.
3.
4.
/* data is in wide format */
+-----------------------------------------------------------------------------------+
| center
id
treat
gender
age
visit0
visit1
visit2
visit3
visit4 |
|-----------------------------------------------------------------------------------|
|
1
1
placebo
male
46
0
0
0
0
0 |
|
1
2
placebo
male
28
0
0
0
0
0 |
|
1
3
active
male
23
1
1
1
1
1 |
|
1
4
placebo
male
44
1
1
1
1
0 |
+-----------------------------------------------------------------------------------+
.
. * a) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
. tab center treat
/* number of treated patients by center */
|
treat
center |
placebo
active |
Total
-----------+----------------------+---------1 |
29
27 |
56
2 |
28
27 |
55
-----------+----------------------+---------Total |
57
54 |
111
.
. * b) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
. reshape long visit, i(id) j(time)
(note: j = 0 1 2 3 4)
Data
wide
->
long
----------------------------------------------------------------------------Number of obs.
111
->
555
Number of variables
10
->
7
j variable (5 values)
->
time
xij variables:
visit0 visit1 ... visit4
->
visit
----------------------------------------------------------------------------. list center id time visit gender if id<=4, sepby(id)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
+-------------------------------------+
| center
id
time
visit
gender |
|-------------------------------------|
|
1
1
0
0
male |
|
1
1
1
0
male |
|
1
1
2
0
male |
|
1
1
3
0
male |
|
1
1
4
0
male |
|-------------------------------------|
|
1
2
0
0
male |
|
1
2
1
0
male |
|
1
2
2
0
male |
|
1
2
3
0
male |
|
1
2
4
0
male |
|-------------------------------------|
|
1
3
0
1
male |
|
1
3
1
1
male |
|
1
3
2
1
male |
|
1
3
3
1
male |
|
1
3
4
1
male |
|-------------------------------------|
|
1
4
0
1
male |
|
1
4
1
1
male |
|
1
4
2
1
male |
|
1
4
3
1
male |
|
1
4
4
0
male |
+-------------------------------------+
.
. twoway (fpfitci visit time )
>
( lfit visit time )
>
,by(treat)
///
///
.
. * c) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/* over time by treatmeant */
. twoway (fpfit visit time ), by(center)
/* over time, by center */
.
. * d) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
. twoway (fpfit visit time ),by(center treat)
treatment */
/* over time, by center and
.
. * e) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
. gen treatTime=treat*time
/* make interaction term */
.
. logit visit treat time treatTime, or
Iteration
Iteration
Iteration
Iteration
0:
1:
2:
3:
log
log
log
log
likelihood
likelihood
likelihood
likelihood
=
=
=
=
/* Ordinary logistic model */
-383.18089
-371.64968
-371.63251
-371.63251
Logistic regression
Number of obs
LR chi2(3)
Prob > chi2
Pseudo R2
Log likelihood = -371.63251
=
=
=
=
555
23.10
0.0000
0.0301
-----------------------------------------------------------------------------visit | Odds Ratio
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------treat |
1.482444
.4410156
1.32
0.186
.8274703
2.655854
time |
.9719871
.0819384
-0.34
0.736
.8239565
1.146612
treatTime |
1.208174
.1492648
1.53
0.126
.9483464
1.539188
-----------------------------------------------------------------------------. estimates store logit
/* save estimates for later */
.
. * f) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
. * GEE, exchangable correlation structure=same variance for all 5 times and same covariance for all, 2 parameters
estimated
. xtgee visit treat time treatTime, i(id) fam(bin) link(logit) corr(exchangeable) robust eform
Iteration 1: tolerance = .00568173
Iteration 2: tolerance = .00001838
Iteration 3: tolerance = 5.182e-08
GEE population-averaged model
Group variable:
id
Link:
logit
Family:
binomial
Correlation:
exchangeable
Scale parameter:
1
Number of obs
Number of groups
Obs per group: min
avg
max
Wald chi2(3)
Prob > chi2
=
=
=
=
=
=
=
555
111
5
5.0
5
10.37
0.0157
(Std. Err. adjusted for clustering on id)
-----------------------------------------------------------------------------|
Semi-robust
visit | Odds Ratio
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------treat |
1.494268
.5038153
1.19
0.234
.7716724
2.893504
time |
.971987
.0643095
-0.43
0.668
.8537732
1.106569
treatTime |
1.208388
.1233099
1.85
0.064
.9893401
1.475935
-----------------------------------------------------------------------------. estimates store GEE_exc
.
. * GEE, unstructured correlation =all possible variance /covariances , 5*(5-1) parameters estimated
. xtgee visit treat time treatTime, i(id) t(time) fam(bin) link(logit) corr(unstructured) robust eform
Iteration 6: tolerance = 3.723e-07
GEE population-averaged model
Group and time vars:
id time
Link:
logit
Family:
binomial
Correlation:
unstructured
Scale parameter:
1
Number of obs
Number of groups
Obs per group: min
avg
max
Wald chi2(3)
Prob > chi2
=
=
=
=
=
=
=
555
111
5
5.0
5
9.30
0.0256
(Std. Err. adjusted for clustering on id)
-----------------------------------------------------------------------------|
Semi-robust
visit | Odds Ratio
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------treat |
1.611431
.5410155
1.42
0.155
.834512
3.11165
time |
.9863445
.0651424
-0.21
0.835
.8665859
1.122653
treatTime |
1.158085
.115908
1.47
0.143
.9518036
1.409074
-----------------------------------------------------------------------------. estimates store GEE_uns
.
. * GEE, 1. order autoregressive correlation =same variance for all 5 times, Corr(1,2)=r, Corr(1,3)=r^2, ..., 2
paramete
> rs estimated
. xtgee visit treat time treatTime, i(id) t(time) fam(bin) link(logit) corr(ar1) robust eform
Iteration 4: tolerance = 2.455e-07
GEE population-averaged model
Group and time vars:
Link:
Family:
Correlation:
id time
logit
binomial
AR(1)
Scale parameter:
1
Number of obs
Number of groups
Obs per group: min
avg
max
Wald chi2(3)
Prob > chi2
=
=
=
=
=
=
=
555
111
5
5.0
5
8.86
0.0312
(Std. Err. adjusted for clustering on id)
-----------------------------------------------------------------------------|
Semi-robust
visit | Odds Ratio
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------treat |
1.290757
.4428865
0.74
0.457
.6588383
2.528774
time |
.9785018
.0648295
-0.33
0.743
.8593424
1.114184
treatTime |
1.214547
.1255522
1.88
0.060
.991796
1.487326
-----------------------------------------------------------------------------. estimates store GEE_ar1
.
.
. estimates table logit GEE_exc GEE_uns GEE_ar1
>
, b(%6.2f) p(%6.3f) eform
///
-----------------------------------------------------Variable | logit
GEE_exc
GEE_uns
GEE_ar1
-------------+---------------------------------------treat |
1.48
1.49
1.61
1.29
|
0.186
0.234
0.155
0.457
time |
0.97
0.97
0.99
0.98
|
0.736
0.668
0.835
0.743
treatTime |
1.21
1.21
1.16
1.21
|
0.126
0.064
0.143
0.060
_cons |
0.85
0.85
0.82
0.84
|
0.433
0.482
0.381
0.462
-----------------------------------------------------legend: b/p
.
. * g) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
. * GEE, ar1, no treat effect
. xtgee visit time treatTime, i(id) t(time) fam(bin) link(logit) corr(ar1) robust eform
Iteration
Iteration
Iteration
Iteration
Iteration
1:
2:
3:
4:
5:
tolerance
tolerance
tolerance
tolerance
tolerance
=
=
=
=
=
.07384754
.00087712
.00004309
2.338e-06
1.272e-07
GEE population-averaged model
Group and time vars:
Link:
Family:
Correlation:
Scale parameter:
id time
logit
binomial
AR(1)
1
Number of obs
Number of groups
Obs per group: min
avg
max
Wald chi2(2)
Prob > chi2
=
=
=
=
=
=
=
555
111
5
5.0
5
8.88
0.0118
(Std. Err. adjusted for clustering on id)
-----------------------------------------------------------------------------|
Semi-robust
visit | Odds Ratio
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------time |
.9477628
.0623936
-0.81
0.415
.8330344
1.078292
treatTime |
1.297369
.1231573
2.74
0.006
1.077111
1.562668
-----------------------------------------------------------------------------.
.
. * h) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
. lincom 1*treatTime, eform
( 1)
/* treatment effect at time=1 */
treatTime = 0
-----------------------------------------------------------------------------visit |
exp(b)
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------(1) |
1.297369
.1231573
2.74
0.006
1.077111
1.562668
-----------------------------------------------------------------------------. lincom 2*treatTime, eform
( 1)
/* treatment effect at time=2 */
2 treatTime = 0
-----------------------------------------------------------------------------visit |
exp(b)
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------(1) |
1.683167
.3195609
2.74
0.006
1.160167
2.441933
-----------------------------------------------------------------------------.
.
.
.
.
.
.
* i) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* j) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
* Check difference in treatment effect between centers
gen cenTime=center*time
/* make 2-way interaction term */
. gen cenTreat=center*treat
/* make 2-way interaction term */
. gen cenTimeTreat=center*time*treat
/* make 3-way interaction term */
.
. * Model with all main effects (except treat), all 2-way interactions, and the 3-way interaction term
. xtgee visit time center treatTime cenTime cenTreat cenTimeTreat, i(id) t(time) fam(bin) link(logit) corr(ar1)
robust
> eform
Iteration
Iteration
Iteration
Iteration
Iteration
1:
2:
3:
4:
5:
tolerance
tolerance
tolerance
tolerance
tolerance
=
=
=
=
=
.0875784
.00288728
.00008192
4.708e-06
2.364e-07
GEE population-averaged model
Group and time vars:
Link:
Family:
Correlation:
Scale parameter:
id time
logit
binomial
AR(1)
1
Number of obs
Number of groups
Obs per group: min
avg
max
Wald chi2(6)
Prob > chi2
=
=
=
=
=
=
=
555
111
5
5.0
5
17.43
0.0078
(Std. Err. adjusted for clustering on id)
-----------------------------------------------------------------------------|
Semi-robust
visit | Odds Ratio
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------time |
1.000044
.205066
0.00
1.000
.6690737
1.494734
center |
2.295983
.817187
2.34
0.020
1.142901
4.612417
treatTime |
1.007334
.3019539
0.02
0.981
.5597844
1.812699
cenTime |
.9822808
.1349656
-0.13
0.896
.7503786
1.285852
cenTreat |
1.161765
.2498075
0.70
0.486
.7622356
1.770708
cenTimeTreat |
1.160214
.2455564
0.70
0.483
.7662726
1.75668
-----------------------------------------------------------------------------.
.
.
.
.
.
.
* The 3-way interaction tell if the treatment effect over time differs by center
* ----------------- Excercise 5 -----------------------------------------------------------------------------------* Read in data
use "F:\Courses\Stat_Epi\Korrelerte kategoriske data\hubro.dta", clear
. des
/* describe all variables */
Contains data from F:\Courses\Stat_Epi\Korrelerte kategoriske data\hubro.dta
obs:
3,320
vars:
6
size:
172,640 (98.4% of memory free)
------------------------------------------------------------------------------storage display
value
variable name
type
format
label
variable label
------------------------------------------------------------------------------id
double %10.0g
sex
double %10.0g
sex
psyk1
double %10.0g
psyk1
psyk2
double %10.0g
psyk2
asmta1
double %10.0g
asmta1
astma2
double %10.0g
astma2
------------------------------------------------------------------------------Sorted by:
. rename
asmta1 astma1
/* rename misspelt variable */
.
. * a) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
. bysort sex: tab1 astma1 astma2 psyk1 psyk2
/* 1-way tables, by sex */
----------------------------------------------------------------------------------------------------------------------> sex = Gutt
-> tabulation of astma1
astma1 |
Freq.
Percent
Cum.
------------+----------------------------------Nei |
1,388
95.66
95.66
Ja |
63
4.34
100.00
------------+----------------------------------Total |
1,451
100.00
-> tabulation of astma2
astma2 |
Freq.
Percent
Cum.
------------+----------------------------------Nei |
1,388
95.66
95.66
Ja |
63
4.34
100.00
------------+----------------------------------Total |
1,451
100.00
-> tabulation of psyk1
psyk1 |
Freq.
Percent
Cum.
------------+----------------------------------Nei |
1,346
92.76
92.76
Ja |
105
7.24
100.00
------------+----------------------------------Total |
1,451
100.00
-> tabulation of psyk2
psyk2 |
Freq.
Percent
Cum.
------------+----------------------------------Nei |
1,274
87.80
87.80
Ja |
177
12.20
100.00
------------+----------------------------------Total |
1,451
100.00
----------------------------------------------------------------------------------------------------------------------> sex = Jente
-> tabulation of astma1
astma1 |
Freq.
Percent
Cum.
------------+----------------------------------Nei |
1,735
92.83
92.83
Ja |
134
7.17
100.00
------------+----------------------------------Total |
1,869
100.00
-> tabulation of astma2
astma2 |
Freq.
Percent
Cum.
------------+----------------------------------Nei |
1,735
92.83
92.83
Ja |
134
7.17
100.00
------------+----------------------------------Total |
1,869
100.00
-> tabulation of psyk1
psyk1 |
Freq.
Percent
Cum.
------------+----------------------------------Nei |
1,433
76.67
76.67
Ja |
436
23.33
100.00
------------+----------------------------------Total |
1,869
100.00
-> tabulation of psyk2
psyk2 |
Freq.
Percent
Cum.
------------+----------------------------------Nei |
1,286
68.81
68.81
Ja |
583
31.19
100.00
------------+----------------------------------Total |
1,869
100.00
. bysort sex:tabstat astma1 astma2 psyk1 psyk2, stat(N mean) col(stat)
sex (alt. to above) */
/* tables of N and mean (proportions), by
----------------------------------------------------------------------------------------------------------------------> sex = Gutt
variable |
N
mean
-------------+-------------------astma1 |
1451 .0434183
astma2 |
1451 .0434183
psyk1 |
1451 .0723639
psyk2 |
1451 .1219848
-------------------------------------------------------------------------------------------------------------------------------------------------------> sex = Jente
variable |
N
mean
-------------+-------------------astma1 |
1869 .0716961
astma2 |
1869 .0716961
psyk1 |
1869 .2332798
psyk2 |
1869 .3119315
---------------------------------.
. * b) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
. cc psyk1 astma1
/* case control analysis: case by exposure */
Proportion
|
Exposed
Unexposed |
Total
Exposed
-----------------+------------------------+-----------------------Cases |
48
493 |
541
0.0887
Controls |
149
2630 |
2779
0.0536
-----------------+------------------------+-----------------------Total |
197
3123 |
3320
0.0593
|
|
|
Point estimate
|
[95% Conf. Interval]
|------------------------+-----------------------Odds ratio |
1.718556
|
1.197059
2.431845 (exact)
Attr. frac. ex. |
.4181163
|
.1646192
.5887895 (exact)
Attr. frac. pop |
.0370972
|
+------------------------------------------------chi2(1) =
10.00 Pr>chi2 = 0.0016
. cc
psyk2 astma2
Proportion
|
Exposed
Unexposed |
Total
Exposed
-----------------+------------------------+-----------------------Cases |
54
706 |
760
0.0711
Controls |
143
2417 |
2560
0.0559
-----------------+------------------------+-----------------------Total |
197
3123 |
3320
0.0593
|
|
|
Point estimate
|
[95% Conf. Interval]
|------------------------+-----------------------Odds ratio |
1.292795
|
.9166512
1.801921 (exact)
Attr. frac. ex. |
.2264822
|
-.0909275
.4450367 (exact)
Attr. frac. pop |
.0160922
|
+------------------------------------------------chi2(1) =
2.42 Pr>chi2 = 0.1195
.
. cc
psyk1 astma1, by(sex)
/* case control analysis: case by exposure, stratified by sex */
sex |
OR
[95% Conf. Interval]
M-H Weight
-----------------+------------------------------------------------Gutt |
1.645408
.6158239
3.748162
3.782219 (exact)
Jente |
1.495576
.9918285
2.223388
19.6549 (exact)
-----------------+------------------------------------------------Crude |
1.718556
1.197059
2.431845
(exact)
M-H combined |
1.519756
1.073218
2.152086
------------------------------------------------------------------Test of homogeneity (M-H)
chi2(1) =
0.04 Pr>chi2 = 0.8349
Test that combined OR = 1:
Mantel-Haenszel chi2(1) =
5.64
Pr>chi2 =
. cc
0.0176
psyk2 astma2, by(sex)
sex |
OR
[95% Conf. Interval]
M-H Weight
-----------------+------------------------------------------------Gutt |
.7491536
.2600333
1.769749
6.717436 (exact)
Jente |
1.251902
.847546
1.83154
24.61744 (exact)
-----------------+------------------------------------------------Crude |
1.292795
.9166512
1.801921
(exact)
M-H combined |
1.144125
.8189533
1.598408
------------------------------------------------------------------Test of homogeneity (M-H)
chi2(1) =
1.17 Pr>chi2 = 0.2794
Test that combined OR = 1:
Mantel-Haenszel chi2(1) =
Pr>chi2 =
.
. tab astma1 sex, nofreq col
0.61
0.4330
/* tables to understand confounding by sex in the crude OR above */
|
sex
astma1 |
Gutt
Jente |
Total
-----------+----------------------+---------Nei |
95.66
92.83 |
94.07
Ja |
4.34
7.17 |
5.93
-----------+----------------------+---------Total |
100.00
100.00 |
100.00
. tab psyk1 sex, nofreq col
|
sex
psyk1 |
Gutt
Jente |
Total
-----------+----------------------+---------Nei |
92.76
76.67 |
83.70
Ja |
7.24
23.33 |
16.30
-----------+----------------------+---------Total |
100.00
100.00 |
100.00
.
. * c) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
. reshape long astma psyk, i(id) j(time)
(note: j = 1 2)
Data
wide
->
long
----------------------------------------------------------------------------Number of obs.
3320
->
6640
Number of variables
6
->
5
j variable (2 values)
->
time
xij variables:
astma1 astma2
->
astma
psyk1 psyk2
->
psyk
----------------------------------------------------------------------------. list id time astma psyk sex if id<=5, sepby(id)
1.
2.
3.
4.
5.
6.
+----------------------------------+
| id
time
astma
psyk
sex |
|----------------------------------|
| 2
1
Nei
Ja
Jente |
| 2
2
Nei
Nei
Jente |
|----------------------------------|
| 3
1
Nei
Nei
Gutt |
| 3
2
Nei
Nei
Gutt |
|----------------------------------|
| 4
1
Nei
Nei
Gutt |
| 4
2
Nei
Nei
Gutt |
+----------------------------------+
.
. gen astmaTime=astma*time
/* generate interaction term */
. xtgee psyk astma time astmaTime if sex==1, i(id) t(time) fam(bin) link(logit) corr(exchangeable) robust eform
boys only */
Iteration 1: tolerance = 3.350e-13
GEE population-averaged model
Group variable:
id
Link:
logit
Family:
binomial
Correlation:
exchangeable
Number of obs
Number of groups
Obs per group: min
avg
max
=
=
=
=
=
2902
1451
2
2.0
2
/*
Scale parameter:
1
Wald chi2(3)
Prob > chi2
=
=
30.60
0.0000
(Std. Err. adjusted for clustering on id)
-----------------------------------------------------------------------------|
Semi-robust
psyk | Odds Ratio
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------astma |
3.613903
3.288906
1.41
0.158
.6071878
21.50948
time |
1.849563
.2059239
5.52
0.000
1.48696
2.300589
astmaTime |
.4552995
.2646258
-1.35
0.176
.1457364
1.422415
-----------------------------------------------------------------------------.
. * The interaction term is not significant, is it were, we would have shown the results below
. lincom astma+1*astmaTime, eform
/* effect of astma at time 1 for boys */
( 1)
astma + astmaTime = 0
-----------------------------------------------------------------------------psyk |
exp(b)
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------(1) |
1.645408
.6820251
1.20
0.230
.7302118
3.707648
-----------------------------------------------------------------------------. lincom astma+2*astmaTime, eform
( 1)
/* effect of astma at time 2 for boys */
astma + 2 astmaTime = 0
-----------------------------------------------------------------------------psyk |
exp(b)
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------(1) |
.7491536
.3274168
-0.66
0.509
.318093
1.764362
-----------------------------------------------------------------------------.
. * ----------------- Excercise 6 ------------------------------------------------------------------------------------> ---. clear
. use "F:\Courses\Stat_Epi\Korrelerte kategoriske data\bbd11.dta", clear
. des
/* describe all variables */
Contains data from F:\Courses\Stat_Epi\Korrelerte kategoriske data\bbd11.dta
obs:
100
vars:
6
size:
5,200 (99.9% of memory free)
------------------------------------------------------------------------------storage display
value
variable name
type
format
label
variable label
------------------------------------------------------------------------------str
double %10.0g
case
double %10.0g
case
agmt
double %10.0g
higd
double %10.0g
exp
double %10.0g
exp
Går regelmessig til lege
agp
double %10.0g
------------------------------------------------------------------------------Sorted by:
.
. * a and b) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
. * Fixed intercept model, conditional
. clogit case exp, or group(str)
Iteration
Iteration
Iteration
Iteration
0:
1:
2:
3:
log
log
log
log
likelihood
likelihood
likelihood
likelihood
=
=
=
=
-28.647448
-28.404811
-28.400948
-28.400947
Conditional (fixed-effects) logistic regression
Log likelihood = -28.400947
Number of obs
LR chi2(1)
Prob > chi2
Pseudo R2
=
=
=
=
100
12.51
0.0004
0.1805
-----------------------------------------------------------------------------case | Odds Ratio
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------exp |
.24
.1091055
-3.14
0.002
.0984577
.5850226
-----------------------------------------------------------------------------. estimates store cond
.
. * Random intercept model
. xtlogit case exp, i(str) or
Fitting comparison model:
Iteration 3:
log likelihood = -61.285314
Fitting full model:
tau =
tau =
0.0
0.1
Iteration 4:
log likelihood = -61.285314
log likelihood = -62.291841
log likelihood = -61.623219
Random-effects logistic regression
Group variable (i): str
Number of obs
Number of groups
=
=
100
50
Random effects u_i ~ Gaussian
Obs per group: min =
avg =
max =
2
2.0
2
Log likelihood
= -61.623219
Wald chi2(1)
Prob > chi2
=
=
14.44
0.0001
-----------------------------------------------------------------------------case |
OR
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------exp |
.168729
.0790061
-3.80
0.000
.067394
.4224335
-------------+---------------------------------------------------------------/lnsig2u | -3.415541
.6486165
-4.686806
-2.144276
-------------+---------------------------------------------------------------sigma_u |
.1812695
.0587872
.0960004
.342276
rho |
.0098891
.0063508
.0027935
.0343857
-----------------------------------------------------------------------------Likelihood-ratio test of rho=0: chibar2(01) =
0.68 Prob >= chibar2 = 0.206
. estimates store rand
.
. * Compare results, OR and standard errors
. estimates table cond rand, eq(1) keep(exp) eform b(%6.2f) se(%6.2f)
---------------------------------Variable | cond
rand
-------------+-------------------exp |
0.24
0.17
|
0.11
0.08
---------------------------------legend: b/se
.
. * ----------------- Excercise 7 -----------------------------------------------------------------------------------. * Read in data
. use "F:\Courses\Stat_Epi\Korrelerte kategoriske data\respir.dta", clear
. des
/* describe all variables */
Contains data from F:\Courses\Stat_Epi\Korrelerte kategoriske data\respir.dta
obs:
111
vars:
10
size:
9,324 (99.9% of memory free)
------------------------------------------------------------------------------storage display
value
variable name
type
format
label
variable label
------------------------------------------------------------------------------center
double %10.0g
id
double %10.0g
treat
double %10.0g
treat
gender
double %10.0g
gender
age
double %10.0g
age in years at basline
visit0
double %10.0g
visit1
double %10.0g
visit2
double %10.0g
visit3
double %10.0g
visit4
double %10.0g
------------------------------------------------------------------------------Sorted by:
.
.
. reshape long visit, i(id) j(time)
(note: j = 0 1 2 3 4)
Data
wide
->
long
----------------------------------------------------------------------------Number of obs.
111
->
555
Number of variables
10
->
7
j variable (5 values)
->
time
xij variables:
visit0 visit1 ... visit4
->
visit
----------------------------------------------------------------------------. list center id time visit gender if id<=5, sepby(id)
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.
+-------------------------------------+
| center
id
time
visit
gender |
|-------------------------------------|
|
1
1
0
0
male |
|
1
1
1
0
male |
|
1
1
2
0
male |
|
1
1
3
0
male |
|
1
1
4
0
male |
|-------------------------------------|
|
1
2
0
0
male |
|
1
2
1
0
male |
|
1
2
2
0
male |
|
1
2
3
0
male |
|
1
2
4
0
male |
|-------------------------------------|
|
1
3
0
1
male |
|
1
3
1
1
male |
|
1
3
2
1
male |
|
1
3
3
1
male |
|
1
3
4
1
male |
|-------------------------------------|
|
1
4
0
1
male |
|
1
4
1
1
male |
|
1
4
2
1
male |
|
1
4
3
1
male |
|
1
4
4
0
male |
|-------------------------------------|
|
1
5
0
1
female |
|
1
5
1
1
female |
|
1
5
2
1
female |
|
1
5
3
1
female |
|
1
5
4
1
female |
+-------------------------------------+
.
. gen treatTime=treat*time
/* make interaction term */
.
.
. * a) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
. * Fixed intercept model, noomit gives one dummy for each subject, noconst removes the usual intercept term
. xi, noomit: logit visit i.id treat time treatTime, noconst or
note: id_1 != 0 predicts failure perfectly
id_1 dropped and 5 obs not used
.
.
.
note: id_111 != 0 predicts success perfectly
id_111 dropped and 5 obs not used
note: id_109 dropped due to collinearity
Iteration 4:
log likelihood = -167.19281
Logistic regression
Log likelihood = -167.19281
Number of obs
LR chi2(61)
Prob > chi2
=
=
=
295
.
.
-----------------------------------------------------------------------------visit | Odds Ratio
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------id_4 |
4.592223
5.286636
1.32
0.185
.4809578
43.84691
id_7 |
1.718935
1.635125
0.57
0.569
.2664157
11.0907
id_10 |
1.718935
1.635125
0.57
0.569
.2664157
11.0907
id_12 |
.355713
.5264513
-0.70
0.485
.0195583
6.469469
id_13 |
.7625738
.7239204
-0.29
0.775
.1186386
4.901598
id_16 |
.0533183
.086286
-1.81
0.070
.0022354
1.271723
id_18 |
.355713
.5264513
-0.70
0.485
.0195583
6.469469
id_20 |
.355713
.5264513
-0.70
0.485
.0195583
6.469469
id_21 |
.1498913
.2220846
-1.28
0.200
.0082149
2.734945
id_24 |
.0533183
.086286
-1.81
0.070
.0022354
1.271723
id_27 |
4.592223
5.286636
1.32
0.185
.4809578
43.84691
id_28 |
.7625738
.7239204
-0.29
0.775
.1186386
4.901598
id_29 |
.7625738
.7239204
-0.29
0.775
.1186386
4.901598
id_32 |
1
1.613841
-0.00
1.000
.0422957
23.64307
id_33 |
1
1.613841
-0.00
1.000
.0422957
23.64307
id_34 |
.7625738
.7239204
-0.29
0.775
.1186386
4.901598
id_35 |
.0533183
.086286
-1.81
0.070
.0022354
1.271723
id_37 |
.0533183
.086286
-1.81
0.070
.0022354
1.271723
id_41 |
.2854423
.3272382
-1.09
0.274
.0301773
2.699957
id_42 |
.0533183
.086286
-1.81
0.070
.0022354
1.271723
id_45 |
1.718935
1.635125
0.57
0.569
.2664157
11.0907
id_50 |
.355713
.5264513
-0.70
0.485
.0195583
6.469469
id_51 |
.355713
.5264513
-0.70
0.485
.0195583
6.469469
id_52 |
.2854423
.3272382
-1.09
0.274
.0301773
2.699957
id_53 |
.0533183
.086286
-1.81
0.070
.0022354
1.271723
id_54 |
1
1.613841
-0.00
1.000
.0422957
23.64307
id_56 |
.355713
.5264513
-0.70
0.485
.0195583
6.469469
id_58 |
.355713
.5264513
-0.70
0.485
.0195583
6.469469
id_60 |
4.592223
5.286636
1.32
0.185
.4809578
43.84691
id_61 |
1.718935
1.635125
0.57
0.569
.2664157
11.0907
id_62 |
.7625738
.7239204
-0.29
0.775
.1186386
4.901598
id_65 |
1
1.613841
-0.00
1.000
.0422957
23.64307
id_66 |
1
1.613841
-0.00
1.000
.0422957
23.64307
id_69 |
4.592223
5.286636
1.32
0.185
.4809578
43.84691
id_70 |
.355713
.5264513
-0.70
0.485
.0195583
6.469469
id_73 |
.2854423
.3272382
-1.09
0.274
.0301773
2.699957
id_74 |
.7625738
.7239204
-0.29
0.775
.1186386
4.901598
id_77 |
1.718935
1.635125
0.57
0.569
.2664157
11.0907
id_78 |
4.592223
5.286636
1.32
0.185
.4809578
43.84691
id_80 |
1.718935
1.635125
0.57
0.569
.2664157
11.0907
id_81 |
1
1.613841
-0.00
1.000
.0422957
23.64307
id_83 |
1
1.613841
-0.00
1.000
.0422957
23.64307
id_86 |
1
1.613841
-0.00
1.000
.0422957
23.64307
id_87 |
4.592223
5.286636
1.32
0.185
.4809578
43.84691
id_88 |
.1498913
.2220846
-1.28
0.200
.0082149
2.734945
id_89 |
1.718935
1.635125
0.57
0.569
.2664157
11.0907
id_90 |
4.592223
5.286636
1.32
0.185
.4809578
43.84691
id_91 |
.2854423
.3272382
-1.09
0.274
.0301773
2.699957
id_94 |
1.718935
1.635125
0.57
0.569
.2664157
11.0907
id_96 |
.2854423
.3272382
-1.09
0.274
.0301773
2.699957
id_99 |
.355713
.5264513
-0.70
0.485
.0195583
6.469469
id_101 |
4.592223
5.286636
1.32
0.185
.4809578
43.84691
id_102 |
.7625738
.7239204
-0.29
0.775
.1186386
4.901598
id_103 |
1
1.613841
-0.00
1.000
.0422957
23.64307
id_104 |
.7625738
.7239204
-0.29
0.775
.1186386
4.901598
id_105 |
.0533183
.086286
-1.81
0.070
.0022354
1.271723
id_107 |
1
1.613841
-0.00
1.000
.0422957
23.64307
id_108 |
1
1.613841
-0.00
1.000
.0422957
23.64307
treat |
2.079548
2.417593
0.63
0.529
.2130094
20.30202
time |
.9345761
.1217211
-0.52
0.603
.7240231
1.20636
treatTime |
1.544123
.2964985
2.26
0.024
1.05983
2.249714
-----------------------------------------------------------------------------. estimates store fix
. drop id_*
/* drop all dummies */
.
.
. * b) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
. * Fixed intercept model, conditional
. clogit visit treat time treatTime, group(id) or
note: multiple positive outcomes within groups encountered.
note: 52 groups (260 obs) dropped due to all positive or
all negative outcomes.
note: treat omitted due to no within-group variance.
Iteration
Iteration
Iteration
Iteration
0:
1:
2:
3:
log
log
log
log
likelihood
likelihood
likelihood
likelihood
=
=
=
=
-111.23061
-110.69846
-110.69827
-110.69827
Conditional (fixed-effects) logistic regression
Log likelihood = -110.69827
Number of obs
LR chi2(2)
Prob > chi2
Pseudo R2
=
=
=
=
295
5.95
0.0511
0.0262
-----------------------------------------------------------------------------visit | Odds Ratio
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------time |
.9473192
.1103228
-0.46
0.642
.7539928
1.190215
treatTime |
1.412961
.2413893
2.02
0.043
1.010908
1.974917
------------------------------------------------------------------------------
. estimates store fixCond
.
.
. * b) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
. * Random intercept model
. xtlogit visit treat time treatTime, i(id) or
>
/* Random intercept model */
Fitting comparison model:
Iteration 3:
log likelihood = -371.63251
Fitting full model:
tau =
0.8
Iteration 4:
log likelihood = -303.65764
log likelihood = -301.24833
Random-effects logistic regression
Group variable (i): id
Number of obs
Number of groups
=
=
555
111
Random effects u_i ~ Gaussian
Obs per group: min =
avg =
max =
5
5.0
5
Log likelihood
= -301.24833
Wald chi2(3)
Prob > chi2
=
=
12.22
0.0067
-----------------------------------------------------------------------------visit |
OR
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------treat |
2.081744
1.304161
1.17
0.242
.6097769
7.106959
time |
.9483884
.1092508
-0.46
0.646
.7567126
1.188616
treatTime |
1.413093
.2394692
2.04
0.041
1.01373
1.969787
-------------+---------------------------------------------------------------/lnsig2u |
1.743785
.2451228
1.263354
2.224217
-------------+---------------------------------------------------------------sigma_u |
2.391433
.2930973
1.880762
3.040764
rho |
.634817
.0568254
.5181186
.7375687
-----------------------------------------------------------------------------Likelihood-ratio test of rho=0: chibar2(01) =
140.77 Prob >= chibar2 = 0.000
. estimates store random
.
.
. * Compare models from a) b) and c), show OR with 2 decimal points, and standard errors with 3 decimal points
. estimates table fix fixCond random
///
>
, eq(1) b(%6.2f) se(%6.3f)
///
>
keep(treat time treatTime) eform
-------------------------------------------Variable |
fix
fixCond
random
-------------+-----------------------------treat |
2.08
2.08
|
2.418
1.304
time |
0.93
0.95
0.95
|
0.122
0.110
0.109
treatTime |
1.54
1.41
1.41
|
0.296
0.241
0.239
-------------------------------------------legend: b/se
.
.
. * d) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
. * Effect of integration points (quadrature points ), the default is 12 points
. xtlogit visit treat time treatTime
///
>
, i(id) or intpoints(4)
Fitting comparison model:
Iteration 3:
log likelihood = -371.63251
Fitting full model:
tau =
0.8
Iteration 4:
log likelihood = -306.04512
log likelihood = -303.87907
Random-effects logistic regression
Group variable (i): id
Number of obs
Number of groups
=
=
555
111
Random effects u_i ~ Gaussian
Log likelihood
Obs per group: min =
avg =
max =
Wald chi2(3)
Prob > chi2
= -303.87907
=
=
5
5.0
5
13.30
0.0040
-----------------------------------------------------------------------------visit |
OR
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------treat |
1.876705
1.003455
1.18
0.239
.6580622
5.352108
time |
.95264
.1049802
-0.44
0.660
.767586
1.182308
treatTime |
1.373206
.2217558
1.96
0.050
1.000638
1.884491
-------------+---------------------------------------------------------------/lnsig2u |
1.376925
.1902932
1.003957
1.749893
-------------+---------------------------------------------------------------sigma_u |
1.990653
.1894039
1.651987
2.398747
rho |
.5463856
.0471639
.453413
.6362317
-----------------------------------------------------------------------------Likelihood-ratio test of rho=0: chibar2(01) =
135.51 Prob >= chibar2 = 0.000
. estimates store qp4
.
. xtlogit visit treat time treatTime
>
, i(id) or intpoints(8)
///
Fitting comparison model:
Iteration 3:
log likelihood = -371.63251
Fitting full model:
tau =
0.8
Iteration 4:
log likelihood = -304.10777
log likelihood = -301.66804
Random-effects logistic regression
Group variable (i): id
Number of obs
Number of groups
=
=
555
111
Random effects u_i ~ Gaussian
Obs per group: min =
avg =
max =
5
5.0
5
Log likelihood
= -301.66804
Wald chi2(3)
Prob > chi2
=
=
12.50
0.0059
-----------------------------------------------------------------------------visit |
OR
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------treat |
2.033086
1.228104
1.17
0.240
.6222713
6.642502
time |
.9494091
.1082431
-0.46
0.649
.7592889
1.187134
treatTime |
1.403314
.2350213
2.02
0.043
1.010646
1.948546
-------------+---------------------------------------------------------------/lnsig2u |
1.651772
.2206202
1.219364
2.08418
-------------+---------------------------------------------------------------sigma_u |
2.283904
.2519377
1.839847
2.835136
rho |
.6132335
.0523263
.5071287
.7095774
-----------------------------------------------------------------------------Likelihood-ratio test of rho=0: chibar2(01) =
139.93 Prob >= chibar2 = 0.000
. estimates store qp8
.
. xtlogit visit treat time treatTime, i(id) or
Fitting comparison model:
Iteration 3:
log likelihood = -371.63251
Fitting full model:
tau =
0.8
Iteration 4:
log likelihood = -303.65764
log likelihood = -301.24833
Random-effects logistic regression
Group variable (i): id
Number of obs
Number of groups
=
=
555
111
Random effects u_i ~ Gaussian
Obs per group: min =
avg =
max =
5
5.0
5
Log likelihood
= -301.24833
Wald chi2(3)
Prob > chi2
=
=
12.22
0.0067
-----------------------------------------------------------------------------visit |
OR
Std. Err.
z
P>|z|
[95% Conf. Interval]
-------------+---------------------------------------------------------------treat |
2.081744
1.304161
1.17
0.242
.6097769
7.106959
time |
.9483884
.1092508
-0.46
0.646
.7567126
1.188616
treatTime |
1.413093
.2394692
2.04
0.041
1.01373
1.969787
-------------+---------------------------------------------------------------/lnsig2u |
1.743785
.2451228
1.263354
2.224217
-------------+---------------------------------------------------------------sigma_u |
2.391433
.2930973
1.880762
3.040764
rho |
.634817
.0568254
.5181186
.7375687
-----------------------------------------------------------------------------Likelihood-ratio test of rho=0: chibar2(01) =
140.77 Prob >= chibar2 = 0.000
. estimates store qp12
.
.
. * Compare models, xtlogit has the defalt=12 points
. estimates table qp4 qp8 qp12, eq(1) b(%6.3f) eform
-------------------------------------------Variable |
qp4
qp8
qp12
-------------+-----------------------------#1
|
treat |
1.877
2.033
2.082
time |
0.953
0.949
0.948
treatTime |
1.373
1.403
1.413
_cons |
0.750
0.720
0.711
-------------+-----------------------------lnsig2u
|
_cons |
3.963
5.216
5.719
-------------------------------------------.
.
. *
. *
.
. *
.
.
end
e) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Time effect: OR=0.95 per time unit, ci=(0.6,7.3). There is no overall time trend in respiration
Interaction effect: OR=1.4 ci=(1.0,2.0). Patients with active treatment do better over time.
of do-file
. log close
log: F:\Courses\Stat_Epi\Korrelerte kategoriske data\Exercises, Answers.smcl
log type: smcl
closed on: 13 May 2008, 13:45:23
----------------------------------------
Download