MCMCglmm数据格式困难 [英] MCMCglmm data format difficulties

查看:79
本文介绍了MCMCglmm数据格式困难的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用动物模型估算动物性状的遗传性.但是,我无法弄清楚如何正确格式化数据,以便MCMCglmm可以创建模型.经过反复的尝试和错误并在互联网上搜寻建议,我陷入了困境.据我所知,我已经按照我所知道的所有可用资源的建议格式化了数据,但是却收到以下错误消息:

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

我的问题是:确切地说,什么是 ginverse ?为什么它没有所有级别的 animal 的行条目?

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:

动物表型数据:

> 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)

家谱数据:

> 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

加载所需的软件包.需要将Ped格式化为矩阵,然后使用insertPed()和orderPed()函数,以便父代在 ID 字段中出现在子代之前:

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)

重新格式化为data.frame

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)

推荐答案

问题已解决!

由于数据集 Data 还需要格式化 Data<-as.data.frame(Data)

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

感谢Jarrod Hadfield提供的简单而易懂的解决方案.

Thanks to Jarrod Hadfield for the simple yet evasive solution.

这篇关于MCMCglmm数据格式困难的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆