moving models

library (tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ ggplot2 3.4.0      ✔ purrr   1.0.1 
✔ tibble  3.1.8      ✔ dplyr   1.0.10
✔ tidyr   1.3.0      ✔ stringr 1.5.0 
✔ readr   2.1.3      ✔ forcats 0.5.2 
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
library(ggplot2)
library(lme4)
Loading required package: Matrix

Attaching package: 'Matrix'

The following objects are masked from 'package:tidyr':

    expand, pack, unpack
library(glmmTMB)
Warning in checkDepPackageVersion(dep_pkg = "TMB"): Package version inconsistency detected.
glmmTMB was built with TMB version 1.9.1
Current TMB version is 1.9.2
Please re-install glmmTMB from source or restore original 'TMB' package (see '?reinstalling' for more information)
library(effects)
Loading required package: carData
lattice theme set by effectsTheme()
See ?effectsTheme for details.
library(car)

Attaching package: 'car'

The following object is masked from 'package:dplyr':

    recode

The following object is masked from 'package:purrr':

    some
library(bbmle)
Loading required package: stats4

Attaching package: 'bbmle'

The following object is masked from 'package:dplyr':

    slice
library(performance)

behavior_23Feb23 <- read.csv("behavior_23Feb23.csv")

behavior <- behavior_23Feb23

Moving Model

m5 <- glmer(formula = moving~temp+day_of_experiment+infected+total_alive+(1|parent), family = "poisson", data = behavior)
Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, : Model is nearly unidentifiable: very large eigenvalue
 - Rescale variables?
# Warning: Model is nearly unidentifiable: very large eigenvalue
plot(allEffects(m5)) 

vif(m5)
             temp day_of_experiment          infected       total_alive 
         1.029687          1.184594          1.043548          1.165267 

Model 5.1: everything except random effect

m5.1 <- glm(formula = moving~temp+day_of_experiment+infected+total_alive, family = "poisson", data = behavior)
plot(allEffects(m5.1)) 

vif(m5.1)
             temp day_of_experiment          infected       total_alive 
         1.072961          1.259494          1.136671          1.123930 

dAIC

ICtab(m5,m5.1)
     dAIC df
m5    0.0 6 
m5.1 22.8 5 
# keep random effect 

Model 5.2: everything except total_alive

m5.2 <- glmer(formula = moving~temp+day_of_experiment+infected+(1|parent), family = "poisson", data = behavior)
Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, : Model is nearly unidentifiable: very large eigenvalue
 - Rescale variables?
# Warning: Model is nearly unidentifiable: very large eigenvalue
plot(allEffects(m5.2)) 

Model 5.3: everything except infected

m5.3 <- glmer(formula = moving~temp+day_of_experiment+total_alive+(1|parent), family = "poisson", data = behavior)
Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, : Model is nearly unidentifiable: very large eigenvalue
 - Rescale variables?
# Warning: Model is nearly unidentifiable: very large eigenvalue
plot(allEffects(m5.3)) 

Model 5.4; everything except day_of_experiment

m5.4 <- glmer(formula = moving~temp+infected+total_alive+(1|parent), family = "poisson", data = behavior)
Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
Model failed to converge with max|grad| = 0.0026707 (tol = 0.002, component 1)
Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, : Model is nearly unidentifiable: very large eigenvalue
 - Rescale variables?
# Warning: Model is nearly unidentifiable: very large eigenvalue
plot(allEffects(m5.4)) 

Compare model performance

compare_performance(m5,m5.1,m5.2,m5.3,m5.4, rank=TRUE)
Warning: Following indices with missing values are not used for ranking:
  R2_conditional, R2_marginal, ICC, R2_Nagelkerke
# Comparison of Model Performance Indices

Name |    Model |  RMSE | Sigma | Score_log | Score_spherical | AIC weights | AICc weights | BIC weights | Performance-Score
----------------------------------------------------------------------------------------------------------------------------
m5.3 | glmerMod | 2.084 | 1.000 |    -2.078 |           0.025 |       0.325 |        0.327 |       0.864 |            85.02%
m5   | glmerMod | 2.085 | 1.000 |    -2.077 |           0.025 |       0.675 |        0.673 |       0.136 |            84.03%
m5.4 | glmerMod | 2.102 | 1.000 |    -2.088 |           0.025 |    4.25e-06 |     4.27e-06 |    1.13e-05 |            42.23%
m5.2 | glmerMod | 2.169 | 1.000 |    -2.131 |           0.025 |    1.01e-30 |     1.01e-30 |    2.68e-30 |            22.90%
m5.1 |      glm | 2.110 | 1.270 |    -2.094 |           0.025 |    7.51e-06 |     7.56e-06 |    1.99e-05 |            19.71%
#Model 5.3: excluding infection works best...