溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

asreml怎樣設(shè)定初始值

發(fā)布時間:2021-12-10 11:11:33 來源:億速云 閱讀:176 作者:柒染 欄目:大數(shù)據(jù)

asreml怎樣設(shè)定初始值,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。

1. 背景

一個朋友問我,如何固定asreml的初始值,現(xiàn)在分為單性狀和多性狀進行說明。
為何要固定初始值:
1,由于群體較小,估算的方差組分不準(zhǔn)確,需要手動設(shè)定初始值,直接進行求解
2,有些群體數(shù)據(jù),估算方差組分不收斂,需要手動固定初始值
為何要設(shè)定初始值:
1,從頭進行估算,模型運行時間較長,根據(jù)先驗信息,手動設(shè)定初始值,迭代收斂速度更快
2,多性狀分析中,模型不容易收斂,手動設(shè)定初始值,更容易收斂和迭代

2. 單性狀設(shè)定初始值和固定初始值

以asreml包中自帶的數(shù)據(jù)harvey為例,進行演示。

> library(asreml)
> data(harvey)
> head(harvey)
Calf   Sire Dam Line ageOfDam  y1  y2  y3
1  101 Sire_1   0    1        3 192 390 224
2  102 Sire_1   0    1        3 154 403 265
3  103 Sire_1   0    1        4 185 432 241
4  104 Sire_1   0    1        4 183 457 225
5  105 Sire_1   0    1        5 186 483 258
6  106 Sire_1   0    1        5 177 469 267

數(shù)據(jù)前三列為系譜數(shù)據(jù),Line為固定因子,ageOfDam為協(xié)變量,y1,y2,y3為三個性狀。

2.1 運行單性狀動物模型
# 計算A逆矩陣
ainv <- asreml.Ainverse(harvey[,1:3])$ginv
head(ainv)
# 1. 單性狀模型
mod1 <- asreml(y1 ~ Line,random =~ ped(Calf),ginverse = list(Calf=ainv),data=harvey)
summary(mod1)$varcomp

結(jié)果如下:

> summary(mod1)$varcomp
gamma component std.error   z.ratio constraint
ped(Calf)!ped 2.144929 108.83588 106.37372 1.0231463   Positive
R!variance    1.000000  50.74101  86.63851 0.5856635   Positive

可以看到Va為108.83,Ve為50.74,模型收斂。

2.2 單性狀動物模型設(shè)定初始值

設(shè)定初始值,是為了更好的收斂,不影響結(jié)果。

# 1.1. 單性狀設(shè)定初始值
mod <- asreml(y1 ~ Line,random =~ ped(Calf),
ginverse = list(Calf=ainv),
start.values = T,
data=harvey)
vc = mod$gammas.table
vc
vc$Value = c(100,50)
vc
mod1.1 <- asreml(y1 ~ Line,random =~ ped(Calf),
ginverse = list(Calf=ainv),
G.param = vc,R.param = vc,
data=harvey)
summary(mod1.1)$varcomp

結(jié)果:

> summary(mod1.1)$varcomp
gamma component std.error   z.ratio constraint
ped(Calf)!ped 108.83606 108.83606 106.37146 1.0231697   Positive
R!variance      1.00000   1.00000        NA        NA      Fixed
R!units.var    50.74109  50.74109  86.63707 0.5856742   Positive
2.3 單性狀動物模型固定初始值

固定初始值,直接求解,asreml的結(jié)果方差組分狀態(tài)為Fixed

# 1.2. 單性狀固定方差組分
mod <- asreml(y1 ~ Line,random =~ ped(Calf),
ginverse = list(Calf=ainv),
start.values = T,
data=harvey)
vc = mod$gammas.table
vc
vc$Value = c(100,50)
vc$Constraint = rep("F",2)
vc
mod1.2 <- asreml(y1 ~ Line,random =~ ped(Calf),
ginverse = list(Calf=ainv),
G.param = vc,R.param = vc,
data=harvey)
summary(mod1.2)$varcomp

結(jié)果:

> summary(mod1.2)$varcomp
gamma component std.error z.ratio constraint
ped(Calf)!ped   100       100        NA      NA      Fixed
R!variance       50        50        NA      NA      Fixed

結(jié)果可以看出,方差組分變?yōu)榱?00,50,同時狀態(tài)是Fixed,說明是固定方差組分的結(jié)果,這樣計算的BLUP值就是我們想要的。

3. 多性狀固定方差組分

3.1 運行多性狀模型
# 2. 多性狀模型
mod2 <- asreml(cbind(y1,y3) ~ trait + trait:Line,
random =~ us(trait):ped(Calf),
rcov = ~ (units):us(trait),
ginverse = list(Calf=ainv),data=harvey)
summary(mod2)$varcomp
> summary(mod2)$varcomp
gamma component std.error    z.ratio constraint
trait:ped(Calf)!trait.y1:y1 108.83746 108.83746 106.37437  1.0231549   Positive
trait:ped(Calf)!trait.y3:y1 -51.25056 -51.25056 166.86351 -0.3071406   Positive
trait:ped(Calf)!trait.y3:y3 499.55701 499.55701 500.53419  0.9980477   Positive
R!variance                    1.00000   1.00000        NA         NA      Fixed
R!trait.y1:y1                50.73993  50.73993  86.63929  0.5856457   Positive
R!trait.y3:y1               -21.53905 -21.53905 136.25598 -0.1580778   Positive
R!trait.y3:y3               273.13654 273.13654 410.03528  0.6661294   Positive
3.2 多性狀模型固定方差組分
# 2.2 固定初始值
Va = c(108,-51,499)
Ve = c(50,-21,273)
mod2.2 <- asreml(cbind(y1,y3) ~ trait + trait:Line,
random =~ us(trait,init=Va):ped(Calf),
rcov = ~ units:us(trait,init=Ve),
start.values = TRUE,
ginverse = list(Calf=ainv),data=harvey)
vc = mod2.2$gammas.table
vc
vc$Value = c(Va,1,Ve)
vc$Constraint = c(rep("F",7))
vc
mod2.3 <- asreml(cbind(y1,y3) ~ trait + trait:Line,
random =~ us(trait,init=Va):ped(Calf),
rcov = ~ units:us(trait,init=Ve),
G.param = vc,R.param = vc,
ginverse = list(Calf=ainv),data=harvey)
summary(mod2.3)$varcomp

結(jié)果:

> summary(mod2.3)$varcomp
gamma component std.error z.ratio constraint
trait:ped(Calf)!trait.y1:y1   108       108        NA      NA      Fixed
trait:ped(Calf)!trait.y3:y1   -51       -51        NA      NA      Fixed
trait:ped(Calf)!trait.y3:y3   499       499        NA      NA      Fixed
R!variance                      1         1        NA      NA      Fixed
R!trait.y1:y1                  50        50        NA      NA      Fixed
R!trait.y3:y1                 -21       -21        NA      NA      Fixed
R!trait.y3:y3                 273       273        NA      NA      Fixed

4. 結(jié)論

  • 1,固定方差組分和設(shè)置方差組分方法類似, 不同的是constraintFixed

  • 2,設(shè)定方差組分時,先要運行start.values=T,這樣就可以生產(chǎn)一個表格,進行修改value和contraint即可

  • 3,單性狀和多性狀設(shè)定方法類似

看完上述內(nèi)容是否對您有幫助呢?如果還想對相關(guān)知識有進一步的了解或閱讀更多相關(guān)文章,請關(guān)注億速云行業(yè)資訊頻道,感謝您對億速云的支持。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI