我正在尝试拟合模型
glmer(trans.dummy ~ pop + year + (year | munname),
data=pool, family=binomial(link = "logit"), REML=T, verbose=T)
但我不断收到以下错误:
Error in glm.fit(fr$X, fr$Y, weights = wts, offset = offset, family = family, :
NA/NaN/Inf in foreign function call (arg 1)
我省略了 NA,更改了模型规范,将 pop 转换为 log(pop) 但没有解决问题。我认为问题出在变量“pop”上,因为它是唯一导致该问题的变量。当我跑
mod6 <- glmer(trans.dummy ~ constituency.coa + I(governat.part) + I(district2) +
gdp.cap + year + ifdm + year + (year | munname) + (year | uf),
data=pool, family=binomial(link = "logit"), REML=T, verbose=T)
我没有任何问题。
对正在发生的事情有任何想法吗?
编辑:
这是我的数据结构:
'data.frame': 41484 obs. of 50 variables:
$ munname : Factor w/ 5392 levels "ACACRELANDIA",..: 1 2 3 4 5 6 7 8 9 10 ...
$ uf : Factor w/ 26 levels "AC","AL","AM",..: 1 1 1 1 1 1 1 1 1 1 ...
$ year : int 2003 2003 2003 2003 2003 2003 2003 2003 2003 2003 ...
$ party : Factor w/ 30 levels "DEM","PAN","PC do B",..: 21 25 25 8 21 10 10 25 10 10 ...
$ candidate : Factor w/ 12600 levels "AARAO CRUZ MENDES",..: 11452 8535 6389 5910 8095 1995 6087 3996 4313 8417 ...
$ may.coalit : Factor w/ 10442 levels "DEM","DEM / PC do B / PRB / PRP / PTN / PSL",..: 7987 10118 10119 4023 8004 10442 4023 10114 4023 3945 ...
$ governat.part : Factor w/ 9 levels "PDT","PFL","PMDB",..: 9 9 9 9 9 9 9 9 9 9 ...
$ transfers : num 920 100920 183698 200920 919 ...
$ pop : num 8695 3667 17944 6641 6096 ...
$ gdp : num 68507 17492 101626 47936 37903 ...
$ bf : num 703 330 1339 335 455 ...
$ ifdm : num 0.422 0.442 0.404 0.511 0.396 ...
$ elec.num : int 45 13 13 15 45 11 11 13 11 11 ...
$ may.votes : int 2394 1345 3864 1415 1434 9422 2313 5423 1078 3348 ...
$ may.round : int 1 1 1 1 1 1 1 1 1 1 ...
$ may.perc.votes : num 0.59 0.586 0.441 0.544 0.615 ...
$ pt.position : Factor w/ 5 levels "0.No PT","1.PT mayor winner",..: 4 2 2 3 4 5 5 2 3 5 ...
$ numb.cand : int 2 2 3 3 2 4 3 2 2 2 ...
$ runup : Factor w/ 3 levels "1.PT","2.Coalition",..: 3 3 2 1 3 2 2 3 1 2 ...
$ voters : num 6422 3158 12234 3721 3682 ...
$ nation.turnout : num 4282 2150 7989 2624 2138 ...
$ lula.vote : num 2202 1197 4579 1431 1138 ...
$ lula.perc.vote : num 0.514 0.557 0.573 0.545 0.532 ...
$ reelec : Factor w/ 2 levels "Able to Run",..: 1 1 1 2 2 1 1 1 1 1 ...
$ constituency.pt : num 9.37e-05 9.41e-05 3.83e-04 4.92e-05 5.38e-05 ...
$ constituency.coa: num 4.10e-05 1.64e-05 6.87e-05 2.88e-05 1.34e-05 ...
$ constituency.opp: num 4.81e-05 1.16e-05 2.47e-05 2.41e-05 3.55e-05 ...
$ transfers.cap : num 0.106 27.521 10.237 30.254 0.151 ...
$ gdp.cap : num 7.88 4.77 5.66 7.22 6.22 ...
$ bf.cap : num 0.0808 0.0899 0.0746 0.0504 0.0747 ...
$ lula.power : num 1.32e-64 7.16e-65 2.74e-64 8.56e-65 6.80e-65 ...
$ mun.vote : int 1 1 1 1 1 0 1 1 1 0 ...
$ mun.vote2 : Factor w/ 2 levels "PSDB","PT": 2 2 2 2 2 1 2 2 2 1 ...
$ mun.vote3 : Factor w/ 2 levels "0.PT","1.PSDB": 1 1 1 1 1 2 1 1 1 2 ...
$ core : Factor w/ 3 levels "Lula Core Municipality",..: 3 3 3 3 3 3 3 1 3 3 ...
$ mayor.party.r : int 0 2 2 1 0 0 0 2 0 0 ...
$ mayor.party.r2 : Factor w/ 3 levels "0.PT","1.Coalition",..: 3 1 1 2 3 3 3 1 3 3 ...
$ pt.dummy : int 0 1 1 0 0 0 0 1 0 0 ...
$ trans.dummy : int 1 1 1 1 1 1 1 0 1 1 ...
$ year2 : Factor w/ 4 levels "2003-2004","2005-2006",..: 1 1 1 1 1 1 1 1 1 1 ...
$ district : Factor w/ 6 levels "PSDB/Coal","PSDB/Opo",..: 5 6 6 4 5 2 5 6 5 2 ...
$ term : int 0 0 0 0 0 0 0 0 0 0 ...
$ time : int 1 1 1 1 1 1 1 1 1 1 ...
$ pt.pt : int 0 1 1 0 0 0 0 1 0 0 ...
$ pt.coa : int 0 0 0 1 0 0 0 0 0 0 ...
$ pt.opp : int 1 0 0 0 1 0 1 0 1 0 ...
$ psdb.pt : int 0 0 0 0 0 0 0 0 0 0 ...
$ psdb.coa : int 0 0 0 0 0 0 0 0 0 0 ...
$ psdb.opp : int 0 0 0 0 0 1 0 0 0 1 ...
$ district2 : Factor w/ 5 levels "Coal/Coal","Opp/Opp",..: 2 4 4 5 2 3 3 4 5 3 ...
- attr(*, "na.action")=Class 'omit' Named int [1:1316] 59 235 242 409 437 555 588 594 645 673 ...
.. ..- attr(*, "names")= chr [1:1316] "59" "235" "242" "409" ...