Chapter 3 Model testing

We tested five models with varying degrees of complexity to estimate the probabilities of each animal to win a tube-test encounter against any of their cage mates.

cages=c("C03","C04","C05","C06","C10","C11","C12","C13")

model_performance1 <- data.frame()
model_performance2 <- data.frame()
for(cage in cages){
    #Filter table by cage
    cage_data <- tube_test_data %>% filter(cage_id == cage)
    #Model with temporal autocorrelation (NULL if the model does not converge)
    M1 <- tryCatch({glmmTMB(win_loss_binomial~1+(1|mouse)+(1|treatment:mouse), data = cage_data, family = binomial)}, warning = function(w){NULL})
    M2 <- tryCatch({glmmTMB(win_loss_binomial~1+ar1(time+0|mouse)+(1|treatment:mouse), data = cage_data, family = binomial)}, warning = function(w){NULL})
    M3 <- tryCatch({glmmTMB(win_loss_binomial~1+ar1(time+0|mouse), data = cage_data, family = binomial)}, warning = function(w){NULL})
    M4 <- tryCatch({glmmTMB(win_loss_binomial~1+(1|mouse), data = cage_data, family = binomial)}, warning = function(w){NULL})
    M5 <- tryCatch({glmmTMB(win_loss_binomial~1, data = cage_data, family = binomial)}, warning = function(w){NULL})
    
    aic <- c(M1=if(is.null(M1)){NA}else{AIC(M1)},
             M2=if(is.null(M2)){NA}else{AIC(M2)},
             M3=if(is.null(M3)){NA}else{AIC(M3)},
             M4=if(is.null(M4)){NA}else{AIC(M4)},
             M5=if(is.null(M5)){NA}else{AIC(M5)}) %>% sort()
    
    rank <- names(aic)
             
    # Append predictions to table
    model_performance1 <- bind_rows(model_performance1,rank %>% as.data.frame() %>% t() %>% as.data.frame())
    model_performance2 <- bind_rows(model_performance2,aic %>% as.data.frame() %>% t() %>% as.data.frame())
}

3.1 Model performance

colnames(model_performance2) <- c("M1","M2","M3","M4","M5")
rownames(model_performance2) <- cages
model_performance2 %>% 
  rownames_to_column(var="Cage") %>%
  tt() |> 
      style_tt(j = 1, color = "#6e0f0f", background = "#e39d9d") |> 
      style_tt(i = 0, color = "white", background = "#a52929")
tinytable_aekb40jriwxkw5ijj27c
Cage M1 M2 M3 M4 M5
C03 403.2859 404.1349 405.2859 407.3120 478.8853
C04 483.7269 486.7366 485.7269 493.9658 584.2436
C05 410.3836 415.5269 412.3836 414.9560 575.9259
C06 445.0369 446.3006 447.0369 444.5417 575.9259
C10 423.7239 423.9744 425.7239 421.9744 584.2436
C11 471.6309 481.7121 473.6309 500.8893 581.4710
C12 NA 400.2945 NA 398.2945 584.2436
C13 403.1068 406.1184 405.1068 404.1184 584.2436

3.2 Model rank

colnames(model_performance1) <- c("1","2","3","4","5")
rownames(model_performance1) <- cages
model_performance1 %>% 
  rownames_to_column(var="Cage") %>%
  tt() |> 
      style_tt(j = 1, color = "#6e0f0f", background = "#e39d9d") |> 
      style_tt(i = 0, color = "white", background = "#a52929")
tinytable_uuhxkutegmxo4j2s6z0m
Cage 1 2 3 4 5
C03 M3 M1 M2 M4 M5
C04 M3 M2 M1 M4 M5
C05 M3 M2 M4 M1 M5
C06 M4 M3 M1 M2 M5
C10 M4 M3 M1 M2 M5
C11 M3 M2 M1 M4 M5
C12 M4 M1 M5 NA NA
C13 M3 M4 M2 M1 M5