MCMCglmm data format difficulties

被刻印的时光 ゝ 提交于 2019-12-11 06:06:20

问题


I want to estimate the heritability of animal traits using an animal model. However, I can't figure out how to properly format my data so that MCMCglmm can create a model. After much trial and error and scouring the internet for advice, I'm stuck. To my knowledge, I've formatted the data as suggested by all available resources that I know of, yet I get the following error message::

Error in MCMCglmm(BWT ~ 1, random = ~animal, pedigree = Ped, data = Data,  : 
some levels of animal do not have a row entry in ginverse

My questions are: What is the ginverse, exactly, and why doesn't it have row entries for all levels of animal?

Here are my two (dummy) data sets:

Animal phenotype data:

> Data
# A tibble: 10 x 6
   ANIMAL MOTHER BYEAR   SEX   BWT TARSUS
    <dbl>  <dbl> <dbl> <dbl> <dbl>  <dbl>
 1      1     11   968     1 10.8    24.8
 2      2     11   968     1  9.3    22.5
 3      3     12   970     2  3.98   12.9
 4      4     12   970     1  5.39   20.5
 5      5     13   970     2 12.1    NA  
 6      6     13   970     1 NA      NA  
 7      7     14   971     2 NA      NA  
 8      8     15   971     1  7.63   14.2
 9      9     16   971     1  4.76   NA  
10     10     17   971     1 NA      NA   

names(Data)[1] <- "animal"
Data$animal<-as.factor(Data$animal)
Data$MOTHER<-as.factor(Data$MOTHER)
Data$BYEAR<-as.factor(Data$BYEAR)
Data$SEX<-as.factor(Data$SEX)
Data$BWT<-as.numeric(Data$BWT)
Data$TARSUS<-as.numeric(Data$TARSUS)

Pedigree data:

> Ped
# A tibble: 17 x 3
      ID MOTHER FATHER
   <dbl>  <dbl>  <dbl>
 1     1     11     18
 2     2     11     NA
 3     3     12     NA
 4     4     12     19
 5     5     13     20
 6     6     13     NA
 7     7     14     NA
 8     8     15     21
 9     9     16     22
10    10     17     23
11    11     NA     NA
12    12     NA     NA
13    13     NA     NA
14    14     NA     NA
15    15     NA     NA
16    16     NA     NA
17    17     NA     NA

Load required packages. Need to format Ped as a matrix, then use the insertPed() and orderPed() functions so that parents appear before offspring in the ID field:

library(MCMCglmm)
library(MasterBayes)
Ped <- as.matrix(Ped)
Ped <- insertPed(Ped)
Ped <- orderPed(Ped)

Reformat to data.frame

Ped <- as.data.frame(Ped)

Load the package, estimate variance and priors, and generate model:

p.var <- var(Data$BWT , na.rm=TRUE)
prior1.1 <- list(G=list(G1=list(V=matrix(p.var/2),n=1)), 
             R=list(V=matrix(p.var/2),n=1))   
model1.1 <- MCMCglmm(BWT ~ 1 , random = ~animal, pedigree = Ped, data = Data, prior = prior1.1)

回答1:


Problem solved!

The Error message was getting thrown because the data set Data also needed to be formatted Data <- as.data.frame(Data)

Thanks to Jarrod Hadfield for the simple yet evasive solution.



来源:https://stackoverflow.com/questions/58107831/mcmcglmm-data-format-difficulties

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!