-
Notifications
You must be signed in to change notification settings - Fork 69
/
MAUSCRIPT_SCRIPTS.Rmd
115 lines (83 loc) · 2.86 KB
/
MAUSCRIPT_SCRIPTS.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
---
title: "Manuscript Scripts"
author: "Paulino Pérez-Rodríguez & Gustavo de los Campos"
#Note: Save and open as UTF-8 in order to display correcly the accents
#date: "9/8/2021"
output:
pdf_document: default
html_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,eval=FALSE,class.source = "numberLines lineAnchors")
```
### Box 1: Multi-trait GBLUP with unstructured and structured covariances
```{r}
library(BGLR)
data(wheat)
K<-tcrossprod(scale(wheat.X,center=TRUE))
K<-K/mean(diag(K))
Y<-wheat.Y # 4 traits
# Fitting a GBLUP un-structured cov-matrices
LP<-list(mar=list(K=K,model="RKHS"))
set.seed(123)
fmUN<-Multitrait(y=Y,ETA=LP,nIter=10000,burnIn=5000,
saveAt="UN_",verbose=FALSE)
# Retrieving estimates and posterior SD
fmUN$resCov$R # residual co-variance matrix
fmUN$resCov$SD.R
fmUN$ETA$mar$Cov$Omega # genomic covariance matrix
fmUN$ETA$mar$Cov$SD.Omega
fmUN$ETA$mar$u # predicted random effects
```
### Box 2: Multi-trait GBLUP with structured covariance matrices
```{r}
#(continued from Box 1)
# Genetic (co)variance recursive (not fully), Residual (co)variance diagonal
# Matrix specifying loading among traits 2=>3,2=>4,3=>4
M1<-matrix(nrow = 4, ncol = 4, FALSE)
M1[3,2]<-M1[4,2]<-M1[4,3]<-TRUE
CovREC<-list(type="REC",M=M1)
LP<-list(mar=list(K=K,model="RKHS",Cov=CovREC))
CovDIAG<-list(type="DIAG")
set.seed(456)
fmRD<-Multitrait(y=Y,ETA=LP,nIter=10000,burnIn=5000,
resCov=CovDIAG,saveAt= "REC_DIAG_",
verbose=FALSE)
fmRD$resCov$R
fmRD$ETA$mar$Cov$Omega # genomic covariance
fmRD$ETA$mar$Cov$W # recursive genetic effects
fmRD$ETA$mar$u # predicted genetic effects
fmRD$ETA$mar$Cov$PSI # scaling factors
# Omega-FA(2), R-diagonal
M2<-matrix(nrow=4,ncol=1,FALSE)
M2[2:4,1]<-TRUE
CovFA<-list(type="FA",M=M2)
LP<-list(mar=list(K=K,model="RKHS",Cov=CovFA))
set.seed(789)
fmFAD<-Multitrait(y=Y,ETA=LP,nIter=10000,burnIn=5000,
resCov=CovDIAG,saveAt= "FA_DIAG_",
verbose=FALSE)
fmFAD$resCov$R
fmFAD$ETA$mar$Cov$Omega # genomic covariance
fmFAD$ETA$mar$Cov$W # factor scores
fmFAD$ETA$mar$u # predicted genetic effects
fmFAD$ETA$mar$Cov$PSI # scaling factors
```
### Box 3: Fitting a Multitrait Spike Slab model
```{r}
fmSS<-Multitrait(y=Y,ETA=list(list(X=X,model='SpikeSlab',
saveEffects=TRUE)),nIter=12000,burnIn=2000)
```
### Box 4: Prediction
```{r}
K<-tcrossprod(X)
K<-K/mean(diag(K))
LP<-list(list(K=K,model="RKHS"))
#Fit multivariate GBLUP with UN-structured covariance matrixes
fmG<-Multitrait(y=YNa,ETA=LP,nIter=10000,burnIn=5000,thin=10,
verbose=FALSE)
#Missing values for trait 3
whichNa3<-fmG$missing_records[fmG$patterns[,3]]
Y[whichNa3,3] #Observed values
fmG$ETAHat[whichNa3,3] #Predicted values
```