将随机效应添加到R(GLM2)中的线性混合效果模型

时间:2016-11-21 02:29:51

标签: r random model effect linear

我正在分析性别,Cap.Year,Cap.Location和Spawning的影响。季节对湖泊鳟鱼访问的产卵场数量(Sites.Visited)。我正在尝试将随机效应变量(“Transmitter”,即单个鱼ID)添加到线性混合效果模型中。请参阅下面的数据样本。

    > head(Conc, 10)
      Transmitter Sex Sites.Visited Cap.Year Cap.Location Season.Length Spawning.Season
1  A69-1601-26770   M             2     2013   Grand Isle             P            2013
2  A69-1601-26771   F             1     2013   Grand Isle             P            2013
3  A69-1601-26773   F             2     2013   Grand Isle             P            2013
4  A69-1601-26774   M             2     2013   Grand Isle             P            2013
5  A69-1601-26776   F             4     2013   Grand Isle             P            2013
6  A69-1601-26778   M             2     2013   Grand Isle             P            2013
7  A69-1601-26784   M             1     2013   Grand Isle             P            2013
8  A69-1601-26785   F             2     2013   Grand Isle             P            2013
9  A69-1601-26786   F             2     2013   Grand Isle             P            2013
10 A69-1601-26787   M             2     2013   Grand Isle             P            2013

这是我的模型(没有随机效应变量):

modelDDF<-glm2(Sites.Visited~ factor(Sex)+factor(Cap.Year)+factor(Spawning.Season)+factor(Cap.Location), 
               family = gaussian, Conc, weights=NULL, subset=NULL, na.action=NULL, start = NULL, 
               offset=NULL, model = TRUE, method = "glm.fit2", x = FALSE, y = TRUE, contrasts = NULL,)

我想添加的随机效果变量是“Transmitter”。根据我读过的所有内容,这应该有效:

modelDDF<-glm2(Sites.Visited~ factor(Sex)+factor(Cap.Year)+factor(Spawning.Season)+factor(Cap.Location)+(1|Transmitter), 
               family = gaussian, Conc, weights=NULL, subset=NULL, na.action=NULL, start = NULL, 
               offset=NULL, model = TRUE, method = "glm.fit2", x = FALSE, y = TRUE, contrasts = NULL,)

但相反,我得到了这个错误:

Error in 1 | Transmitter : 
  operations are possible only for numeric, logical or complex types
> 

请帮忙!!!谢谢!

0 个答案:

没有答案