-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisolation_mhealth_overlap_ACE_sexdiffs.Rmd
2421 lines (1891 loc) · 98.6 KB
/
isolation_mhealth_overlap_ACE_sexdiffs.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "The overlap between social isolation and mental health problems: ACE herogeniety model (sex differences)"
output:
html_document:
df_print: paged
toc: yes
toc_depth: 2
toc_float:
collapsed: false
number_sections: false
highlight: monochrome
theme: flatly
code_folding: show
includes:
after_body: footer.html
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,
comment = NA,
prompt = FALSE,
cache = FALSE,
message = FALSE,
warning = FALSE,
results = 'markup')
options(bitmapType = 'quartz') # to render fonts better
```
```{r Clear global environment, include=FALSE}
remove(list = ls())
```
```{r Load packages, include=FALSE}
library(knitr)
library(haven)
library(psych)
library(bestNormalize)
library(OpenMx)
library(tidyr)
library(tidyverse)
library(dplyr) # conflicts with tidyverse for e.g. rename and row_number
```
# Source functions
```{r source functions, include=FALSE}
source("isolation_mhealth_functions.R")
```
# Read in data
```{r source the data file path, include=FALSE}
# source raw data directory
source("../isolation_mentalhealth_data_path.R")
```
```{r read in dta data file, include=FALSE}
dat.raw <- read_dta(paste0(data_path_raw, "Katie_23Sep22.dta"))
colnames(dat.raw)
```
### Column names
```{r select variables needed}
dat <- dat.raw %>%
dplyr::select(
atwinid,
btwinid,
familyid,
rorderp5,
torder,
zygosity,
sampsex,
sisoe12,
sisoy12,
masce12, # anxiety
mascy12,
cdie12, # depression
cdiy12,
conec12, # antisocial behaviour / conduct disorder
conyc12,
psysympe12, # psychosis - why is this not the tot scale variable - to give more variation?
psysympy12,
socisoe18,
socisoy18,
gadsxe18, # anxiety
gadsxy18,
mdesxe18, # depression
mdesxy18,
cdsxe18, # antisocial behaviour / conduct disorder
cdsxy18,
psyexpe18, # psychotic experiences
psyexpy18
)
colnames(dat)
```
### Recode variables into factors {.tabset .tabset-fade}
#### Sex
```{r recode sex}
dat <- dat %>%
mutate(
sex =
recode_factor(as_factor(sampsex),
"1" = "Male",
"2" = "Female"))
table(dat$sex)
```
#### Zygosity
```{r recode zygosity}
dat <- dat %>%
mutate(
zygosity =
recode_factor(as_factor(zygosity),
"1" = "MZ",
"2" = "DZ"))
table(dat$zygosity)
```
### Convert variables to numeric
```{r create numeric isolation variables}
dat <- dat %>%
mutate(
sisoe12 = as.numeric(sisoe12),
sisoy12 = as.numeric(sisoy12),
masce12 = as.numeric(masce12), # anxiety
mascy12 = as.numeric(mascy12),
cdie12 = as.numeric(cdie12), # depression
cdiy12 = as.numeric(cdiy12),
conec12 = as.numeric(conec12), # antisocial behaviour / conduct disorder
conyc12 = as.numeric(conyc12),
psysympe12 = as.numeric(psysympe12), # psychosis - why is this not the tot scale variable - to give more variation?
psysympy12 = as.numeric(psysympy12),
socisoe18 = as.numeric(socisoe18),
socisoy18 = as.numeric(socisoy18),
gadsxe18 = as.numeric(gadsxe18), # anxiety
gadsxy18 = as.numeric(gadsxy18),
mdesxe18 = as.numeric(mdesxe18), # depression
mdesxy18 = as.numeric(mdesxy18),
cdsxe18 = as.numeric(cdsxe18), # antisocial behaviour / conduct disorder
cdsxy18 = as.numeric(cdsxy18),
psyexpe18 = as.numeric(psyexpe18), # psychotic experiences
psyexpy18 = as.numeric(psyexpy18)
) %>%
select( # remove variables not needed
-c(sampsex)
)
```
# Variable lists
```{r select variables - raw}
# social isolation
selvars_si12 <- c("sisoe12", "sisoy12")
selvars_si18 <- c("socisoe18", "socisoy18")
# anxiety
selvars_anx12 <- c("masce12", "mascy12")
selvars_anx18 <- c("gadsxe18", "gadsxy18")
# depression
selvars_dep12 <- c("cdie12", "cdiy12")
selvars_dep18 <- c("mdesxe18", "mdesxy18")
# conduct
selvars_con12 <- c("conec12", "conyc12")
selvars_con18 <- c("cdsxe18", "cdsxy18")
# psychosis
selvars_psy12 <- c("psysympe12", "psysympy12")
selvars_psy18 <- c("psyexpe18", "psyexpy18")
# all
selvars <- c("sisoe12", "masce12", "cdie12", "conec12", "psysympe12", "socisoe18", "gadsxe18", "mdesxe18", "cdsxe18", "psyexpe18",
"sisoy12", "mascy12", "cdiy12", "conyc12", "psysympy12", "socisoy18", "gadsxy18", "mdesxy18", "cdsxy18","psyexpy18")
selvars_e <- c("sisoe12", "masce12", "cdie12", "conec12", "psysympe12", "socisoe18", "gadsxe18", "mdesxe18", "cdsxe18", "psyexpe18")
```
```{r select variables - normalised}
# social isolation
selvars_si12norm <- c("sisoe12norm", "sisoy12norm")
selvars_si18norm <- c("socisoe18norm", "socisoy18norm")
# anxiety
selvars_anx12norm <- c("masce12norm", "mascy12norm")
selvars_anx18norm <- c("gadsxe18norm", "gadsxy18norm")
# depression
selvars_dep12norm <- c("cdie12norm", "cdiy12norm")
selvars_dep18norm <- c("mdesxe18norm", "mdesxy18norm")
# conduct
selvars_con12norm <- c("conec12norm", "conyc12norm")
selvars_con18norm <- c("cdsxe18norm", "cdsxy18norm")
# psychosis
selvars_psy12norm <- c("psysympe12norm", "psysympy12norm")
selvars_psy18norm <- c("psyexpe18norm", "psyexpy18norm")
# all
selvars_norm <- c("sisoe12norm", "masce12norm", "cdie12norm", "conec12norm", "psysympe12norm", "socisoe18norm", "gadsxe18norm", "mdesxe18norm", "cdsxe18norm", "psyexpe18norm",
"sisoy12norm", "mascy12norm", "cdiy12norm", "conyc12norm", "psysympy12norm", "socisoy18norm", "gadsxy18norm", "mdesxy18norm", "cdsxy18norm", "psyexpy18norm")
# all with non-normalised - not in the twin modelling specific order here only used to standardise all variables at once
selvars_norm_all <- c("sisoe12", "sisoy12", "masce12", "mascy12", "cdie12", "cdiy12", "conec12", "conyc12", "psysympe12", "psysympy12",
"socisoe18", "socisoy18", "gadsxe18", "gadsxy18", "mdesxe18", "mdesxy18", "cdsxe18", "cdsxy18", "psyexpe18", "psyexpy18",
"sisoe12norm", "sisoy12norm", "masce12norm", "mascy12norm", "cdie12norm", "cdiy12norm", "conec12norm", "conyc12norm", "psysympe12norm", "psysympy12norm",
"socisoe18norm", "socisoy18norm", "gadsxe18norm", "gadsxy18norm", "mdesxe18norm", "mdesxy18norm", "cdsxe18norm", "cdsxy18norm", "psyexpe18norm", "psyexpy18norm")
```
```{r select variables - normalised and regressed sex}
# social isolation
selvars_si12norm_reg <- c("sisoe12norm_reg", "sisoy12norm_reg")
selvars_si18norm_reg <- c("socisoe18norm_reg", "socisoy18norm_reg")
# anxiety
selvars_anx12norm_reg <- c("masce12norm_reg", "mascy12norm_reg")
selvars_anx18norm_reg <- c("gadsxe18norm_reg", "gadsxy18norm_reg")
# depression
selvars_dep12norm_reg <- c("cdie12norm_reg", "cdiy12norm_reg")
selvars_dep18norm_reg <- c("mdesxe18norm_reg", "mdesxy18norm_reg")
# conduct
selvars_con12norm_reg <- c("conec12norm_reg", "conyc12norm_reg")
selvars_con18norm_reg <- c("cdsxe18norm_reg", "cdsxy18norm_reg")
# psychosis
selvars_psy12norm_reg <- c("psysympe12norm_reg", "psysympy12norm_reg")
selvars_psy18norm_reg <- c("psyexpe18norm_reg", "psyexpy18norm_reg")
# all
selvars_norm_reg <- c("sisoe12norm_reg", "masce12norm_reg", "cdie12norm_reg", "conec12norm_reg", "psysympe12norm_reg", "socisoe18norm_reg", "gadsxe18norm_reg", "mdesxe18norm_reg", "cdsxe18norm_reg", "psyexpe18norm_reg",
"sisoy12norm_reg", "mascy12norm_reg", "cdiy12norm_reg", "conyc12norm_reg", "psysympy12norm_reg", "socisoy18norm_reg", "gadsxy18norm_reg", "mdesxy18norm_reg", "cdsxy18norm_reg", "psyexpy18norm_reg")
# all with non-norm_regalised - not in the twin modelling specific order here only used to standardise all variables at once
selvars_norm_reg_all <- c("sisoe12", "sisoy12", "masce12", "mascy12", "cdie12", "cdiy12", "conec12", "conyc12", "psysympe12", "psysympy12",
"socisoe18", "socisoy18", "gadsxe18", "gadsxy18", "mdesxe18", "mdesxy18", "cdsxe18", "cdsxy18", "psyexpe18", "psyexpy18",
"sisoe12norm_reg", "sisoy12norm_reg", "masce12norm_reg", "mascy12norm_reg", "cdie12norm_reg", "cdiy12norm_reg", "conec12norm_reg", "conyc12norm_reg", "psysympe12norm_reg", "psysympy12norm_reg",
"socisoe18norm_reg", "socisoy18norm_reg", "gadsxe18norm_reg", "gadsxy18norm_reg", "mdesxe18norm_reg", "mdesxy18norm_reg", "cdsxe18norm_reg", "cdsxy18norm_reg", "psyexpe18norm_reg", "psyexpy18norm_reg")
```
# Data prep
## Skewness
```{r histograms}
# isolation
hist(dat$sisoe12) # not normal
hist(dat$socisoe18) # not normal
# anxiety
hist(dat$masce12) # normal
hist(dat$gadsxe18) # not normal
# depression
hist(dat$cdie12) # not normal
hist(dat$mdesxe18) # not normal
# conduct
hist(dat$conec12) # not normal
hist(dat$cdsxe18) # not normal
# psychosis
hist(dat$psysympe12) # not normal
hist(dat$psyexpe18) # not normal
```
## Rank transformation
Almost all variables are non-normal. We will use the van der Waerden's rank-based transformation as used in [Rimfeld et al 2021](https://acamh.onlinelibrary.wiley.com/doi/full/10.1002/jcv2.12053). For analyses using transformed data, they conducted the van der Waerden transformation prior to residualizing for age and sex as recommended by [Pain et al. 2018](https://www.nature.com/articles/s41431-018-0159-6).
I will transform all variables to get the normalised estimate.
```{r rank transform variables elder variables}
# isolation age 12
sisoe12_n <- bestNormalize(dat$sisoe12) # select the type of transformation needed
dat$sisoe12norm <- predict(sisoe12_n) # create normalised variable
hist(dat$sisoe12norm)
summary(dat$sisoe12norm)
# isolation age 18
socisoe18_n <- bestNormalize(dat$socisoe18)
dat$socisoe18norm <- predict(socisoe18_n)
hist(dat$socisoe18norm)
summary(dat$socisoe18norm)
# anxiety age 12 - wont actually use this as it's already normally distributed
masce12_n <- bestNormalize(dat$masce12)
dat$masce12norm <- predict(masce12_n)
hist(dat$masce12norm)
summary(dat$masce12norm)
# anxiety age 18
gadsxe18_n <- bestNormalize(dat$gadsxe18)
dat$gadsxe18norm <- predict(gadsxe18_n)
hist(dat$gadsxe18norm)
summary(dat$gadsxe18norm)
# depression age 12
cdie12_n <- bestNormalize(dat$cdie12)
dat$cdie12norm <- predict(cdie12_n)
hist(dat$cdie12norm)
summary(dat$cdie12norm)
# depression age 18
mdesxe18_n <- bestNormalize(dat$mdesxe18)
dat$mdesxe18norm <- predict(mdesxe18_n)
hist(dat$mdesxe18norm)
summary(dat$mdesxe18norm)
# conduct age 12
conec12_n <- bestNormalize(dat$conec12)
dat$conec12norm <- predict(conec12_n)
hist(dat$conec12norm)
summary(dat$conec12norm)
# conduct age 18
cdsxe18_n <- bestNormalize(dat$cdsxe18)
dat$cdsxe18norm <- predict(cdsxe18_n)
hist(dat$cdsxe18norm)
summary(dat$cdsxe18norm)
# psychosis age 12
psysympe12_n <- bestNormalize(dat$psysympe12)
dat$psysympe12norm <- predict(psysympe12_n)
hist(dat$psysympe12norm)
summary(dat$psysympe12norm)
# psychosis age 18
psyexpe18_n <- bestNormalize(dat$psyexpe18)
dat$psyexpe18norm <- predict(psyexpe18_n)
hist(dat$psyexpe18norm)
summary(dat$psyexpe18norm)
```
```{r rank transform variables younger variables}
# isolation age 12
sisoy12_n <- bestNormalize(dat$sisoy12) # select the type of transformation needed
dat$sisoy12norm <- predict(sisoy12_n) # create normalised variable
hist(dat$sisoy12norm)
summary(dat$sisoy12norm)
# isolation age 18
socisoy18_n <- bestNormalize(dat$socisoy18)
dat$socisoy18norm <- predict(socisoy18_n)
hist(dat$socisoy18norm)
summary(dat$socisoy18norm)
# anxiety age 12 - wont actually use this as it's already normally distributed
mascy12_n <- bestNormalize(dat$mascy12)
dat$mascy12norm <- predict(mascy12_n)
hist(dat$mascy12norm)
summary(dat$mascy12norm)
# anxiety age 18
gadsxy18_n <- bestNormalize(dat$gadsxy18)
dat$gadsxy18norm <- predict(gadsxy18_n)
hist(dat$gadsxy18norm)
summary(dat$gadsxy18norm)
# depression age 12
cdiy12_n <- bestNormalize(dat$cdiy12)
dat$cdiy12norm <- predict(cdiy12_n)
hist(dat$cdiy12norm)
summary(dat$cdiy12norm)
# depression age 18
mdesxy18_n <- bestNormalize(dat$mdesxy18)
dat$mdesxy18norm <- predict(mdesxy18_n)
hist(dat$mdesxy18norm)
summary(dat$mdesxy18norm)
# conduct age 12
conyc12_n <- bestNormalize(dat$conyc12)
dat$conyc12norm <- predict(conyc12_n)
hist(dat$conyc12norm)
summary(dat$conyc12norm)
# conduct age 18
cdsxy18_n <- bestNormalize(dat$cdsxy18)
dat$cdsxy18norm <- predict(cdsxy18_n)
hist(dat$cdsxy18norm)
summary(dat$cdsxy18norm)
# psychosis age 12
psysympy12_n <- bestNormalize(dat$psysympy12)
dat$psysympy12norm <- predict(psysympy12_n)
hist(dat$psysympy12norm)
summary(dat$psysympy12norm)
# psychosis age 18
psyexpy18_n <- bestNormalize(dat$psyexpy18)
dat$psyexpy18norm <- predict(psyexpy18_n)
hist(dat$psyexpy18norm)
summary(dat$psyexpy18norm)
```
## Regress out sex
We first normalised the twin variables, then regress out sex. We don't regress out age here as all twins were measured as close to thir birthday as possible.
```{r Regress out age and sex}
# twin 1 - elder
## isolation
dat$sisoe12norm_reg <- (resid(lm(data = dat, sisoe12norm ~ sex, na.action = na.exclude))) + 1
dat$socisoe18norm_reg <- (resid(lm(data = dat, socisoe18norm ~ sex, na.action = na.exclude))) + 1
## anxiety
dat$masce12norm_reg <- (resid(lm(data = dat, masce12norm ~ sex, na.action = na.exclude))) + 1
dat$gadsxe18norm_reg <- (resid(lm(data = dat, gadsxe18norm ~ sex, na.action = na.exclude))) + 1
## depression
dat$cdie12norm_reg <- (resid(lm(data = dat, cdie12norm ~ sex, na.action = na.exclude))) + 1
dat$mdesxe18norm_reg <- (resid(lm(data = dat, mdesxe18norm ~ sex, na.action = na.exclude))) + 1
## conduct
dat$conec12norm_reg <- (resid(lm(data = dat, conec12norm ~ sex, na.action = na.exclude))) + 1
dat$cdsxe18norm_reg <- (resid(lm(data = dat, cdsxe18norm ~ sex, na.action = na.exclude))) + 1
## psychosis
dat$psysympe12norm_reg <- (resid(lm(data = dat, psysympe12norm ~ sex, na.action = na.exclude))) + 1
dat$psyexpe18norm_reg <- (resid(lm(data = dat, psyexpe18norm ~ sex, na.action = na.exclude))) + 1
# twin 2 - younger
## isolation
dat$sisoy12norm_reg <- (resid(lm(data = dat, sisoy12norm ~ sex, na.action = na.exclude))) + 1
dat$socisoy18norm_reg <- (resid(lm(data = dat, socisoy18norm ~ sex, na.action = na.exclude))) + 1
## anxiety
dat$mascy12norm_reg <- (resid(lm(data = dat, mascy12norm ~ sex, na.action = na.exclude))) + 1
dat$gadsxy18norm_reg <- (resid(lm(data = dat, gadsxy18norm ~ sex, na.action = na.exclude))) + 1
## depression
dat$cdiy12norm_reg <- (resid(lm(data = dat, cdiy12norm ~ sex, na.action = na.exclude))) + 1
dat$mdesxy18norm_reg <- (resid(lm(data = dat, mdesxy18norm ~ sex, na.action = na.exclude))) + 1
## conduct
dat$conyc12norm_reg <- (resid(lm(data = dat, conyc12norm ~ sex, na.action = na.exclude))) + 1
dat$cdsxy18norm_reg <- (resid(lm(data = dat, cdsxy18norm ~ sex, na.action = na.exclude))) + 1
## psychosis
dat$psysympy12norm_reg <- (resid(lm(data = dat, psysympy12norm ~ sex, na.action = na.exclude))) + 1
dat$psyexpy18norm_reg <- (resid(lm(data = dat, psyexpy18norm ~ sex, na.action = na.exclude))) + 1
```
## Create twin dataset
To remove the double entry in the data, we will remove everyone who has a "random twin order" variable of 0. This will then remove any birth order effects.
```{r remove one twin pair row}
dat.twin <- dat %>% filter(rorderp5 == "1")
```
```{r datasets for MZ and DZ}
dat.twin.MZ <- dat.twin %>% filter(zygosity == "MZ")
dat.twin.DZ <- dat.twin %>% filter(zygosity == "DZ")
# male only
dat.twin.MZm <- dat.twin.MZ %>% filter(sex == "Male")
dat.twin.DZm <- dat.twin.DZ %>% filter(sex == "Male")
# female only
dat.twin.MZf <- dat.twin.MZ %>% filter(sex == "Female")
dat.twin.DZf <- dat.twin.DZ %>% filter(sex == "Female")
```
## Summary of MZ and DZ data
### Overall
```{r describe MZ and DZ data}
MZ_summary <- describe(dat.twin.MZ,
skew = FALSE,
range = FALSE)
DZ_summary <- describe(dat.twin.DZ,
skew = FALSE,
range = FALSE)
```
### MZ correlations
```{r MZ matrices}
# covariance matrix
covar.mz <- cov(dat.twin.MZ[, selvars], use = "complete")
# correlation matrix (standardized covariance)
cor.mz <- cor(dat.twin.MZ[, selvars], use = "complete")
# round(cor.mz, 3)
```
### DZ correlations
```{r DZ matrices}
# covariance matrix
covar.dz <- cov(dat.twin.DZ[, selvars], use = "complete")
# correlation matrix (standardized covariance)
cor.dz <- cor(dat.twin.DZ[, selvars], use = "complete")
# round(cor.dz, 3)
```
# Heterogeneity ACE model
This model tests whether genes and environment influence a trait to a different degree in males and females - i.e. do they show quantitative sex differences.
Sex-limited expression of genetic or environmental factors occurs in two basic forms. First, the effects of a factor may be larger on one sex than on another, which is known as *scalar sex limitation*. Second, some factors may have an effect on one sex but not on the other, which is called nonscalar sex limitation. In the classical twin study, scalar sex- limited effects cause same-sex male and same-sex female twin correlations to differ (Neale, Røysamb, and Jacobson, 2006).
## Specify
This model will be applied to all variables at age 12 and 18 - social isolation, anxiety, depression, conduct disorder, psychosis.
```{r number of variables (phenotypes)}
# number of variables
nv <- 1 # number of variables
ntv <- nv*2 # number of twin variables
# default optimizer
mxOption(NULL, "Default optimizer", "CSOLNP")
```
```{r start values}
# start values
svM <- c(rep(0.7, ntv)) # means
svSD <- c(rep(1.1, ntv)) # standard deviations
svRmz <- c(0.3) # correlations for MZ
svRdz <- c(0.15) # correlations for DZ
rowVars <- rep('Vars', nv)
colVars <- rep(c('h2', 'c2', 'e2'), each = nv)
```
```{r specify quantitative heterogeneity ACE model}
# Matrix & Algebra for expected means vector
MeanM <- mxMatrix(type = "Full", nrow = 1, ncol = nv, free = TRUE, values = 0, label = "meanm", name = "Mm")
MeanMM <- mxAlgebra(expression = cbind(Mm, Mm), name = "expMeanm")
MeanF <- mxMatrix(type = "Full", nrow = 1, ncol = nv, free = TRUE, values = 0, label = "meanf", name = "Mf" )
MeanFF <- mxAlgebra(expression = cbind(Mf, Mf), name = "expMeanf")
# Define Matrices to estimate a, c, and e path coefficients for Males And Females
pathAm <- mxMatrix(type = "Full", nrow = nv, ncol = nv, free = TRUE, values = 0.6, label = "am11", name = "am")
pathCm <- mxMatrix(type = "Full", nrow = nv, ncol = nv, free = TRUE, values = 0.6, label = "cm11", name = "cm")
pathEm <- mxMatrix(type = "Full", nrow = nv, ncol = nv, free = TRUE, values = 0.6, label = "em11", name = "em")
pathAf <- mxMatrix(type = "Full", nrow = nv, ncol = nv, free = TRUE, values = 0.6, label = "af11", name = "af")
pathCf <- mxMatrix(type = "Full", nrow = nv, ncol = nv, free = TRUE, values = 0.6, label = "cf11", name = "cf")
pathEf <- mxMatrix(type = "Full", nrow = nv, ncol = nv, free = TRUE, values = 0.6, label = "ef11", name = "ef")
# Matrices A, C, and E compute variance components
covAm <- mxAlgebra(expression = am %*% t(am), name = "Am")
covCm <- mxAlgebra(expression = cm %*% t(cm), name = "Cm")
covEm <- mxAlgebra(expression = em %*% t(em), name = "Em")
covAf <- mxAlgebra(expression = af %*% t(af), name = "Af")
covCf <- mxAlgebra(expression = cf %*% t(cf), name = "Cf")
covEf <- mxAlgebra(expression = ef %*% t(ef), name = "Ef")
# Algebra to compute total variances and standard deviations (diagonal only)
Varm <- mxAlgebra(expression = Am + Cm + Em, name = "Vm")
Varf <- mxAlgebra(expression = Af + Cf + Ef, name = "Vf")
# Algebra to compute standardized variance components
h2m <- mxAlgebra(expression = Am/Vm, name = "hm2")
c2m <- mxAlgebra(expression = Cm/Vm, name = "cm2")
e2m <- mxAlgebra(expression = Em/Vm, name = "em2")
h2f <- mxAlgebra(expression = Af/Vf, name = "hf2")
c2f <- mxAlgebra(expression = Cf/Vf, name = "cf2")
e2f <- mxAlgebra(expression = Ef/Vf, name = "ef2")
# Algebra for expected variance/covariance matrix in the 4 groups
covMZM <- mxAlgebra(expression = rbind(cbind(Am + Cm + Em, Am+Cm), cbind(Am + Cm, Am + Cm + Em)), name = "expCovMZM")
covMZF <- mxAlgebra(expression = rbind(cbind(Af + Cf + Ef, Af+Cf), cbind(Af + Cf, Af + Cf + Ef)), name = "expCovMZF")
covDZM <- mxAlgebra(expression = rbind(cbind(Am + Cm + Em, 0.5%x%Am + Cm), cbind(0.5%x%Am + Cm, Am + Cm + Em)), name = "expCovDZM")
covDZF <- mxAlgebra(expression = rbind(cbind(Af + Cf + Ef, 0.5%x%Af + Cf), cbind(0.5%x%Af + Cf, Af + Cf + Ef)), name = "expCovDZF")
# Data objects for Multiple Groups
dataMZM <- mxData(observed = dat.twin.MZm, type = "raw")
dataDZM <- mxData(observed = dat.twin.DZm, type = "raw")
dataMZF <- mxData(observed = dat.twin.MZf, type = "raw")
dataDZF <- mxData(observed = dat.twin.DZf, type = "raw")
# fit function
fitFunction <- mxFitFunctionML()
obj <-mxFitFunctionAlgebra("m2LL")
# confidence intervals
ciM <- mxCI(c('hm2', 'cm2', 'em2'))
ciF <- mxCI(c('hf2', 'cf2', 'ef2'))
```
## Social isolation
### Age 12
```{r select which variables to use}
# selvars_si12_chosen <- selvars_si12 # raw
# selvars_si12_chosen <- selvars_si12_z_score # standardised
# selvars_si12_chosen <- selvars_si12norm # normalised
# selvars_si12_chosen <- selvars_si12_z_score_norm # standardised and normalised
selvars_si12_chosen <- selvars_si12norm_reg # normalised and regressed sex
```
```{r fit het model for social isolation 12}
# Objective objects for Multiple Groups
objMZM <- mxExpectationNormal(covariance = "expCovMZM", means = "expMeanm", dimnames = selvars_si12_chosen)
objDZM <- mxExpectationNormal(covariance = "expCovDZM", means = "expMeanm", dimnames = selvars_si12_chosen)
objMZF <- mxExpectationNormal(covariance = "expCovMZF", means = "expMeanf", dimnames = selvars_si12_chosen)
objDZF <- mxExpectationNormal(covariance = "expCovDZF", means = "expMeanf", dimnames = selvars_si12_chosen)
# Combine Groups
parsm <- list(pathAm, pathCm, pathEm, covAm, covCm, covEm, Varm, h2m, c2m, e2m)
parsf <- list(pathAf, pathCf, pathEf, covAf, covCf, covEf, Varf, h2f, c2f, e2f)
modelMZM <- mxModel(parsm, MeanM, MeanMM, covMZM, dataMZM, objMZM, fitFunction, name = "MZM")
modelDZM <- mxModel(parsm, MeanM, MeanMM, covDZM, dataDZM, objDZM, fitFunction, name = "DZM")
modelMZF <- mxModel(parsf, MeanF, MeanFF, covMZF, dataMZF, objMZF, fitFunction, name = "MZF")
modelDZF <- mxModel(parsf, MeanF, MeanFF, covDZF, dataDZF, objDZF, fitFunction, name = "DZF")
minus2ll <-mxAlgebra(expression = MZM.objective + DZM.objective + MZF.objective + DZF.objective, name = "m2LL")
hetace_isolation12 <-mxModel("univHetACE", parsm, parsf, modelMZM, modelDZM, modelMZF, modelDZF, minus2ll, obj, ciM, ciF)
```
```{r run het model for social isolation 12}
# Run
hetace_fit_isolation12 <- mxTryHard(hetace_isolation12, intervals = TRUE)
hetace_isolation12_summ <- summary(hetace_fit_isolation12)
# Table
hetace_isolation12_table <- ACEhet_esitmates_table(data = hetace_isolation12_summ,
variable = "Social isolation",
age = "12")
hetace_isolation12_table
```
```{r specify and run the sub-model homogeneity ACE model isolation 12}
homace_isolation12 <- mxModel(hetace_fit_isolation12, name = "homace")
homace_isolation12 <- omxSetParameters(homace_isolation12,
labels = c("am11", "cm11", "em11", "af11", "cf11", "ef11"), free = TRUE, values = 0.6,
newlabels = c("a11", "c11", "e11", "a11", "c11", "e11"))
homace_fit_isolation12 <- mxTryHard(homace_isolation12, intervals = TRUE)
homace_fit_isolation12_summ <- summary(homace_fit_isolation12)
# parameter estimates (check that hf2,cf2 and ef2 are the same)
homace_isolation12_table <- ACEhet_esitmates_table(data = homace_fit_isolation12_summ,
variable = "Social isolation",
age = "12")
homace_isolation12_table
# compare het and hom
mxCompare(hetace_fit_isolation12, homace_fit_isolation12)
```
### Age 18
```{r select which variables to use}
# selvars_si18_chosen <- selvars_si18 # raw
# selvars_si18_chosen <- selvars_si18_z_score # standardised
# selvars_si18_chosen <- selvars_si18norm # normalised
# selvars_si18_chosen <- selvars_si18_z_score_norm # standardised and normalised
selvars_si18_chosen <- selvars_si18norm_reg # normalised and regressed sex
```
```{r fit het model for social isolation 18}
# Objective objects for Multiple Groups
objMZM <- mxExpectationNormal(covariance = "expCovMZM", means = "expMeanm", dimnames = selvars_si18_chosen)
objDZM <- mxExpectationNormal(covariance = "expCovDZM", means = "expMeanm", dimnames = selvars_si18_chosen)
objMZF <- mxExpectationNormal(covariance = "expCovMZF", means = "expMeanf", dimnames = selvars_si18_chosen)
objDZF <- mxExpectationNormal(covariance = "expCovDZF", means = "expMeanf", dimnames = selvars_si18_chosen)
# Combine Groups
parsm <- list(pathAm, pathCm, pathEm, covAm, covCm, covEm, Varm, h2m, c2m, e2m)
parsf <- list(pathAf, pathCf, pathEf, covAf, covCf, covEf, Varf, h2f, c2f, e2f)
modelMZM <- mxModel(parsm, MeanM, MeanMM, covMZM, dataMZM, objMZM, fitFunction, name = "MZM")
modelDZM <- mxModel(parsm, MeanM, MeanMM, covDZM, dataDZM, objDZM, fitFunction, name = "DZM")
modelMZF <- mxModel(parsf, MeanF, MeanFF, covMZF, dataMZF, objMZF, fitFunction, name = "MZF")
modelDZF <- mxModel(parsf, MeanF, MeanFF, covDZF, dataDZF, objDZF, fitFunction, name = "DZF")
minus2ll <-mxAlgebra(expression = MZM.objective + DZM.objective + MZF.objective + DZF.objective, name = "m2LL")
hetace_isolation18 <-mxModel("univHetACE", parsm, parsf, modelMZM, modelDZM, modelMZF, modelDZF, minus2ll, obj, ciM, ciF)
```
```{r run het model for social isolation 18}
# Run
hetace_fit_isolation18 <- mxTryHard(hetace_isolation18, intervals = TRUE)
hetace_isolation18_summ <- summary(hetace_fit_isolation18)
# Table
hetace_isolation18_table <- ACEhet_esitmates_table(data = hetace_isolation18_summ,
variable = "Social isolation",
age = "18")
hetace_isolation18_table
```
```{r specify and run the sub-model homogeneity ACE model isolation 18}
homace_isolation18 <- mxModel(hetace_fit_isolation18, name = "homace")
homace_isolation18 <- omxSetParameters(homace_isolation18,
labels = c("am11", "cm11", "em11", "af11", "cf11", "ef11"), free = TRUE, values = 0.6,
newlabels = c("a11", "c11", "e11", "a11", "c11", "e11"))
homace_fit_isolation18 <- mxTryHard(homace_isolation18, intervals = TRUE)
homace_fit_isolation18_summ <- summary(homace_fit_isolation18)
# parameter estimates (check that hf2,cf2 and ef2 are the same)
homace_isolation18_table <- ACEhet_esitmates_table(data = homace_fit_isolation18_summ,
variable = "Social isolation",
age = "18")
homace_isolation18_table
# compare het and hom
mxCompare(hetace_fit_isolation18, homace_fit_isolation18)
```
## Anxiety
### Age 12
```{r select which variables to use}
# selvars_anx12_chosen <- selvars_anx12 # raw
# selvars_anx12_chosen <- selvars_anx12_z_score # standardised
# selvars_anx12_chosen <- selvars_anx12norm # normalised
# selvars_anx12_chosen <- selvars_anx12_z_score_norm # standardised and normalised
selvars_anx12_chosen <- selvars_anx12norm_reg # normalised and regressed sex
```
```{r fit het model for anxiety 12}
# Objective objects for Multiple Groups
objMZM <- mxExpectationNormal(covariance = "expCovMZM", means = "expMeanm", dimnames = selvars_anx12_chosen)
objDZM <- mxExpectationNormal(covariance = "expCovDZM", means = "expMeanm", dimnames = selvars_anx12_chosen)
objMZF <- mxExpectationNormal(covariance = "expCovMZF", means = "expMeanf", dimnames = selvars_anx12_chosen)
objDZF <- mxExpectationNormal(covariance = "expCovDZF", means = "expMeanf", dimnames = selvars_anx12_chosen)
# Combine Groups
parsm <- list(pathAm, pathCm, pathEm, covAm, covCm, covEm, Varm, h2m, c2m, e2m)
parsf <- list(pathAf, pathCf, pathEf, covAf, covCf, covEf, Varf, h2f, c2f, e2f)
modelMZM <- mxModel(parsm, MeanM, MeanMM, covMZM, dataMZM, objMZM, fitFunction, name = "MZM")
modelDZM <- mxModel(parsm, MeanM, MeanMM, covDZM, dataDZM, objDZM, fitFunction, name = "DZM")
modelMZF <- mxModel(parsf, MeanF, MeanFF, covMZF, dataMZF, objMZF, fitFunction, name = "MZF")
modelDZF <- mxModel(parsf, MeanF, MeanFF, covDZF, dataDZF, objDZF, fitFunction, name = "DZF")
minus2ll <-mxAlgebra(expression = MZM.objective + DZM.objective + MZF.objective + DZF.objective, name = "m2LL")
hetace_anxiety12 <-mxModel("univHetACE", parsm, parsf, modelMZM, modelDZM, modelMZF, modelDZF, minus2ll, obj, ciM, ciF)
```
```{r run het model for anxiety 12}
# Run
hetace_fit_anxiety12 <- mxTryHard(hetace_anxiety12, intervals = TRUE)
hetace_anxiety12_summ <- summary(hetace_fit_anxiety12)
# Table
hetace_anxiety12_table <- ACEhet_esitmates_table(data = hetace_anxiety12_summ,
variable = "Anxiety",
age = "12")
hetace_anxiety12_table
```
```{r specify and run the sub-model homogeneity ACE model anxiety 12}
homace_anxiety12 <- mxModel(hetace_fit_anxiety12, name = "homace")
homace_anxiety12 <- omxSetParameters(homace_anxiety12,
labels = c("am11", "cm11", "em11", "af11", "cf11", "ef11"), free = TRUE, values = 0.6,
newlabels = c("a11", "c11", "e11", "a11", "c11", "e11"))
homace_fit_anxiety12 <- mxTryHard(homace_anxiety12, intervals = TRUE)
homace_fit_anxiety12_summ <- summary(homace_fit_anxiety12)
# parameter estimates (check that hf2,cf2 and ef2 are the same)
homace_anxiety12_table <- ACEhet_esitmates_table(data = homace_fit_anxiety12_summ,
variable = "Anxiety",
age = "12")
homace_anxiety12_table
# compare het and hom
mxCompare(hetace_fit_anxiety12, homace_fit_anxiety12)
```
### Age 18
```{r select which variables to use}
# selvars_anx18_chosen <- selvars_anx18 # raw
# selvars_anx18_chosen <- selvars_anx18_z_score # standardised
# selvars_anx18_chosen <- selvars_anx18norm # normalised
# selvars_anx18_chosen <- selvars_anx18_z_score_norm # standardised and normalised
selvars_anx18_chosen <- selvars_anx18norm_reg # normalised and regressed sex
```
```{r fit het model for anxiety 18}
# Objective objects for Multiple Groups
objMZM <- mxExpectationNormal(covariance = "expCovMZM", means = "expMeanm", dimnames = selvars_anx18_chosen)
objDZM <- mxExpectationNormal(covariance = "expCovDZM", means = "expMeanm", dimnames = selvars_anx18_chosen)
objMZF <- mxExpectationNormal(covariance = "expCovMZF", means = "expMeanf", dimnames = selvars_anx18_chosen)
objDZF <- mxExpectationNormal(covariance = "expCovDZF", means = "expMeanf", dimnames = selvars_anx18_chosen)
# Combine Groups
parsm <- list(pathAm, pathCm, pathEm, covAm, covCm, covEm, Varm, h2m, c2m, e2m)
parsf <- list(pathAf, pathCf, pathEf, covAf, covCf, covEf, Varf, h2f, c2f, e2f)
modelMZM <- mxModel(parsm, MeanM, MeanMM, covMZM, dataMZM, objMZM, fitFunction, name = "MZM")
modelDZM <- mxModel(parsm, MeanM, MeanMM, covDZM, dataDZM, objDZM, fitFunction, name = "DZM")
modelMZF <- mxModel(parsf, MeanF, MeanFF, covMZF, dataMZF, objMZF, fitFunction, name = "MZF")
modelDZF <- mxModel(parsf, MeanF, MeanFF, covDZF, dataDZF, objDZF, fitFunction, name = "DZF")
minus2ll <-mxAlgebra(expression = MZM.objective + DZM.objective + MZF.objective + DZF.objective, name = "m2LL")
hetace_anxiety18 <-mxModel("univHetACE", parsm, parsf, modelMZM, modelDZM, modelMZF, modelDZF, minus2ll, obj, ciM, ciF)
```
```{r run het model for anxiety 18}
# Run
hetace_fit_anxiety18 <- mxTryHard(hetace_anxiety18, intervals = TRUE)
hetace_anxiety18_summ <- summary(hetace_fit_anxiety18)
# Table
hetace_anxiety18_table <- ACEhet_esitmates_table(data = hetace_anxiety18_summ,
variable = "Anxiety",
age = "18")
hetace_anxiety18_table
```
```{r specify and run the sub-model homogeneity ACE model anxiety 18}
homace_anxiety18 <- mxModel(hetace_fit_anxiety18, name = "homace")
homace_anxiety18 <- omxSetParameters(homace_anxiety18,
labels = c("am11", "cm11", "em11", "af11", "cf11", "ef11"), free = TRUE, values = 0.6,
newlabels = c("a11", "c11", "e11", "a11", "c11", "e11"))
homace_fit_anxiety18 <- mxTryHard(homace_anxiety18, intervals = TRUE)
homace_fit_anxiety18_summ <- summary(homace_fit_anxiety18)
# parameter estimates (check that hf2,cf2 and ef2 are the same)
homace_anxiety18_table <- ACEhet_esitmates_table(data = homace_fit_anxiety18_summ,
variable = "Anxiety",
age = "18")
homace_anxiety18_table
# compare het and hom
mxCompare(hetace_fit_anxiety18, homace_fit_anxiety18)
```
## Depression
### Age 12
```{r select which variables to use}
# selvars_dep12_chosen <- selvars_dep12 # raw
# selvars_dep12_chosen <- selvars_dep12_z_score # standardised
# selvars_dep12_chosen <- selvars_dep12norm # normalised
# selvars_dep12_chosen <- selvars_dep12_z_score_norm # standardised and normalised
selvars_dep12_chosen <- selvars_dep12norm_reg # normalised and regressed sex
```
```{r fit het model for depression 12}
# Objective objects for Multiple Groups
objMZM <- mxExpectationNormal(covariance = "expCovMZM", means = "expMeanm", dimnames = selvars_dep12_chosen)
objDZM <- mxExpectationNormal(covariance = "expCovDZM", means = "expMeanm", dimnames = selvars_dep12_chosen)
objMZF <- mxExpectationNormal(covariance = "expCovMZF", means = "expMeanf", dimnames = selvars_dep12_chosen)
objDZF <- mxExpectationNormal(covariance = "expCovDZF", means = "expMeanf", dimnames = selvars_dep12_chosen)
# Combine Groups
parsm <- list(pathAm, pathCm, pathEm, covAm, covCm, covEm, Varm, h2m, c2m, e2m)
parsf <- list(pathAf, pathCf, pathEf, covAf, covCf, covEf, Varf, h2f, c2f, e2f)
modelMZM <- mxModel(parsm, MeanM, MeanMM, covMZM, dataMZM, objMZM, fitFunction, name = "MZM")
modelDZM <- mxModel(parsm, MeanM, MeanMM, covDZM, dataDZM, objDZM, fitFunction, name = "DZM")
modelMZF <- mxModel(parsf, MeanF, MeanFF, covMZF, dataMZF, objMZF, fitFunction, name = "MZF")
modelDZF <- mxModel(parsf, MeanF, MeanFF, covDZF, dataDZF, objDZF, fitFunction, name = "DZF")
minus2ll <-mxAlgebra(expression = MZM.objective + DZM.objective + MZF.objective + DZF.objective, name = "m2LL")
hetace_depression12 <-mxModel("univHetACE", parsm, parsf, modelMZM, modelDZM, modelMZF, modelDZF, minus2ll, obj, ciM, ciF)
```
```{r run het model for depression 12}
# Run
hetace_fit_depression12 <- mxTryHard(hetace_depression12, intervals = TRUE)
hetace_depression12_summ <- summary(hetace_fit_depression12)
# Table
hetace_depression12_table <- ACEhet_esitmates_table(data = hetace_depression12_summ,
variable = "Depression",
age = "12")
hetace_depression12_table
```
```{r specify and run the sub-model homogeneity ACE model depression 12}
homace_depression12 <- mxModel(hetace_fit_depression12, name = "homace")
homace_depression12 <- omxSetParameters(homace_depression12,
labels = c("am11", "cm11", "em11", "af11", "cf11", "ef11"), free = TRUE, values = 0.6,
newlabels = c("a11", "c11", "e11", "a11", "c11", "e11"))
homace_fit_depression12 <- mxTryHard(homace_depression12, intervals = TRUE)
homace_fit_depression12_summ <- summary(homace_fit_depression12)
# parameter estimates (check that hf2,cf2 and ef2 are the same)
homace_depression12_table <- ACEhet_esitmates_table(data = homace_fit_depression12_summ,
variable = "Depression",
age = "12")
homace_depression12_table
# compare het and hom
mxCompare(hetace_fit_depression12, homace_fit_depression12)
```
### Age 18
```{r select which variables to use}
# selvars_dep18_chosen <- selvars_dep18 # raw
# selvars_dep18_chosen <- selvars_dep18_z_score # standardised
# selvars_dep18_chosen <- selvars_dep18norm # normalised
# selvars_dep18_chosen <- selvars_dep18_z_score_norm # standardised and normalised
selvars_dep18_chosen <- selvars_dep18norm_reg # normalised and regressed sex
```
```{r fit het model for depression 18}
# Objective objects for Multiple Groups
objMZM <- mxExpectationNormal(covariance = "expCovMZM", means = "expMeanm", dimnames = selvars_dep18_chosen)
objDZM <- mxExpectationNormal(covariance = "expCovDZM", means = "expMeanm", dimnames = selvars_dep18_chosen)
objMZF <- mxExpectationNormal(covariance = "expCovMZF", means = "expMeanf", dimnames = selvars_dep18_chosen)
objDZF <- mxExpectationNormal(covariance = "expCovDZF", means = "expMeanf", dimnames = selvars_dep18_chosen)
# Combine Groups
parsm <- list(pathAm, pathCm, pathEm, covAm, covCm, covEm, Varm, h2m, c2m, e2m)
parsf <- list(pathAf, pathCf, pathEf, covAf, covCf, covEf, Varf, h2f, c2f, e2f)
modelMZM <- mxModel(parsm, MeanM, MeanMM, covMZM, dataMZM, objMZM, fitFunction, name = "MZM")
modelDZM <- mxModel(parsm, MeanM, MeanMM, covDZM, dataDZM, objDZM, fitFunction, name = "DZM")
modelMZF <- mxModel(parsf, MeanF, MeanFF, covMZF, dataMZF, objMZF, fitFunction, name = "MZF")
modelDZF <- mxModel(parsf, MeanF, MeanFF, covDZF, dataDZF, objDZF, fitFunction, name = "DZF")
minus2ll <-mxAlgebra(expression = MZM.objective + DZM.objective + MZF.objective + DZF.objective, name = "m2LL")
hetace_depression18 <-mxModel("univHetACE", parsm, parsf, modelMZM, modelDZM, modelMZF, modelDZF, minus2ll, obj, ciM, ciF)
```
```{r run het model for depression 18}
# Run
hetace_fit_depression18 <- mxTryHard(hetace_depression18, intervals = TRUE)
hetace_depression18_summ <- summary(hetace_fit_depression18)
# Table
hetace_depression18_table <- ACEhet_esitmates_table(data = hetace_depression18_summ,
variable = "Depression",
age = "18")
hetace_depression18_table
```
```{r specify and run the sub-model homogeneity ACE model depression 18}
homace_depression18 <- mxModel(hetace_fit_depression18, name = "homace")
homace_depression18 <- omxSetParameters(homace_depression18,
labels = c("am11", "cm11", "em11", "af11", "cf11", "ef11"), free = TRUE, values = 0.6,
newlabels = c("a11", "c11", "e11", "a11", "c11", "e11"))
homace_fit_depression18 <- mxTryHard(homace_depression18, intervals = TRUE)
homace_fit_depression18_summ <- summary(homace_fit_depression18)
# parameter estimates (check that hf2,cf2 and ef2 are the same)
homace_depression18_table <- ACEhet_esitmates_table(data = homace_fit_depression18_summ,
variable = "Depression",
age = "18")
homace_depression18_table
# compare het and hom
mxCompare(hetace_fit_depression18, homace_fit_depression18)
```
## Conduct disorder
### Age 12
```{r select which variables to use}
# selvars_con12_chosen <- selvars_con12 # raw
# selvars_con12_chosen <- selvars_con12_z_score # standardised
# selvars_con12_chosen <- selvars_con12norm # normalised
# selvars_con12_chosen <- selvars_con12_z_score_norm # standardised and normalised
selvars_con12_chosen <- selvars_con12norm_reg # normalised and regressed sex
```
```{r fit het model for conduct 12}
# Objective objects for Multiple Groups
objMZM <- mxExpectationNormal(covariance = "expCovMZM", means = "expMeanm", dimnames = selvars_con12_chosen)
objDZM <- mxExpectationNormal(covariance = "expCovDZM", means = "expMeanm", dimnames = selvars_con12_chosen)
objMZF <- mxExpectationNormal(covariance = "expCovMZF", means = "expMeanf", dimnames = selvars_con12_chosen)
objDZF <- mxExpectationNormal(covariance = "expCovDZF", means = "expMeanf", dimnames = selvars_con12_chosen)
# Combine Groups
parsm <- list(pathAm, pathCm, pathEm, covAm, covCm, covEm, Varm, h2m, c2m, e2m)
parsf <- list(pathAf, pathCf, pathEf, covAf, covCf, covEf, Varf, h2f, c2f, e2f)
modelMZM <- mxModel(parsm, MeanM, MeanMM, covMZM, dataMZM, objMZM, fitFunction, name = "MZM")
modelDZM <- mxModel(parsm, MeanM, MeanMM, covDZM, dataDZM, objDZM, fitFunction, name = "DZM")
modelMZF <- mxModel(parsf, MeanF, MeanFF, covMZF, dataMZF, objMZF, fitFunction, name = "MZF")
modelDZF <- mxModel(parsf, MeanF, MeanFF, covDZF, dataDZF, objDZF, fitFunction, name = "DZF")
minus2ll <-mxAlgebra(expression = MZM.objective + DZM.objective + MZF.objective + DZF.objective, name = "m2LL")
hetace_conduct12 <-mxModel("univHetACE", parsm, parsf, modelMZM, modelDZM, modelMZF, modelDZF, minus2ll, obj, ciM, ciF)
```