2016-07-13 45 views
2

我试图运行glmer模型:错误在glmer:在EVAL错误(表达式,ENVIR,enclos):无法找到有效的开始>值:请指定一些

这是我装盘运行模型

md$count<-as.integer(md$count) 
Model1 <- glmer (count ~ distance_nest_tag + ep_nest + (1|tag_ID), 
       family = gaussian (link="log"),   
       data=md) 
  • count是从0到19的整数,其指示的访问次数。
  • distance_nest_tag是以米为单位的连续可变
  • ep_nest是二进制变量(1,0)

和随机效果方面都只是巢和个人号码。

我也试过这种

Model1 <- glmer (count ~ distance_nest_tag + ep_nest + (1|tag_ID), 
       family = gaussian (link="log"), 
       start = coef (lm(md$count ~ md$distance_nest_tag + md$ep_nest)),     
       data=md) 

但我总是得到这个

> Error in eval(expr, envir, enclos) : cannot find valid starting 
> values: please specify some 

有什么想法???

dput 



     Generalized linear mixed model fit by maximum likelihood (Laplace Approximation) ['glmerMod'] 
Family: binomial (logit) 
Formula: EP0 ~ counts + dist_mean_hour + nest_reproductive_period + X.vistors + 
    (1 | nest_ID) + (1 | tag_ring_ID) + (1 | distance_nesttag_nest) +  (1 | date) 
    Data: only_visits_encounternet 
    AIC  BIC logLik deviance df.resid 
34.7643 81.1238 -7.3822 14.7643  752 
Random effects: 
Groups    Name  Std.Dev. 
date     (Intercept) 8.507 
distance_nesttag_nest (Intercept) 68.095 
tag_ring_ID   (Intercept) 64.491 
nest_ID    (Intercept) 2.251 
Number of obs: 762, groups: date, 96; distance_nesttag_nest, 35; tag_ring_ID, 20; nest_ID, 19 
Fixed Effects: 
       (Intercept)      counts    dist_mean_hour 
       -13.08952     -1.80786     -0.04528 
nest_reproductive_periodI nest_reproductive_periodP     X.vistors 
       -4.04944     -1.56264     0.06601 
convergence code 0; 1 optimizer warnings; 0 lme4 warnings 
> dput(R) 
structure(list(nest_ID = c(6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L), nest_reproductive_period = structure(c(3L, 
1L, 2L, 3L, 1L, 2L, 3L, 1L), .Label = c("F", "I", "P"), class = "factor"), 
    tag_ID = c(23L, 23L, 23L, 4L, 4L, 4L, 5L, 5L), ring_tag_id = structure(c(3L, 
    3L, 3L, 1L, 1L, 1L, 2L, 2L), .Label = c("AU34180", "AU70442", 
    "BD12273"), class = "factor"), age_tag = c(5L, 5L, 5L, 4L, 
    4L, 4L, NA, NA), p3_tag = c(590L, 590L, 590L, 585L, 585L, 
    585L, 590L, 590L), weight_tag = c(1770L, 1770L, 1770L, 1843L, 
    1843L, 1843L, 1856L, 1856L), next_box_tag = c(42L, 42L, 42L, 
    56L, 56L, 56L, 0L, 0L), dist_mean = c(NA, NA, NA, NA, NA, 
    NA, NA, NA), count = c(3L, 2L, 1L, 0L, 0L, 0L, 0L, 0L), comb = structure(c(2L, 
    2L, 2L, 3L, 3L, 3L, 1L, 1L), .Label = c("6_0", "6_42", "6_56" 
    ), class = "factor"), distance_nest_tag = c(0.189813484, 
    0.189813484, 0.189813484, 0.649465717, 0.649465717, 0.649465717, 
    NA, NA), epp_male_comb = c(NA, NA, NA, NA, NA, NA, NA, NA 
    ), epp_male = c(NA, NA, NA, NA, NA, NA, NA, NA), nest_epmale = c(NA, 
    NA, NA, NA, NA, NA, NA, NA), neighbour = c(0L, 0L, 0L, 0L, 
    0L, 0L, 0L, 0L), ep_nest = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 
    0L), roost_nextbox_tag = c(8L, 8L, 8L, 335L, 335L, 335L, 
    332L, 332L), nestroost = structure(c(3L, 3L, 3L, 2L, 2L, 
    2L, 1L, 1L), .Label = c("6_332", "6_335", "6_8"), class = "factor"), 
    neighbours_roost = c(1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L)), .Names = c("nest_ID", 
"nest_reproductive_period", "tag_ID", "ring_tag_id", "age_tag", 
"p3_tag", "weight_tag", "next_box_tag", "dist_mean", "count", 
"comb", "distance_nest_tag", "epp_male_comb", "epp_male", "nest_epmale", 
"neighbour", "ep_nest", "roost_nextbox_tag", "nestroost", "neighbours_roost" 
), class = "data.frame", row.names = c(NA, -8L)) 

编辑

这里是包含0在响应变量的数据集和一个分组变量的小再现的例子。

dat = structure(list(y = c(0, 13.0988072077744, 1.53920266020577, 12.1207857178524, 
33.9470080593601, 0, 0, 3.46572339150589, 1.05917038733605, 14.295924854232, 
11.29307367, 8.1866351980716, 0.0106620794860646, 0.731016675010324, 
5.99548577982932, 0, 0, 3.15404516097624, 7.62275500199758, 0.604545763926581, 
0, 2.37143378704786, 2.39386320579797, 0.800569675164297), x = c(0, 
0, 0, 0, 0, 0, 2.43684896701947, 0.808418724797666, 0.672910050840583, 
0, 0.763154948372394, 1.44573423753027, 0.96113385074772, 0, 
0.498556550480425, 2.43977373047965, 1.55665618954226, 0.88557694968069, 
4.12758995011915, 3.16827587767271, 2.55354765986558, 3.99502024875255, 
1.71053826174466, 3.59887218330055), tag = c(1, 1, 1, 1, 1, 1, 
2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 5, 5, 5, 5, 5, 5)), .Names = c("y", 
"x", "tag"), row.names = c(NA, -24L), class = "data.frame") 

mod2 = glmer(y ~ x + (1|tag), 
      data = dat, family = gaussian(link = log), 
      start = list(theta = 1, coef(lm(y ~ x, data = dat)))) 
+0

'count'是否有零值? –

+0

是的,它从0 ... –

+0

请提供数据,使其成为一个可重复的例子。 http://stackoverflow.com/help/mcve感谢您刚刚做出的更新,但数据应采用可重复的格式,例如'dput',以便在我们的R会话中轻松导入,以帮助我们为您提供帮助。 –

回答

2

TL;博士为了使这项工作,你需要设置mustart参数的东西明智的;据报道,与mgcv类似的问题报告为here。在glmer当前版本,你只需要包括

mustart=pmax(dd$count,1e-3) 
glmer通话

解释:通常用于GLM(迭代重新加权最小二乘)的迭代算法需要设置一个起点,不仅仅是参数,而且是预测的响应值。高斯模型的默认设置是将预测值设置为等于观察值;如果观测值对于特定链路函数是不可能的(例如,当对数变换时零值变为负 - 无限),则这将破坏东西(即使观测值是合法的(即, ,我们可以观察到零值甚至当平均约束为正)因此,gaussian(link="log")家庭项目的$initialize成分是:

if (is.null(etastart) && is.null(start) && is.null(mustart) && 
    ((family$link == "inverse" && any(y == 0)) || (family$link == 
     "log" && any(y <= 0)))) 
    stop("cannot find valid starting values: please specify some") 
mustart <- y 

所以,我们真正需要做的是建立mustart所以所有的这个值是正数

然后就是这是否是正确的统计方法的问题,它不是疯狂的;我t也可能是合理的尝试泊松模型,或基于log(1+x)的简单线性模型或序数模型......取决于您对推动访问的过程以及您观察到的有关分布/条件分布的观点数量...

相关问题