0

I'm running a segmented poisson glm (R version 4.1.0), but the output is giving me huge estimates and standard errors so I think something is wrong. I don't get any errors or warnings when I run the model. However, when I do a Davies' test on the segmented model, I do get an error. Code + error shown below.

library(segmented)
df <- structure(list(nspp = c(0L, 0L, 2L, 1L, 0L, 2L, 3L, 2L, 
                                     1L, 2L, 6L, 3L), date_num = 1:12), class = "data.frame", row.names = c(NA, 
                                                                                                          -12L))
glm <- glm(nspp ~ date_num, family="poisson", data=df)
seg_glm <- segmented(glm , seg.Z = ~date_num)
summary(seg_glm)

***Regression Model with Segmented Relationship(s)***

Call: 
segmented.glm(obj = adv_nn_spp_m, seg.Z = ~date_num)

Estimated Break-Point(s):
                Est. St.Err
psi1.date_num 2.097 50.665

Meaningful coefficients of the linear terms:
            Estimate Std. Error z value Pr(>|z|)
(Intercept)   -430.2    21078.6  -0.020    0.984
date_num       205.1    13331.2   0.015    0.988
U1.date_num   -205.0    13331.2  -0.015       NA

(Dispersion parameter for poisson family taken to be 1)

Null     deviance: 19.1048  on 11  degrees of freedom
Residual deviance:  7.5822  on  8  degrees of freedom
AIC: 39.678

Boot restarting based on 9 samples. Last fit:
Convergence attained in 0 iterations (rel. change 0.0000000033397)

You can see the estimates and standard errors are huge.

This is the warning message from the Davies' test:

davies.test(glm, seg.Z= ~date_num)

Warning message:
glm.fit: fitted rates numerically 0 occurred 

Is this purely because I don't have much data? Or too many zeros? Any help appreciated!

LHordley
  • 95
  • 5
  • It sems you have only on value for each value of date_num (the segmented variable). I changed nspp variable with randomly drawn integers from 1 to 6 and increased the sample size to 60. It seems to work fine. Try running these two lines and see for yourself .df2 <- df[rep(seq_len(nrow(df)), times = 5), ] and then df2$nspp <- sample.int(6,60, replace = TRUE). After this, run your regression. – Vaibhav Aug 03 '22 at 09:31
  • Thanks for your help. I do only have one value for each value of date_num, this is the data I have unfortunately. It does work for other data with the same format of one value for each date_num, so I don't think that is the specific issue. – LHordley Aug 03 '22 at 10:59
  • Could you share that data by any chance? – Vaibhav Aug 03 '22 at 11:30
  • Here you go `df2 <- structure(list(nspp = c(1L, 1L, 0L, 1L, 2L, 0L, 2L, 0L, 1L, 3L, 8L, 3L), date_num = 1:12), class = "data.frame", row.names = c(NA, -12L))` – LHordley Aug 03 '22 at 12:15
  • plot your segmented glm object. There seems to be some issue with the breakpoint, which is estimated at 2. Thus, the additional coefficient in the segmented regression is basically calculated with 1 variable's data (that's probably why it's just the inverse of the other coefficient). This is probably going to reduce the degree of freedom to close to 0. Can you manually specify a breakpoint? I also noticed that the first 2 fitted values in the model are essentially zero. This whole result seems to be because of the kind of variation in your data, that doesn't lend itself well to segmented reg. – Vaibhav Aug 03 '22 at 14:41
  • Try this - https://stackoverflow.com/questions/12135400/errors-in-segmented-package-breakpoints-confusion – Vaibhav Aug 03 '22 at 14:50

0 Answers0