1

When I run the following model I get the below error.

> w7 <- glmmTMB(weight_t ~ 
+                 tagged + ns(age.x, knots = c(73, 134, 220, 292)) + (age.x || scale_id) + (1 | clutch_id), 
+               data = long, family = gaussian)
Error in names(object) <- nm : 
  'names' attribute [3] must be the same length as the vector [1]
> 

When I google this error message, it get lots of results and it often seems to be the result of trying to assign names to a vector that is shorter than the vector of names, for example see here. However, in my example I cannot work out why I am getting this error. Any help would be much appreciated?

The length of all of my variables in my model are equal

> length(long$weight_t)
[1] 1200
> length(long$tagged)
[1] 1200
> length(long$age.x)
[1] 1200
> length(long$scale_id)
[1] 1200
> length(long$clutch_id)
[1] 1200
>

I'm not sure that it is relevant but below are also the number of levels of each factor variable

> levels(long$clutch_id)
[1] "1" "2" "3" "4" "5" "6" "7" "8"
> levels(long$scale_id)
  [1] "1"   "2"   "3"   "4"   "5"   "6"   "7"   "8"   "9"   "10"  "11"  "12"  "13"  "14"  "15"  "16"  "17"  "18"  "19"  "20"  "21" 
 [22] "22"  "23"  "24"  "25"  "26"  "27"  "28"  "29"  "30"  "31"  "32"  "33"  "34"  "35"  "36"  "37"  "38"  "39"  "40"  "41"  "42" 
 [43] "43"  "44"  "45"  "46"  "47"  "48"  "49"  "50"  "51"  "52"  "53"  "54"  "55"  "56"  "57"  "58"  "59"  "60"  "61"  "62"  "63" 
 [64] "64"  "65"  "66"  "67"  "68"  "69"  "70"  "71"  "72"  "73"  "74"  "75"  "76"  "77"  "78"  "79"  "80"  "81"  "82"  "83"  "84" 
 [85] "85"  "86"  "87"  "88"  "89"  "90"  "91"  "92"  "93"  "94"  "95"  "96"  "97"  "98"  "99"  "100" "101" "102" "103" "104" "105"
[106] "106" "107" "108" "109" "110" "111" "112" "113" "114" "115" "116" "117" "118" "119" "120" "121" "122" "123" "124" "125" "126"
[127] "127" "128" "129" "130" "131" "132" "133" "134" "135" "136" "137" "138" "139" "140" "141" "142" "143" "144" "145" "146" "147"
[148] "148" "149" "150" "151" "152" "153" "154" "155" "156" "157" "158" "159" "160" "161" "162" "163" "164" "165" "166" "167" "168"
[169] "169" "170" "171" "172" "173" "174" "175" "176" "177" "178" "179" "180" "181" "182" "183" "184" "185" "186" "187" "188" "189"
[190] "190" "191" "192" "193" "194" "195" "196" "197" "198" "199" "200"
> levels(long$tagged)
[1] "0" "1"
> 

and summaries for each variable

> summary(long$weight_t)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
     70     325    1628    2649    4200   16000     107 
> summary(long$tagged)
  0   1 
600 600 
> summary(long$age.x)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
    9.0    73.0   177.0   185.5   292.0   385.0 
> summary(long$scale_id)
      1       2       3       4       5       6       7       8       9      10      11      12      13      14      15      16 
      6       6       6       6       6       6       6       6       6       6       6       6       6       6       6       6 
     17      18      19      20      21      22      23      24      25      26      27      28      29      30      31      32 
      6       6       6       6       6       6       6       6       6       6       6       6       6       6       6       6 
     33      34      35      36      37      38      39      40      41      42      43      44      45      46      47      48 
      6       6       6       6       6       6       6       6       6       6       6       6       6       6       6       6 
     49      50      51      52      53      54      55      56      57      58      59      60      61      62      63      64 
      6       6       6       6       6       6       6       6       6       6       6       6       6       6       6       6 
     65      66      67      68      69      70      71      72      73      74      75      76      77      78      79      80 
      6       6       6       6       6       6       6       6       6       6       6       6       6       6       6       6 
     81      82      83      84      85      86      87      88      89      90      91      92      93      94      95      96 
      6       6       6       6       6       6       6       6       6       6       6       6       6       6       6       6 
     97      98      99 (Other) 
      6       6       6     606 
> summary(long$clutch_id)
  1   2   3   4   5   6   7   8 
162 180 126 162 156 168 120 126
>

Edit 1: I am unable to post original data, but have also now included the results of traceback if this helps.

> traceback()
8: setNames(ans, names(reTrms$Ztlist))
7: getReStruc(reTrms, ss)
6: eval(substitute(expr), data, enclos = parent.frame())
5: eval(substitute(expr), data, enclos = parent.frame())
4: with.default(condList, getReStruc(reTrms, ss))
3: with(condList, getReStruc(reTrms, ss))
2: mkTMBStruc(formula, ziformula, dispformula, combForm, mf, fr, 
       yobs = y, respCol, weights, contrasts = contrasts, family = family, 
       se = se, call = call, verbose = verbose, REML = REML, start = start, 
       map = map, sparseX = sparseX)
1: glmmTMB(weight_t ~ tagged + ns(age.x, knots = c(73, 134, 220, 
       292)) + (age.x || scale_id) + (1 | clutch_id), data = long, 
       family = gaussian)

Edit 2: This posts suggests that this error can occur if a particular column in the data has fewer unique values than rows in the column, with many consecutively repeating values. This may be my problem here? long$clutch_id has only 8 unique values that repeat throughout the column of data, in fact long$scale_id is actually nested within long$clutch_id. Maybe this is also partly why I get this error, maybe R is recognising this nesting/clustering? If I specify the random effects in my model slightly differently, I no longer get this error, but instead just get an error message that suggests my model is overparametised.

> w7 <- glmmTMB(weight_t ~ 
+                 tagged + ns(age.x, knots = c(73, 134, 220, 292)) + (age.x || clutch_id/scale_id), 
+               data = long, family = gaussian)
Warning message:
In fitTMB(TMBStruc) :
  Model convergence problem; non-positive-definite Hessian matrix. See vignette('troubleshooting')
> 
Pat Taggart
  • 321
  • 1
  • 9

0 Answers0