1
$\begingroup$

I encountered an issue when using glmer.nb() to model my data. First I used fitdistr to tell me which distribution fits my data. it told me I should fit with negative binomail distribuion

library(MASS)
nbinom = fitdistr(temp$y,"Negative Binomial")
qqp(temp$y,"nbinom",size = nbinom$estimate[[1]], mu = nbinom$estimate[[2]])

And then, I tried to use lme4::glmer.nb() to model:

library(lme4)
m.glm <- glmer.nb(y ~ x + z.fac  + SIDI  +(1|SITE), data=temp, trace=TRUE)

This is the formula I got from help(glmer.nb()). But the Error says:

Error in pwrssUpdate(pp, resp, tol = tolPwrss, GQmat = GQmat, compDev = compDev,  :
Downdated VtV is not positive definite
Extra: Warning messages:
1: extra argument(s) ‘trace’ disregarded 
2: Some predictor variables are on very different scales: consider rescaling

However, when I removed x from the formula, the function worked.

m.glm <- glmer.nb(y ~ z.fac  + SIDI  +(1|SITE), data=temp, trace=TRUE)  # dropped x

Here is my partial dataset below. What's the matter with the x? Why is x so strange, and how can I resolve this issue?

temp <- structure(list(DATE=structure(c(17684,17684,17684,17684,
17684,17684,17684,17684,17684,17684,17684,17684,17684,
17684,17684,17686,17686,17686,17686,17686,17686,17686,
17686,17686,17686,17686,17686,17687,17687,17687,17687,
17687,17687,17687,17687,17687,17688,17688,17688,17688,
17688,17688,17688,17688,17688,17688,17688,17688,17689,
17689,17689,17689,17689,17689,17689,17689,17689,17689,
17689,17689,17690,17690,17690,17690,17690,17690,17690,
17690,17690,17690,17690,17690,17690,17690,17690,17691,
17691,17691,17691,17691,17691,17691,17691,17691,17691,
17691,17691,17692,17692,17692,17692,17692,17692,17692,
17692,17692,17693,17693,17693,17693,17693,17693,17693,
17693,17693,17693,17693,17694,17694,17694,17694,17694,
17694,17694,17694,17694,17694,17694,17694,17694,17694,
17694,17694,17694,17694,17694,17694,17694,17694,17694,
17694,17694,17694,17694,17694,17694,17694,17694,17694,
17694,17694,17694,17694,17694,17694,17694,17694,17694,
17694,17694,17694,17694,17694,17694,17694,17694,17694,
17694,17694,17694,17694,17694,17694,17694,17694,17694,
17694,17694,17694,17694,17694,17694,17694,17694,17694,
17694,17694,17694,17694,17694,17694,17694,17694,17694,
17694,17694,17694,17694,17694,17694,17694,17694,17694,
17694,17695,17695,17695,17695,17695,17695,17695,17695,
17695,17695,17695,17695,17695,17695,17695,17696,17696,
17696,17696,17696,17696,17696,17696,17696,17696,17696,
17696,17697,17697,17697,17697,17697,17697,17697,17697,
17697,17697,17697,17697,17697,17698,17698,17698,17698,
17698,17698,17699,17699,17699,17699,17699,17699,17699,
17699,17699,17702,17702,17702,17702,17702,17702,17702,
17702,17702,17702,17702,17702,17702,17702,17702,17703,
17703,17703,17703,17703,17703,17703,17703,17703,17703,
17703,17703,17704,17704,17704,17704,17704,17704,17704,
17704,17704,17705,17705,17705,17705,17705,17705,17705,
17705,17705,17705,17705,17705,17706,17706,17706,17706,
17706,17706,17706,17706,17706,17706,17706,17706,17709,
17709,17709,17709,17709,17709,17709,17709,17709,17709,
17709,17709,17710,17710,17710,17710,17710,17710,17710,
17710,17710,17710,17711,17711,17711,17711,17711,17711,
17711,17712,17712,17712,17712,17712,17712,17712,17712,
17712,17712,17713,17713,17713,17713,17713,17713,17713,
17713,17713,17713,17713,17713,18053,18053,18053,18053,
18053,18053,18053,18053,18053,18053,18053,18053,18053,
18053,18053,18053,18053,18053,18053,18059,18059,18059,
18059,18059,18059,18060,18060,18060,18060,18060,18060,
18061,18061,18061,18061,18061,18061,18061,18061,18061,
18061,18061,18061,18061,18061,18061,18061,18061,18061,
18066,18066,18066,18066,18066,18066,18066,18066,18066,
18066,18066,18066,18066,18067,18067,18067,18067,18067,
18067,18067,18067,18067,18067,18067,18067,18067,18067,
18067,18067,18067,18067,18067,18067,18067,18067,18068,
18068,18068,18068,18068,18068,18068,18068,18068,18073,
18073,18073,18073,18073,18073,18073,18073,18073,18073,
18073,18073,18073,18073,18073,18073,18074,18074,18074,
18074,18074,18074,18074,18074,18074,18074,18074,18074,
18074,18074,18074,18074,18074,18074,18075,18075,18075,
18075,18075,18075,18075,18075,18075,18075,18075,18075,
18075,18075,18075,18075,18075,18075),class="Date"),SITE=structure(c(1L,
1L,1L,2L,2L,2L,3L,3L,3L,4L,4L,4L,5L,5L,5L,6L,6L,
6L,7L,7L,7L,8L,8L,8L,9L,9L,9L,10L,10L,10L,11L,11L,
11L,12L,12L,12L,13L,13L,13L,14L,14L,14L,15L,15L,15L,
16L,16L,16L,17L,17L,17L,18L,18L,18L,19L,19L,19L,20L,
20L,20L,1L,1L,1L,2L,2L,2L,3L,3L,3L,4L,4L,4L,5L,
5L,5L,6L,6L,6L,7L,7L,7L,8L,8L,8L,9L,9L,9L,10L,
10L,10L,11L,11L,11L,12L,12L,12L,13L,13L,13L,14L,14L,
14L,15L,15L,16L,16L,16L,17L,17L,17L,17L,17L,17L,17L,
17L,17L,17L,17L,17L,17L,17L,17L,17L,17L,17L,17L,17L,
17L,17L,17L,17L,17L,17L,17L,17L,17L,17L,17L,17L,17L,
17L,17L,17L,17L,17L,17L,17L,17L,17L,17L,17L,17L,17L,
17L,17L,17L,17L,17L,17L,17L,17L,17L,17L,17L,17L,17L,
17L,17L,17L,17L,17L,17L,17L,17L,17L,17L,17L,17L,17L,
17L,17L,17L,17L,17L,17L,18L,18L,18L,19L,19L,19L,20L,
20L,20L,1L,1L,1L,2L,2L,2L,3L,3L,3L,4L,4L,4L,5L,
5L,5L,6L,6L,6L,7L,7L,7L,8L,8L,8L,9L,9L,9L,10L,
10L,10L,11L,11L,11L,12L,14L,14L,14L,15L,15L,15L,13L,
13L,13L,16L,16L,16L,18L,18L,18L,19L,19L,19L,20L,20L,
20L,1L,1L,1L,2L,2L,2L,3L,3L,3L,4L,4L,4L,5L,5L,
5L,6L,6L,6L,7L,7L,7L,8L,8L,8L,9L,9L,9L,10L,10L,
10L,11L,11L,11L,12L,12L,12L,13L,13L,13L,14L,14L,14L,
15L,15L,15L,16L,16L,16L,17L,17L,17L,18L,18L,18L,19L,
19L,19L,20L,20L,20L,1L,1L,1L,2L,2L,2L,3L,3L,3L,
4L,5L,5L,6L,6L,6L,7L,8L,8L,8L,9L,9L,9L,10L,11L,
11L,11L,12L,12L,12L,13L,13L,13L,14L,15L,15L,15L,16L,
16L,16L,17L,17L,17L,18L,18L,18L,19L,19L,19L,20L,20L,
20L,21L,22L,23L,24L,25L,26L,27L,28L,29L,30L,31L,31L,
32L,33L,34L,35L,36L,37L,38L,21L,31L,32L,33L,34L,35L,
22L,23L,24L,36L,37L,38L,25L,25L,25L,26L,26L,26L,27L,
27L,27L,28L,28L,28L,29L,29L,29L,30L,30L,30L,21L,21L,
21L,31L,33L,33L,33L,34L,34L,34L,35L,35L,35L,22L,22L,
22L,23L,23L,23L,24L,24L,24L,29L,29L,29L,32L,36L,36L,
36L,37L,37L,37L,38L,38L,38L,25L,26L,27L,27L,27L,28L,
30L,30L,30L,21L,21L,21L,31L,31L,31L,32L,32L,32L,33L,
33L,33L,34L,35L,35L,35L,22L,22L,22L,23L,23L,23L,24L,
24L,24L,36L,36L,36L,37L,37L,37L,38L,38L,38L,25L,25L,
25L,26L,26L,26L,27L,27L,27L,28L,28L,28L,29L,29L,29L,
30L,30L,30L),.Label=c("CB1","CB2","CB3","CB4","CB5",
"CB6","CB7","CB8","CB9","CB10","CB11","CB12","CB13","CB14",
"CB15","CB16","CB17","CB18","CB19","CB20","CC1","CC10",
"CC11","CC12","CC13","CC14","CC15","CC16","CC17","CC18",
"CC2","CC3","CC4","CC5","CC6","CC7","CC8","CC9","cc1",
"cc10","cc11","cc12","cc13","cc14","cc15","cc16","cc17",
"cc18","cc2","cc3","cc4","cc5","cc6","cc7","cc8","cc9"
),class="factor"),y=c(0L,0L,8L,0L,16L,20L,0L,8L,
4L,4L,0L,4L,0L,0L,0L,24L,0L,24L,0L,4L,0L,0L,0L,
8L,0L,24L,4L,0L,4L,0L,4L,0L,0L,0L,88L,4L,0L,12L,
0L,4L,0L,0L,0L,0L,0L,8L,0L,12L,0L,0L,0L,0L,0L,
4L,0L,0L,0L,12L,12L,12L,0L,16L,32L,48L,16L,36L,0L,
0L,4L,0L,48L,0L,0L,0L,0L,0L,0L,8L,8L,12L,16L,16L,
8L,0L,52L,56L,36L,4L,4L,8L,0L,0L,0L,4L,12L,4L,16L,
4L,8L,4L,0L,0L,0L,0L,8L,8L,24L,0L,0L,0L,0L,0L,
0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,4L,0L,0L,
0L,0L,0L,0L,0L,0L,0L,0L,0L,4L,0L,0L,0L,0L,0L,0L,
0L,0L,0L,0L,0L,0L,0L,0L,4L,0L,4L,0L,0L,0L,4L,4L,
0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,
0L,0L,0L,0L,0L,0L,20L,32L,4L,24L,0L,0L,0L,0L,0L,
8L,8L,32L,20L,52L,36L,72L,52L,52L,12L,4L,16L,0L,
0L,4L,4L,0L,0L,20L,8L,0L,16L,32L,32L,0L,12L,20L,
24L,8L,40L,92L,20L,28L,8L,32L,92L,0L,4L,4L,0L,8L,
20L,4L,20L,4L,12L,28L,24L,8L,16L,36L,84L,8L,0L,0L,
16L,44L,48L,4L,0L,0L,20L,24L,12L,40L,136L,188L,0L,
24L,44L,12L,32L,40L,0L,8L,32L,24L,16L,8L,12L,16L,
12L,12L,12L,24L,16L,80L,68L,20L,12L,44L,28L,36L,12L,
56L,168L,48L,20L,40L,64L,4L,0L,0L,20L,4L,28L,8L,
4L,12L,76L,60L,48L,12L,4L,0L,4L,20L,28L,4L,4L,8L,
20L,56L,28L,392L,328L,476L,60L,4L,0L,116L,72L,84L,
8L,260L,284L,140L,60L,184L,4L,124L,108L,48L,48L,288L,
608L,528L,148L,136L,40L,0L,84L,120L,16L,92L,116L,76L,
32L,8L,4L,28L,28L,24L,0L,12L,4L,40L,20L,92L,0L,0L,
0L,0L,8L,0L,40L,0L,0L,0L,0L,0L,0L,0L,0L,0L,0L,
0L,0L,0L,4L,12L,8L,0L,0L,0L,0L,4L,0L,0L,0L,0L,
0L,0L,0L,0L,0L,0L,0L,0L,4L,0L,0L,4L,16L,32L,0L,
0L,4L,4L,60L,116L,4L,0L,12L,0L,0L,0L,0L,0L,0L,0L,
0L,0L,0L,28L,0L,20L,0L,0L,0L,88L,24L,12L,16L,0L,
0L,0L,0L,0L,0L,0L,0L,8L,16L,0L,8L,0L,0L,0L,20L,
28L,24L,68L,168L,64L,0L,0L,0L,304L,4L,24L,4L,0L,
4L,0L,0L,0L,0L,0L,4L,0L,4L,4L,4L,0L,0L,0L,0L,0L,
4L,0L,8L,4L,4L,0L,0L,32L,68L,28L,0L,0L,0L,80L,0L,
4L,12L,4L,8L,12L,48L,0L,24L,40L,88L),x=c(13168L,
2168L,1240L,1916L,3876L,15732L,1056L,1984L,1548L,1184L,
1676L,2212L,288L,556L,416L,14800L,4436L,6360L,808L,1348L,
3216L,988L,1180L,948L,10152L,32172L,5356L,1704L,5612L,
2636L,10012L,3980L,6116L,3340L,2684L,1088L,2796L,7768L,
2428L,464L,712L,496L,4568L,5084L,5400L,464L,1088L,1260L,
316L,292L,336L,4724L,11180L,8760L,2936L,2056L,3412L,
3724L,3204L,2120L,51932L,65564L,93480L,69792L,67688L,
89692L,9932L,22492L,13888L,1084L,804L,412L,11568L,16632L,
10724L,21704L,19960L,40636L,17056L,18184L,6184L,2704L,
1932L,2576L,19456L,41404L,34416L,10000L,16336L,8856L,
60480L,55052L,117396L,31004L,33620L,27588L,4944L,14288L,
2784L,816L,456L,764L,1056L,3260L,19876L,12084L,9128L,
288L,132L,432L,300L,144L,108L,172L,196L,36L,20L,88L,
132L,144L,84L,520L,76L,1000L,204L,440L,104L,260L,160L,
520L,80L,180L,132L,204L,96L,28L,52L,560L,120L,16L,
16L,64L,120L,208L,28L,36L,40L,12L,44L,240L,20L,52L,
28L,0L,220L,12L,160L,280L,276L,1880L,28L,44L,376L,
580L,48L,128L,160L,72L,28L,168L,60L,40L,92L,84L,148L,
24L,20L,244L,280L,72L,92L,56L,6788L,5672L,1448L,72860L,
106248L,70972L,79452L,92504L,98108L,37696L,41480L,50116L,
275372L,403224L,451172L,368936L,394448L,303560L,42784L,
141940L,289936L,3440L,4828L,7984L,7508L,4356L,3800L,100580L,
156052L,121284L,161308L,108888L,80868L,9576L,7980L,11876L,
31592L,54008L,88916L,27844L,20844L,25264L,394000L,336804L,
530008L,3748L,6004L,5324L,6244L,26700L,24696L,11984L,
11876L,12512L,10500L,4332L,3632L,4552L,584852L,862216L,
796300L,2116L,2076L,1880L,473620L,468804L,418832L,4496L,
2584L,2024L,6836L,7432L,10356L,1144660L,897788L,1015528L,
61676L,49192L,83880L,23600L,49756L,45180L,252220L,490040L,
410024L,116888L,216488L,146652L,13424L,22936L,20376L,5152L,
3588L,2956L,261124L,316888L,303800L,35748L,19868L,17056L,
136712L,213704L,277568L,392644L,527116L,593788L,191296L,
244312L,233852L,2448L,2300L,2492L,41044L,91080L,156684L,
4468L,5536L,10992L,526120L,466640L,145332L,14484L,18680L,
21520L,11172L,83512L,84088L,29496L,45056L,26240L,22276L,
59052L,56116L,425020L,585604L,599200L,931520L,78796L,8508L,
43156L,24560L,100284L,2912L,609400L,677832L,592504L,98044L,
118460L,106804L,678400L,49360L,45700L,40500L,1365272L,
1234296L,1188048L,20840L,23380L,11580L,476L,41380L,19712L,
10312L,81124L,123560L,168060L,36920L,43000L,37884L,3856L,
10064L,32160L,4288L,6136L,3852L,72020L,167572L,342444L,
3536L,328L,160L,4L,2180L,1056L,2536L,1232L,6544L,600L,
2248L,4868L,6252L,584L,1468L,368L,132L,260L,140L,31236L,
43184L,90728L,4740L,5380L,5984L,2300L,1464L,1088L,900L,
48L,1608L,10280L,11108L,15444L,20040L,17288L,39596L,14072L,
33632L,56580L,9964L,23600L,7628L,45324L,45132L,34376L,
2140L,2524L,1632L,734660L,900288L,983124L,298628L,3212L,
3080L,3116L,23888L,43948L,85296L,31360L,19836L,19956L,
13544L,9940L,10048L,11332L,6896L,10888L,1036L,796L,896L,
412016L,437348L,555224L,76120L,10312L,20948L,12024L,2984L,
2576L,2852L,4244L,3740L,380L,325440L,40L,17744L,26260L,
23444L,164L,8396L,19780L,22664L,548164L,514468L,340464L,
912L,276L,152L,7244L,5348L,6928L,47208L,62488L,34304L,
3632L,4136L,3568L,4748L,32484L,35860L,41480L,204176L,
331408L,273684L,35184L,18840L,16948L,25580L,31940L,24160L,
20700L,18496L,19928L,32280L,21800L,28688L,806488L,854176L,
1259328L,29204L,25984L,22440L,85680L,76400L,99120L,37052L,
38172L,48892L,46584L,65264L,71680L,256260L,370332L,363968L
),z.fac=structure(c(2L,2L,2L,2L,2L,2L,1L,1L,1L,3L,
3L,3L,4L,4L,4L,2L,2L,2L,4L,4L,4L,2L,2L,2L,1L,1L,
1L,4L,4L,4L,3L,3L,3L,2L,2L,2L,3L,3L,3L,3L,3L,3L,
2L,2L,2L,2L,2L,2L,3L,3L,3L,2L,2L,2L,4L,4L,4L,2L,
2L,2L,2L,2L,2L,2L,2L,2L,1L,1L,1L,3L,3L,3L,4L,4L,
4L,2L,2L,2L,4L,4L,4L,2L,2L,2L,1L,1L,1L,4L,4L,4L,
3L,3L,3L,2L,2L,2L,3L,3L,3L,3L,3L,3L,2L,2L,2L,2L,
2L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,
3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,
3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,
3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,
3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,3L,2L,
2L,2L,4L,4L,4L,2L,2L,2L,2L,2L,2L,2L,2L,2L,1L,1L,
1L,3L,3L,3L,4L,4L,4L,2L,2L,2L,4L,4L,4L,2L,2L,2L,
1L,1L,1L,4L,4L,4L,3L,3L,3L,2L,3L,3L,3L,2L,2L,2L,
3L,3L,3L,2L,2L,2L,2L,2L,2L,4L,4L,4L,2L,2L,2L,2L,
2L,2L,2L,2L,2L,1L,1L,1L,3L,3L,3L,4L,4L,4L,2L,2L,
2L,4L,4L,4L,2L,2L,2L,1L,1L,1L,4L,4L,4L,3L,3L,3L,
2L,2L,2L,3L,3L,3L,3L,3L,3L,2L,2L,2L,2L,2L,2L,3L,
3L,3L,2L,2L,2L,4L,4L,4L,2L,2L,2L,2L,2L,2L,2L,2L,
2L,1L,1L,1L,3L,4L,4L,2L,2L,2L,4L,2L,2L,2L,1L,1L,
1L,4L,3L,3L,3L,2L,2L,2L,3L,3L,3L,3L,2L,2L,2L,2L,
2L,2L,3L,3L,3L,2L,2L,2L,4L,4L,4L,2L,2L,2L,2L,3L,
3L,4L,1L,3L,3L,3L,2L,2L,1L,1L,4L,3L,5L,3L,2L,2L,
2L,2L,1L,4L,3L,5L,3L,3L,3L,4L,2L,2L,2L,1L,1L,1L,
3L,3L,3L,3L,3L,3L,3L,3L,3L,2L,2L,2L,2L,2L,2L,2L,
2L,2L,1L,3L,3L,3L,5L,5L,5L,3L,3L,3L,3L,3L,3L,3L,
3L,3L,4L,4L,4L,2L,2L,2L,4L,2L,2L,2L,2L,2L,2L,2L,
2L,2L,1L,3L,3L,3L,3L,3L,2L,2L,2L,2L,2L,2L,1L,1L,
1L,4L,4L,4L,3L,3L,3L,5L,3L,3L,3L,3L,3L,3L,3L,3L,
3L,4L,4L,4L,2L,2L,2L,2L,2L,2L,2L,2L,2L,1L,1L,1L,
3L,3L,3L,3L,3L,3L,3L,3L,3L,2L,2L,2L,2L,2L,2L),.Label=c("0",
"1","2","3","4"),class="factor"),SIDI=c(0.6549,0.6549,
0.6549,0.819,0.819,0.819,0.7304,0.7304,0.7304,0.744,0.744,
0.744,0.7066,0.7066,0.7066,0.6495,0.6495,0.6495,0.8357,
0.8357,0.8357,0.4408,0.4408,0.4408,0.7161,0.7161,0.7161,
0.5601,0.5601,0.5601,0.5488,0.5488,0.5488,0.7409,0.7409,
0.7409,0.7505,0.7505,0.7505,0.4861,0.4861,0.4861,0.8634,
0.8634,0.8634,0.5299,0.5299,0.5299,0.8452,0.8452,0.8452,
0.7962,0.7962,0.7962,0.7968,0.7968,0.7968,0.8719,0.8719,
0.8719,0.6549,0.6549,0.6549,0.819,0.819,0.819,0.7304,
0.7304,0.7304,0.744,0.744,0.744,0.7066,0.7066,0.7066,
0.6495,0.6495,0.6495,0.8357,0.8357,0.8357,0.4408,0.4408,
0.4408,0.7161,0.7161,0.7161,0.5601,0.5601,0.5601,0.5488,
0.5488,0.5488,0.7409,0.7409,0.7409,0.7505,0.7505,0.7505,
0.4861,0.4861,0.4861,0.8634,0.8634,0.5299,0.5299,0.5299,
0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,
0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,
0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,
0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,
0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,
0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,
0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,
0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,
0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,
0.8452,0.8452,0.8452,0.8452,0.8452,0.8452,0.7962,0.7962,
0.7962,0.7968,0.7968,0.7968,0.8719,0.8719,0.8719,0.6549,
0.6549,0.6549,0.819,0.819,0.819,0.7304,0.7304,0.7304,
0.744,0.744,0.744,0.7066,0.7066,0.7066,0.6495,0.6495,
0.6495,0.8357,0.8357,0.8357,0.4408,0.4408,0.4408,0.7161,
0.7161,0.7161,0.5601,0.5601,0.5601,0.5488,0.5488,0.5488,
0.7409,0.4861,0.4861,0.4861,0.8634,0.8634,0.8634,0.7505,
0.7505,0.7505,0.5299,0.5299,0.5299,0.7962,0.7962,0.7962,
0.7968,0.7968,0.7968,0.8719,0.8719,0.8719,0.6549,0.6549,
0.6549,0.819,0.819,0.819,0.7304,0.7304,0.7304,0.744,0.744,
0.744,0.7066,0.7066,0.7066,0.6495,0.6495,0.6495,0.8357,
0.8357,0.8357,0.4408,0.4408,0.4408,0.7161,0.7161,0.7161,
0.5601,0.5601,0.5601,0.5488,0.5488,0.5488,0.7409,0.7409,
0.7409,0.7505,0.7505,0.7505,0.4861,0.4861,0.4861,0.8634,
0.8634,0.8634,0.5299,0.5299,0.5299,0.8452,0.8452,0.8452,
0.7962,0.7962,0.7962,0.7968,0.7968,0.7968,0.8719,0.8719,
0.8719,0.6549,0.6549,0.6549,0.819,0.819,0.819,0.7304,
0.7304,0.7304,0.744,0.7066,0.7066,0.6495,0.6495,0.6495,
0.8357,0.4408,0.4408,0.4408,0.7161,0.7161,0.7161,0.5601,
0.5488,0.5488,0.5488,0.7409,0.7409,0.7409,0.7505,0.7505,
0.7505,0.4861,0.8634,0.8634,0.8634,0.5299,0.5299,0.5299,
0.8452,0.8452,0.8452,0.7962,0.7962,0.7962,0.7968,0.7968,
0.7968,0.8719,0.8719,0.8719,0.7289,0.7263,0.6633,0.3309,
0.7317,0.7003,0.7932,0.8188,0.7889,0.7731,0.7882,0.7882,
0.8556,0.8002,0.8337,0.8385,0.7121,0.6724,0.3816,0.7289,
0.7882,0.8556,0.8002,0.8337,0.8385,0.7263,0.6633,0.3309,
0.7121,0.6724,0.3816,0.7317,0.7317,0.7317,0.7003,0.7003,
0.7003,0.7932,0.7932,0.7932,0.8188,0.8188,0.8188,0.7889,
0.7889,0.7889,0.7731,0.7731,0.7731,0.7289,0.7289,0.7289,
0.7882,0.8002,0.8002,0.8002,0.8337,0.8337,0.8337,0.8385,
0.8385,0.8385,0.7263,0.7263,0.7263,0.6633,0.6633,0.6633,
0.3309,0.3309,0.3309,0.7889,0.7889,0.7889,0.8556,0.7121,
0.7121,0.7121,0.6724,0.6724,0.6724,0.3816,0.3816,0.3816,
0.7317,0.7003,0.7932,0.7932,0.7932,0.8188,0.7731,0.7731,
0.7731,0.7289,0.7289,0.7289,0.7882,0.7882,0.7882,0.8556,
0.8556,0.8556,0.8002,0.8002,0.8002,0.8337,0.8385,0.8385,
0.8385,0.7263,0.7263,0.7263,0.6633,0.6633,0.6633,0.3309,
0.3309,0.3309,0.7121,0.7121,0.7121,0.6724,0.6724,0.6724,
0.3816,0.3816,0.3816,0.7317,0.7317,0.7317,0.7003,0.7003,
0.7003,0.7932,0.7932,0.7932,0.8188,0.8188,0.8188,0.7889,
0.7889,0.7889,0.7731,0.7731,0.7731)),row.names=c(NA,-505L
),class=c("data.table","data.frame"))
$\endgroup$
1
  • $\begingroup$ Could you share what package provides the qqp function? $\endgroup$
    – josliber
    Commented Mar 5, 2020 at 15:36

1 Answer 1

1
$\begingroup$

The warning messages you received are informative here:

2: Some predictor variables are on very different scales: consider rescaling

So it seems like a good approach is to rescale some variables. Let's start by taking a look at the data summary:

summary(temp)
#       DATE                 SITE           y                x          
#  Min.   :2018-06-02   CB17   : 87   Min.   :  0.00   Min.   :      0  
#  1st Qu.:2018-06-12   CB1    : 15   1st Qu.:  0.00   1st Qu.:   1448  
#  Median :2018-06-20   CB2    : 15   Median :  4.00   Median :  10312  
#  Mean   :2018-09-28   CB3    : 15   Mean   : 22.19   Mean   :  90391  
#  3rd Qu.:2019-06-06   CB6    : 15   3rd Qu.: 20.00   3rd Qu.:  49360  
#  Max.   :2019-06-28   CB8    : 15   Max.   :608.00   Max.   :1365272  
#                       (Other):343                                     
#  z.fac        SIDI       
#  0: 45   Min.   :0.3309  
#  1:184   1st Qu.:0.6724  
#  2:201   Median :0.7505  
#  3: 69   Mean   :0.7285  
#  4:  6   3rd Qu.:0.8385  
#          Max.   :0.8719  

Here, x jumps out as a culprit -- it's on a much different scale from the rest of the data. You can try the following:

library(lme4)
temp$xrescale <- temp$x / 10000
m.glm <- glmer.nb(y ~ xrescale + z.fac  + SIDI  +(1|SITE), data=temp)

You still get warnings about numerical challenges in fitting the model, but at least it converges with the scaled version of x in the model.

It is actually quite common for optimization models to struggle to include variables on much different scales (the google results for "variable scale optimization" return some informative results like https://www.alglib.net/optimization/scaling.php ). As a result, feature scaling is a common data pre-processing step. As you can see here, it can materially affect whether or not your model converges.

$\endgroup$
5
  • $\begingroup$ I totally agree with you. But I'm still confused if I need to rescale other variables when I proceed x/10000 like y/10000 , z.fac/10000 . Do they need to proceed at the same time ? $\endgroup$ Commented Mar 6, 2020 at 0:34
  • $\begingroup$ @PeterPanPan folks often will, e.g. by dividing each by their standard deviation. $\endgroup$
    – josliber
    Commented Mar 6, 2020 at 0:48
  • $\begingroup$ oh I got confused more. It generates a new problem ? Before I use scale() to variables, all variables ,you know , are discrete data, therefore I am capable of using poisson or negative binomial if fitdistr checks ok. But after scale() applying all of variables, they will be continuous data .,and then the norm or lnorm distribution fits the data. But fitdist() displays countable data with negative binomail is pretty good , as above graphic, wheras the norm and lnorm with scale(y) are not so good. So is that correct that I only scale(x) but others variables keep countable data? Thank u. $\endgroup$ Commented Mar 6, 2020 at 3:15
  • $\begingroup$ @PeterPanPan there's probably no need to scale the 1/0 dummy variables introduced from a categorical variable -- they are already on a reasonable scale. But scaling your continuous variables would be reasonable. $\endgroup$
    – josliber
    Commented Mar 6, 2020 at 14:23
  • $\begingroup$ oh yeah you are right. thank you about that. thank you $\endgroup$ Commented Mar 8, 2020 at 3:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.