问题
I am estimating a poisson model from a set of interaction coefficients, and the BMA package's bic.glm helps navigate the model space. I've been using it for years, but when I updated R from 2.10.x to 2.14.2 last night, it stopped working. Here's the error: first, a call that works:
> glm(formula(Y~.), data=XY5, family=poisson)
Call: glm(formula = formula(Y ~ .), family = poisson, data = XY5)
Coefficients:
<results, etc>
Now bic.glm failing:
> bic.glm(formula(Y~.), data=XY5, glm.family=poisson, model=TRUE)
Error in terms.formula(formula, data = data) :
'.' in formula and no 'data' argument
Again, this exact code worked in the earlier version of R with five systems. When I run bic.glm with 4 interacting systems instead of 5 (i.e., drop x5 and collapse the interactions), bic.glm runs fine. I'll include the five system data below. Thanks in advance.
> XY5
x1 x2 x3 x4 x5 x12 x13 x14 x15 x23 x24 x25 x34 x35 x45 x123 x124 x125 x134 x135 x145
2 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
3 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
4 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
5 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
6 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
7 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0
8 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0
9 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
10 0 1 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
11 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
12 0 1 0 1 1 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0
13 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0
14 0 1 1 0 1 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0
15 0 1 1 1 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 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0 0 0 239
13 0 0 0 0 0 0 0 0 0 144
14 0 1 0 0 0 0 0 0 0 135
15 1 0 0 0 0 0 0 0 0 469
16 1 1 1 1 0 0 0 0 1 1356
17 0 0 0 0 0 0 0 0 0 594
18 0 0 0 0 0 0 0 0 0 431
19 0 0 0 0 0 0 0 0 0 18
20 0 0 0 0 0 0 0 0 0 83
21 0 0 0 0 0 0 0 0 0 22
22 0 0 0 0 0 0 0 0 0 16
23 0 0 0 0 0 0 0 0 0 12
24 0 0 0 1 0 0 0 1 0 29
25 0 0 0 0 0 0 0 0 0 16
26 0 0 0 0 0 0 0 0 0 3
27 0 0 0 0 0 0 0 0 0 2
28 0 0 1 0 0 0 1 0 0 3
29 0 0 0 0 0 0 0 0 0 6
30 0 1 0 0 0 1 0 0 0 0
31 1 0 0 0 1 0 0 0 0 11
32 1 1 1 1 1 1 1 1 1 9
回答1:
I'm answering on behalf of the BMA package team, to whom I'm very grateful. Here's what they said:
I think there may be some unanticipated degeneracy due to the discrete nature of the data that is causing this problem to surface. I will update the package accordingly, but you should be able to fix it by adding the line indicated below to bic.glm.data.frame (and bic.glm.matrix)
while (length(glm.out$coefficients) > maxCol) {
any.dropped <- TRUE
dropglm <- drop1(glm.out, test = "Chisq")
dropped <- which.max(dropglm$"Pr(Chi)"[-1]) + 1
#
if (length(dropped) == 0) break #### add to prevent bug
#
x.df <- x.df[, -(dropped - 1)]
designx.levels <- designx.levels[-dropped]
designx <- designx[-dropped]
来源:https://stackoverflow.com/questions/13444117/data-error-in-bma-packages-bic-glm-but-not-glm