1

I am using glmmTMB to run a zero-inflated two-component hurdle model to determine how certain covariates might influence (1) whether or not a fish has food in its stomach and (2) if the stomach contains food, which covariates effect the number of prey items found in its stomach.

My data consists of the year a fish was caught, the season it was caught, sex, condition, place of origin, gross sea age (1SW = one year at sea, MSW = multiple years at sea), its genotype at two different loci, and fork length residuals. Data are available at my GitHub here.

Model interpretation

When I run the model (see code below), I get the following warning message about unusually large z-statistics.

library(glmmTMB)
library(DHARMa)
library(performance)
set.seed(111) 
feast_or_famine_all_prey <- glmmTMB(num_prey ~ autumn_winter+  
          fishing_season + sex+ condition_scaled + 
          place_of_origin+ 
          sea_age/(gene1+gene2+fork_length_residuals) + (1|location),
    data = data_5,
    family= nbinom2,
    ziformula = ~ .,
    dispformula = ~ fishing_season + place_of_origin,    
    control = glmmTMBControl(optCtrl = list(iter.max = 100000, 
       eval.max = 100000), 
       profile = TRUE, collect = FALSE))

summary(feast_or_famine_all_prey_df)
diagnose(feast_or_famine_all_prey_df)

Since the data does display imbalance for the offending variables (e.g. mean number of prey items in autumn = 85.33, mean number of prey items in winter = 10.61), I think the associated model parameters are near the edge of their range, hence, the extreme probabilities suggested by the z-statistics. Since this is an actual reflection of the underlying data structure (please correct me if I'm wrong!) and not a failure of the model itself, is the model output safe to interpret and use?

Conflicting error messages

Using the diagnose() function as well as exploring model diagnostics using the DHARMa package seem to suggest the model is okay.

diagnose(feast_or_famine_all_prey_df)

ff_all_prey_residuals_df<- simulateResiduals(feast_or_famine_all_prey_df, n = 1000)

testUniformity(ff_all_prey_residuals_df)
testOutliers(ff_all_prey_residuals_df, type = "bootstrap")
testDispersion(ff_all_prey_residuals_df)
testQuantiles(ff_all_prey_residuals_df)
testZeroInflation(ff_all_prey_residuals_df)
 

However, if I run the code performance::r2_nakagawa(feast_or_famine_all_prey_df) then I get the following error messages:

> R2 for Mixed Models
 Conditional R2: 0.333
     Marginal R2: 0.251

Warning messages: 1: In (function (start, objective, gradient = NULL, hessian = NULL, : NA/NaN function evaluation 2: In (function (start, objective, gradient = NULL, hessian = NULL, : NA/NaN function evaluation 3: In (function (start, objective, gradient = NULL, hessian = NULL, : NA/NaN function evaluation 4: In fitTMB(TMBStruc) : Model convergence problem; non-positive-definite Hessian matrix. See vignette('troubleshooting') 5: In fitTMB(TMBStruc) : Model convergence problem; false convergence (8). See vignette('troubleshooting')"

None of these appeared using diagnose() nor were they (to the best of my knowledge) hinted at by the DHARMa diagnostics. Should these errors be believed?

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453

1 Answers1

1

Short answer: when you run performance::r2_nakagawa it refits the model with the fixed effects components removed. It's possible that your R^2 estimates are unreliable, but this shouldn't affect any of the other model results.

(update after much digging):

The code descends through these functions:

performance::r2_nakagawa
performance:::.compute_random_vars
insight::get_variance
insight:::.compute_variances
insight:::.compute_variance_distribution
insight:::.variance_distributional
insight:::null_model
insight:::.null_model_mixed

at which point it tries to run a null model with no fixed effects (num_prey ~ (1 | location)). This is where the warnings are coming from.

When I run your code I get R^2 values of 0.308/0.237, which does suggest that this is a somewhat unstable calculation (not that these differences would really change the conclusion much).

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • Thanks, Ben. Appreciate the work you put in investigating this. I've accepted your answer but I don't have the reputation to upvote it, sorry! – Ronan O'Sullivan Jan 31 '23 at 08:18