#### From Lagrangian to Eulerian perspectives
#### Script: Function to compute the contribution of each variable to the linear predictor
#### Last modification: 04 04 2024
#### R version 4.2.3 (2023-03-15 ucrt) -- "Shortstop Beagle"

contrib_func <- function(model, data){
  pred <- predict(model, newdata = data, type = "terms")
  
  predlin <- rowSums(abs(pred))  
  relative.row <- apply(pred, MARGIN = 2, FUN = function(x){abs(x) / abs(predlin)}) 
  contrib <- apply(relative.row, MARGIN = 2, FUN = mean, na.rm = T) 
  
  return(contrib)
}
