R中的MCMCglmm多项式模型 [英] MCMCglmm multinomial model in R
问题描述
我正在尝试使用R中的MCMCglmm
包创建模型.
I'm trying to create a model using the MCMCglmm
package in R.
数据的结构如下,其中dyad,focus,其他均为随机效应,predest1-2为预测变量,而Response 1-5为结果变量,捕获了#个不同亚型的观察到的行为:
The data are structured as follows, where dyad, focal, other are all random effects, predict1-2 are predictor variables, and response 1-5 are outcome variables that capture # of observed behaviors of different subtypes:
dyad focal other r present village resp1 resp2 resp3 resp4 resp5
1 10101 14302 0.5 3 1 0 0 4 0 5
2 10405 11301 0.0 5 0 0 0 1 0 1
…
所以只有一个结果(教学)的模型如下:
So a model with only one outcome (teaching) is as follows:
prior_overdisp_i <- list(R=list(V=diag(2),nu=0.08,fix=2),
G=list(G1=list(V=1,nu=0.08), G2=list(V=1,nu=0.08), G3=list(V=1,nu=0.08), G4=list(V=1,nu=0.08)))
m1 <- MCMCglmm(teaching ~ trait-1 + at.level(trait,1):r + at.level(trait,1):present,
random= ~idh(at.level(trait,1)):focal + idh(at.level(trait,1)):other +
idh(at.level(trait,1)):X + idh(at.level(trait,1)):village,
rcov=~idh(trait):units, family = "zipoisson", prior=prior_overdisp_i,
data = data, nitt = nitt.1, thin = 50, burnin = 15000, pr = TRUE, pl = TRUE, verbose = TRUE, DIC = TRUE)
Hadfield的课程注释(第5章)给出了一个多项式模型的示例,该模型仅使用具有3个级别(3种类型的羊角)的单个结果变量.可以在此处找到类似的处理方法: http://hlplab.wordpress.com/2009/05/07/multinomial-random-effects-models-in-r/对于我正在做的事情,这不太正确,但其中包含有用的背景信息.
Hadfield's course notes (Ch 5) give an example of a multinomial model that uses only a single outcome variable with 3 levels (sheep horns of 3 types). Similar treatment can be found here: http://hlplab.wordpress.com/2009/05/07/multinomial-random-effects-models-in-r/ This is not quite right for what I'm doing, but contains helpful background info.
另一个参考文献(Hadfield,2010年)给出了多响应MCMCglmm的示例,该示例遵循相同的格式,但使用cbind()预测响应的向量,而不是单个结果.具有多个响应的相同模型如下所示:
Another reference (Hadfield 2010) gives an example of a multi-response MCMCglmm that follows the same format but uses cbind() to predict a vector of responses, rather than a single outcome. The same model with multiple responses would look like this:
m1 <- MCMCglmm(cbind(resp1, resp2, resp3, resp4, resp5) ~ trait-1 +
at.level(trait,1):r + at.level(trait,1):present,
random= ~idh(at.level(trait,1)):focal + idh(at.level(trait,1)):other +
idh(at.level(trait,1)):X + idh(at.level(trait,1)):village,
rcov=~idh(trait):units,
family = cbind("zipoisson","zipoisson","zipoisson","zipoisson","zipoisson"),
prior=prior_overdisp_i,
data = data, nitt = nitt.1, thin = 50, burnin = 15000, pr = TRUE, pl = TRUE, verbose = TRUE, DIC = TRUE)
我在这里有两个编程问题:
I have two programming questions here:
-
如何为此模型指定先验条件?我看了这篇文章中提到的材料,但无法弄清楚.
How do I specify a prior for this model? I've looked at the materials mentioned in this post but just can't figure it out.
我运行的相似版本只有两个响应变量,但是我只有一个斜率-我以为每个resp
变量都应该有一个不同的斜率.我要去哪里错了,或者我误解了模型?
I've run a similar version with only two response variables, but I only get one slope - where I thought I should get a different slope for each resp
variable. Where am I going wrong, or having I misunderstood the model?
推荐答案
基于HLP帖子以及大学/统计顾问的一些帮助,回答了我的第一个问题:
Answer to my first question, based on the HLP post and some help from a colleage/stats consultant:
# values for prior
k <- 5 # originally: length(levels(dative$SemanticClass)), so k = # of outcomes for SemanticClass aka categorical outcomes
I <- diag(k-1) #should make matrix of 0's with diagonal of 1's, dimensions k-1 rows and k-1 columns
J <- matrix(rep(1, (k-1)^2), c(k-1, k-1)) # should make k-1 x k-1 matrix of 1's
对于我的模型,使用multinomial5
系列和5个结果变量,先验是:
And for my model, using the multinomial5
family and 5 outcome variables, the prior is:
prior = list(
R = list(fix=1, V=0.5 * (I + J), n = 4),
G = list(
G1 = list(V = diag(4), n = 4))
对于第二个问题,我需要在此模型的固定效果中添加一个交互项:
For my second question, I need to add an interaction term to the fixed effects in this model:
m <- MCMCglmm(cbind(Resp1, Resp2...) ~ -1 + trait*predictorvariable,
...
结果既给出了响应变量的主要效果,又给出了响应/预测变量交互作用的后验估计值(预测变量对每个响应变量的影响).
The result gives both main effects for the Response variables and posterior estimates for the Response/Predictor interaction (the effect of the predictor variable on each response variable).
这篇关于R中的MCMCglmm多项式模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!