-
Notifications
You must be signed in to change notification settings - Fork 1
/
R-bios6643-L09sas-completed.Rmd
executable file
·161 lines (111 loc) · 4.95 KB
/
R-bios6643-L09sas-completed.Rmd
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
---
title: "BIOS6643. L09 Specifying both G and R"
cheauthor: "EJC"
-- date: ""
header-includes:
- \usepackage{amsmath}
- \usepackage{float}
output: pdf_document
---
\newcommand{\bi}{\begin{itemize}}
\newcommand{\ei}{\end{itemize}}
\newcommand{\itt}{\item}
```{r setup, include=FALSE, echo=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
<!-- -->
```{r installp, echo = FALSE, eval=T, include=F}
library(SASmarkdown)
```
```{r include=FALSE}
# set up the options so that knit knows where you SAS executable is
# set the line size to be easily readable on letter size paper, portrait
# and set the knitr options using opts_chunk$set().
sasopts <- "-nosplash -linesize 75"
saspath <- "C:/Program Files/SASHome/SASFoundation/9.4/sas.exe"
## those two parts should have been universal
## just copy and paste into your Rmarkdown files
knitr::opts_chunk$set(engine = "sas",
engine.path = saspath,
engine.opts = sasopts,
comment = NA)
```
The RANDOM statement may be used with TYPE=UN
and possibly the GROUP= option to specify the among-individual
covariance matrix G (possibly different by levels of GROUP).
The REPEATED statement may be used with various TYPE= specifications,
and possibly the GROUP = option with SUBJECT = to
specify the within-individual covariance matrix R_i.
```{r engine="sas", engine.path="C:/Program Files/SASHome/SASFoundation/9.4/sas.exe", engine.opts="-nosplash -linesize 75", collectcode=TRUE}
proc import DATAFILE='C:\Users\juarezce\OneDrive - The University of Colorado Denver\BIOS6643\BIOS6643_Notes\data\dental.csv'
replace out=dental0 dbms=csv; run;
data dental;
set dental0;
time=age;
run;
proc print data=dental(obs=2);run;
title '(a) DIAGONAL WITHIN-CHILD COVARIANCE MATRIX R_i';
title2 'WITH CONSTANT VARIANCE SAME FOR EACH GENDER';
title3 'SAME G MATRIX FOR BOTH GENDERS';
proc mixed method=ml data=dental;
class gender id;
model distance = gender gender*age / noint solution;
random intercept age / type=un subject=id g gcorr v vcorr;
run;
/******************************************************************
MODEL (b)
Fit the same model as (a) but with a separate diagonal Ri matrix for
each gender. Thus, there are 2 separate variances sigma^2_(G and B)
specified using GROUP=GENDER in the REPEATED statement
D still = (2x2) unstructured matrix same for both genders as in (a)
(specified in the RANDOM statement)
*******************************************************************/
title '(b) DIAGONAL WITHIN-CHILD COVARIANCE MATRIX R_i';
title2 'WITH SEPARATE CONSTANT VARIANCE FOR EACH GENDER';
title3 'SAME D MATRIX FOR BOTH GENDERS';
proc mixed method=ml data=dental;
class id gender;
model distance = gender gender*age / noint solution;
repeated / group=gender subject=id r=1,4 rcorr=1,4;
random intercept age / type=un subject=id g gcorr v=1,4 vcorr=1,4;
run;
/******************************************************************
MODEL (b2)
*******************************************************************/
title '(c) COMMON AR(1) WITHIN-CHILD REALIZATION COMPONENT AND';
title2 'COMMON WITHIN-CHILD COMPONENT FOR R_i';
title3 'SAME G MATRIX FOR BOTH GENDERS';
proc mixed method=ml data=dental;
class gender id time;
model distance = gender gender*age / noint solution ;
random intercept age / type=un subject=id g gcorr v vcorr;
repeated / type=ar(1) subject=id rcorr r;
run;
/******************************************************************
*******************************************************************/
title '(d) COMMON AR(1) WITHIN-CHILD REALIZATION COMPONENT AND';
title2 'COMMON WITHIN-CHILD COMPONENT FOR R_i';
title3 'USING EXPONENTIAL MODEL; SAME G MATRIX FOR BOTH GENDERS';
proc mixed method=ml data=dental;
class gender id age;
model distance = gender gender*age / noint solution ;
* random intercept age / type=un subject=id g gcorr v vcorr;
repeated age / type=sp(exp)(age) subject=id rcorr r;
run;
/******************************************************************
MODEL (b2)
Fit the same model as (b) but now with D a (2x2) unstructured
matrix different across genders, so there are two matrices G_Girls and G_Boys
This is specified in the RANDOM statement by the GROUP=GENDER option
*******************************************************************/
title '(b2) DIAGONAL WITHIN-CHILD COVARIANCE MATRIX R_i';
title2 'WITH SEPARATE CONSTANT VARIANCE FOR EACH GENDER';
title3 'DIFFERENT G MATRIX FOR BOTH GENDERS';
proc mixed method=ml data=dental;
class id gender;
model distance = gender gender*age / noint solution;
repeated / group=gender subject=id;
random intercept age / type=un group=gender subject=id g gcorr v=1,12 vcorr=1,12;
run;
/* */
```