2

I'm fairly new to R but have so far been managing to use it for my master's thesis.

Having run the following GLM:

M1 <- glm.nb(abundance ~ temp * fseason * fperiod * fregion 
                       + offset(LogRSize) + offset(LogPLength) + offset(LogSLength), 
                       data = test_data)

visreg(M1, "temp", by = "fperiod")

I am trying to visualise the regression using visreg, however am getting the following error message. I have used visreg to run a model of the same structure and the data in the same format and it works fine - the only difference was that the dataset is for a different time period, so I am not sure what is different this time.

Error in qr.solve(qr.R(qr.lm(object))[p1, p1]) :
singular matrix 'a' in solve

    > str(test_data)
tibble [2,660 x 15] (S3: tbl_df/tbl/data.frame)
 $ abundance     : num [1:2660] 0 0 0 0 0 1 0 0 4 0 ...
 $ month         : chr [1:2660] "09" "10" "11" "09" ...
 $ season        : num [1:2660] 1 1 1 1 1 1 1 1 1 1 ...
 $ season_length : num [1:2660] 3 3 3 3 3 3 3 3 3 3 ...
 $ period        : chr [1:2660] "1" "1" "1" "1" ...
 $ period_length : num [1:2660] 10 10 10 10 10 10 10 10 10 10 ...
 $ region        : num [1:2660] 2 2 2 2 2 2 2 2 2 2 ...
 $ region_size_km: num [1:2660] 19157 19157 19157 19157 19157 ...
 $ temp          : num [1:2660] 15.38 9.51 5.03 14.99 8.99 ...
 $ fseason       : Factor w/ 2 levels "1","2": 1 1 1 1 1 1 1 1 1 1 ...
 $ LogSLength    : num [1:2660] 1.1 1.1 1.1 1.1 1.1 ...
 $ fperiod       : Factor w/ 3 levels "1","2","3": 1 1 1 1 1 1 1 1 1 1 ...
 $ LogPLength    : num [1:2660] 2.3 2.3 2.3 2.3 2.3 ...
 $ LogRSize      : num [1:2660] 9.86 9.86 9.86 9.86 9.86 ...
 $ fregion       : Factor w/ 10 levels "1","2","3","4",..: 2 2 2 2 2 2 2 2 2 2 ...

Minimum reproducible example here:

https://drive.google.com/drive/folders/1p3-0BqKvErtedbT2PIr0J_FKSxihg4Td?usp=sharing

  • Are you receiving the error after the modelling i.e. nothing to do with visreg? It could be you are trying to estimate more parameters than observations? Could you add `str(test_data)` to your question please. – user20650 Aug 13 '20 at 20:06
  • I have edited the post to include. No, the modelling runs fine without the generating the error, it is only after I attempt the visreg function that it appears. – Matt Livesey Aug 13 '20 at 20:24
  • Thanks. Its probably worth showing the `visreg` code if that is what is throwing the error - just in case someone uses `visreg` notices something obvious. – user20650 Aug 13 '20 at 20:26
  • we will probably need a [mcve] in order to debug this ... does `summary(M1)` work OK? – Ben Bolker Aug 13 '20 at 20:34
  • 1
    Okay I will get on it - yes the model summary works fine. – Matt Livesey Aug 13 '20 at 20:43
  • @BenBolker unfortunately I can only reproduce the visreg error with 500+ observations of 11 variables. Any less than this and the glm command will not run due to errors. The resulting code then exceeds the character limit of my original post when I try to edit it back in. – Matt Livesey Aug 13 '20 at 21:53
  • Can you post the data in some publicly accessible place and provide a link? – Ben Bolker Aug 13 '20 at 21:53
  • I've put the code into a notepad file and added a link to download it into the main post. – Matt Livesey Aug 13 '20 at 22:23

0 Answers0