如何在MCMCglmm中拟合单独的方差 - 协方差矩阵

时间:2017-09-05 08:05:34

标签: r matrix

我试图将动物的行为(活动)和新陈代谢(resBMR)联系起来。我使用混合模型分析和包MCMCglmm。我将试验和季节作为固定因素。此外,我们还有其他两个固定效果:SEX和RESP。 RESP代表对冬季的反应类型:R,NR和HR。

我准备了一个双变量混合模型。该模型应该允许我根据RESP(3个级别)拟合单独的方差 - 协方差矩阵。 代码如下:

prior<-list(R=list(R1=list(V=diag(2), nu=1.002),R2=list(V=diag(2), nu=1.002),R3=list(V=diag(2), nu=1.002)),G=list(G1=list(V=diag(2), nu=1.002),G2=list(V=diag(2), nu=1.002),G3=list(V=diag(2), nu=1.002)))

RESP <- MCMCglmm (cbind(resBMR,activity)

~trait-1+trait:trial + trait:SEX + trait:RESP + trait:season,

random=~us(at.level(RESP,"NR"):trait):ID+us(at.level(RESP,"R"):trait):ID+us(at.level(RESP, "HR"):trait):ID,

rcov = us(at.level(RESP,"NR"):trait):units+us(at.level(RESP,"R"):trait):units +us(at.level(RESP, "HR"):trait):units,

family=c("gaussian","gaussian"),prior=prior,data=data)

该模型有效,但我想计算依赖性状的截距 - 截距相关性如下:

cor_int_intR <- RESP$VCV[,"at.level(RESP,"NR"):traitactivity:at.level(RESP, "NR"):traitresBMR.ID"] 

/sqrt(RESP$VCV[,"at.level(RESP,"NR"):traitactivity:at.level(RESP,"NR"):traitactivity.ID"]

*RESP$VCV[,"at.level(RESP,"NR"):traitresBMR:at.level(RESP,"NR"):traitresBMR.ID"])

我得到了错误:

  

错误:意外的符号   &#34;&cor_int_intR LT; -RESP $ VCV [&#34; at.level(RESP,&#34; NR&#34;

我检查了模型的VCV,它看起来完全一样。但是当我在引文中写下NR时,它会改变颜色并告诉我&#34;意外的令牌&#39; NR&#39; &#34;

知道这有什么不对吗?

编辑:这是我的数据框示例:

&#13;
&#13;
ID	RESP	SEX	trial	season	resBMR	activity
1	HR	male 	1	lato	0.250052984	0.3536
1	HR	male 	2	lato	NA	-0.15325
1	HR	male 	3	zima	0.239365502	1.63709
1	HR	male 	4	zima	NA	0.90206
4	R	male 	1	lato	0.184630641	0.72714
4	R	male 	2	lato	NA	0.9956
4	R	male 	3	zima	0.222260753	0.4192
4	R	male 	4	zima	NA	-1.78506
5	NR	male 	1	lato	0.269151827	-0.2999
5	NR	male 	2	lato	NA	-0.19877
5	NR	male 	3	zima	0.22583699	0.95727
5	NR	male 	4	zima	NA	-0.76502
6	HR	male 	1	lato	0.244090325	0.18667
6	HR	male 	2	lato	NA	-0.42045
6	HR	male 	3	zima	0.261126729	0.13811
6	HR	male 	4	zima	NA	-0.70864
7	NR	female	1	lato	0.252336196	0.78315
7	NR	female	2	lato	NA	1.12088
7	NR	female	3	zima	0.19488432	0.30034
7	NR	female	4	zima	NA	-0.95369
8	NR	female	1	lato	0.216474311	-0.89225
8	NR	female	2	lato	NA	-0.23443
8	NR	female	3	zima	0.241733394	0.79699
8	NR	female	4	zima	NA	-0.41397
9	NR	male 	1	lato	0.233164752	-0.11484
9	NR	male 	2	lato	NA	-1.26982
9	NR	male 	3	zima	0.258378951	0.35827
9	NR	male 	4	zima	NA	-1.32658
10	R	male 	1	lato	0.233973797	-0.24418
10	R	male 	2	lato	NA	-0.37234
10	R	male 	3	zima	0.283488877	1.05007
10	R	male 	4	zima	NA	-1.62183
11	NR	male 	1	lato	0.247344964	-1.27324
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

我处理了这个问题。也许它不是最优雅的方式,但我只是改变了VCV中列的名称,我在代码中使用了新名称。有用!