Pedigree_PIC

Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.

Running Code

When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:

library(broom)
library(lme4)
Loading required package: Matrix
library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
library(lme4)
library(lmerTest)

Attaching package: 'lmerTest'
The following object is masked from 'package:lme4':

    lmer
The following object is masked from 'package:stats':

    step
library(emmeans)
library(car)
Loading required package: carData

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

    recode
library(tidyverse)
-- Attaching core tidyverse packages ------------------------ tidyverse 2.0.0 --
v forcats   1.0.0     v readr     2.1.4
v ggplot2   3.4.3     v stringr   1.5.0
v lubridate 1.9.2     v tibble    3.2.1
v purrr     1.0.1     v tidyr     1.3.0
-- Conflicts ------------------------------------------ tidyverse_conflicts() --
x tidyr::expand() masks Matrix::expand()
x dplyr::filter() masks stats::filter()
x dplyr::lag()    masks stats::lag()
x tidyr::pack()   masks Matrix::pack()
x car::recode()   masks dplyr::recode()
x purrr::some()   masks car::some()
x tidyr::unpack() masks Matrix::unpack()
i Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(corrplot)
corrplot 0.92 loaded
library(RColorBrewer)
library(ggplot2)
library(MASS)

Attaching package: 'MASS'

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

    select
library(agricolae)
library(vegan)
Loading required package: permute
Loading required package: lattice
Registered S3 methods overwritten by 'vegan':
  method      from
  plot.rda    klaR
  predict.rda klaR
  print.rda   klaR
This is vegan 2.6-4
library(dplyr)
library(readr)
library(DT)
library(ggplot2)
library(quantreg)
Loading required package: SparseM

Attaching package: 'SparseM'

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

    backsolve
library(broom.mixed)
library(pedigree)
library(pedigreemm)
library(pedtools)

You can add options to executable code like this

Reading data

rm(list = ls())

setwd("C:/Users/anune/OneDrive/Desktop/PIC_DataAnalysis_files")

data_PIC <- read.csv("PIC_65_FIRE.AN.1.csv")

head(data_PIC$ENTRY_TIME)
[1] "10/27/2022 12:51" "10/27/2022 12:00" "10/27/2022 13:03" "10/27/2022 7:27" 
[5] "10/27/2022 8:04"  "10/27/2022 8:41" 
data_PIC <- mutate(data_PIC, 

                   ENTRY_DATE = as_date(mdy_hm(ENTRY_TIME, tz = "UTC")),

                   ENTRY = mdy_hm(ENTRY_TIME, tz = "UTC")

                   )

summary(data_PIC$ENTRY_DATE)
        Min.      1st Qu.       Median         Mean      3rd Qu.         Max. 
"2022-04-06" "2023-01-02" "2023-02-19" "2023-02-18" "2023-04-08" "2023-06-19" 

Data arrange

class(data_PIC)
[1] "data.frame"
data_PIC$PEN <- as.factor(data_PIC$PEN)

data_PIC$Social_Group <- paste(data_PIC$PEN, data_PIC$START_DAY, data_PIC$OFFTEST_DAY, sep = "_")

head(data_PIC$Social_Group)
[1] "B0113_27-Oct-22_2-Jan-23" "B0113_27-Oct-22_2-Jan-23"
[3] "B0113_27-Oct-22_2-Jan-23" "B0113_27-Oct-22_2-Jan-23"
[5] "B0113_27-Oct-22_2-Jan-23" "B0113_27-Oct-22_2-Jan-23"
data_PIC <- group_by(data_PIC, Social_Group)


data_PIC.arrange <- arrange(data_PIC, Social_Group, ENTRY, by_group = TRUE)%>%
  mutate(line= row_number())


data_PIC.arrange
# A tibble: 114,263 x 20
# Groups:   Social_Group [36]
         ID  LINE    SIRE    DAM LITTER PEN    FARM ENTRY_TIME EXIT_TIME STAY_IN
      <int> <int>   <int>  <int>  <int> <fct> <int> <chr>      <chr>       <int>
 1 97900600    65  8.82e7 9.22e7 7.90e7 B0111   774 3/15/2023~ 3/15/202~     156
 2 97900500    65  9.20e7 9.15e7 7.86e7 B0111   774 3/15/2023~ 3/15/202~     416
 3 97900600    65  8.82e7 9.22e7 7.90e7 B0111   774 3/15/2023~ 3/15/202~     469
 4 97887849    65  8.83e7 9.34e7 7.90e7 B0111   774 3/15/2023~ 3/15/202~      48
 5 97900500    65  9.20e7 9.15e7 7.86e7 B0111   774 3/15/2023~ 3/15/202~     166
 6 97900600    65  8.82e7 9.22e7 7.90e7 B0111   774 3/15/2023~ 3/15/202~     113
 7 97887847    65  8.83e7 9.34e7 7.90e7 B0111   774 3/15/2023~ 3/15/202~       7
 8 97900600    65  8.82e7 9.22e7 7.90e7 B0111   774 3/15/2023~ 3/15/202~     103
 9 97887847    65  8.83e7 9.34e7 7.90e7 B0111   774 3/15/2023~ 3/15/202~      24
10 97900231    65  8.83e7 9.37e7 7.90e7 B0111   774 3/15/2023~ 3/15/202~    1862
# i 114,253 more rows
# i 10 more variables: FEED_INTK <int>, ENTRY_WT <int>, EXIT_WT <int>,
#   FEEDER_NO <int>, START_DAY <chr>, OFFTEST_DAY <chr>, ENTRY_DATE <date>,
#   ENTRY <dttm>, Social_Group <chr>, line <int>
data_PIC.arrange %>%
  dplyr::select(ID, ENTRY, Social_Group)
# A tibble: 114,263 x 3
# Groups:   Social_Group [36]
         ID ENTRY               Social_Group             
      <int> <dttm>              <chr>                    
 1 97900600 2023-03-15 08:06:00 B0111_16-Mar-23_15-May-23
 2 97900500 2023-03-15 08:12:00 B0111_16-Mar-23_15-May-23
 3 97900600 2023-03-15 08:19:00 B0111_16-Mar-23_15-May-23
 4 97887849 2023-03-15 08:34:00 B0111_16-Mar-23_15-May-23
 5 97900500 2023-03-15 08:36:00 B0111_16-Mar-23_15-May-23
 6 97900600 2023-03-15 08:39:00 B0111_16-Mar-23_15-May-23
 7 97887847 2023-03-15 08:44:00 B0111_16-Mar-23_15-May-23
 8 97900600 2023-03-15 08:49:00 B0111_16-Mar-23_15-May-23
 9 97887847 2023-03-15 08:52:00 B0111_16-Mar-23_15-May-23
10 97900231 2023-03-15 09:04:00 B0111_16-Mar-23_15-May-23
# i 114,253 more rows

Creating time between

#| warning: true
#| echo: true
data_PIC <- data_PIC %>%
  arrange(Social_Group, ENTRY) %>%
  group_by(Social_Group) %>%
  mutate(Follower_ID = lead(ID),
         Follower_Time = lead(ENTRY),
         Follower_Social_Group = lead(Social_Group),
         line= row_number(),
         Hour_ENTRY = hour(ENTRY),
         time_between= as.numeric(Follower_Time - ENTRY, unit="secs"))%>%
  filter(time_between < 36000)
data_PIC%>%
  mutate(time_between= as.numeric(Follower_Time - ENTRY, unit="secs"),
         lapse_Time = seconds(Follower_Time - ENTRY))%>%
  dplyr::select(time_between, lapse_Time)
Adding missing grouping variables: `Social_Group`
# A tibble: 114,210 x 3
# Groups:   Social_Group [36]
   Social_Group              time_between lapse_Time
   <chr>                            <dbl> <Period>  
 1 B0111_16-Mar-23_15-May-23          360 360S      
 2 B0111_16-Mar-23_15-May-23          420 420S      
 3 B0111_16-Mar-23_15-May-23          900 900S      
 4 B0111_16-Mar-23_15-May-23          120 120S      
 5 B0111_16-Mar-23_15-May-23          180 180S      
 6 B0111_16-Mar-23_15-May-23          300 300S      
 7 B0111_16-Mar-23_15-May-23          300 300S      
 8 B0111_16-Mar-23_15-May-23          180 180S      
 9 B0111_16-Mar-23_15-May-23          720 720S      
10 B0111_16-Mar-23_15-May-23         1920 1920S     
# i 114,200 more rows
data_PIC$time_between <- as.numeric(data_PIC$time_between)

data_PIC_pvalues <- filter (data_PIC, time_between > 0) %>%
  mutate(TIME_FEEDER = as.numeric(STAY_IN))


data_PIC_pvalues <- (data_PIC) %>%
     mutate(TIME_FEEDER = as.numeric(STAY_IN))
  
 
summary(data_PIC_pvalues$TIME_FEEDER)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
      5     577    1316    1403    2038   10169 

Data PIC_PValues

head(data_PIC_pvalues)
# A tibble: 6 x 26
# Groups:   Social_Group [1]
        ID  LINE     SIRE    DAM LITTER PEN    FARM ENTRY_TIME EXIT_TIME STAY_IN
     <int> <int>    <int>  <int>  <int> <fct> <int> <chr>      <chr>       <int>
1 97900600    65 88153118 9.22e7 7.90e7 B0111   774 3/15/2023~ 3/15/202~     156
2 97900500    65 92013924 9.15e7 7.86e7 B0111   774 3/15/2023~ 3/15/202~     416
3 97900600    65 88153118 9.22e7 7.90e7 B0111   774 3/15/2023~ 3/15/202~     469
4 97887849    65 88291968 9.34e7 7.90e7 B0111   774 3/15/2023~ 3/15/202~      48
5 97900500    65 92013924 9.15e7 7.86e7 B0111   774 3/15/2023~ 3/15/202~     166
6 97900600    65 88153118 9.22e7 7.90e7 B0111   774 3/15/2023~ 3/15/202~     113
# i 16 more variables: FEED_INTK <int>, ENTRY_WT <int>, EXIT_WT <int>,
#   FEEDER_NO <int>, START_DAY <chr>, OFFTEST_DAY <chr>, ENTRY_DATE <date>,
#   ENTRY <dttm>, Social_Group <chr>, Follower_ID <int>, Follower_Time <dttm>,
#   Follower_Social_Group <chr>, line <int>, Hour_ENTRY <int>,
#   time_between <dbl>, TIME_FEEDER <dbl>
data_PIC_pvalues <- data_PIC_pvalues %>%
  mutate(L_time = log(TIME_FEEDER))

Umbral p-values

umbral <- 60

data_PIC_pvalues_0 <- data_PIC_pvalues %>%
  mutate(time_between_group = case_when(
    time_between <= umbral ~ "immediate",
    time_between > umbral ~ "distant"
  ))%>% group_by(time_between_group) %>%
  group_modify( ~ broom.mixed::tidy(lme4::lmer(L_time ~ (1|ID) + (1|Follower_ID) + (1|Social_Group) + as.factor(Hour_ENTRY) , data = .x)))%>% filter(., effect == "ran_pars") 
boundary (singular) fit: see ?isSingular
data_PIC_pvalues_0
# A tibble: 8 x 7
# Groups:   time_between_group [2]
  time_between_group effect   group        term     estimate std.error statistic
  <chr>              <chr>    <chr>        <chr>       <dbl>     <dbl>     <dbl>
1 distant            ran_pars ID           sd__(In~    0.241        NA        NA
2 distant            ran_pars Follower_ID  sd__(In~    0.154        NA        NA
3 distant            ran_pars Social_Group sd__(In~    0.121        NA        NA
4 distant            ran_pars Residual     sd__Obs~    1.05         NA        NA
5 immediate          ran_pars ID           sd__(In~    0.365        NA        NA
6 immediate          ran_pars Follower_ID  sd__(In~    0.279        NA        NA
7 immediate          ran_pars Social_Group sd__(In~    0            NA        NA
8 immediate          ran_pars Residual     sd__Obs~    1.32         NA        NA
umbral <- 120

data_PIC_pvalues_1 <- data_PIC_pvalues %>%
  mutate(time_between_group = case_when(
    time_between <= umbral ~ "immediate",
    time_between > umbral ~ "distant"
  ))%>% group_by(time_between_group) %>%
  group_modify( ~ broom.mixed::tidy(lme4::lmer(L_time ~ (1|ID) + (1|Follower_ID) + (1|Social_Group) + as.factor(Hour_ENTRY) , data = .x)))%>% filter(., effect == "ran_pars") 

data_PIC_pvalues_1 
# A tibble: 8 x 7
# Groups:   time_between_group [2]
  time_between_group effect   group        term     estimate std.error statistic
  <chr>              <chr>    <chr>        <chr>       <dbl>     <dbl>     <dbl>
1 distant            ran_pars ID           sd__(In~   0.230         NA        NA
2 distant            ran_pars Follower_ID  sd__(In~   0.131         NA        NA
3 distant            ran_pars Social_Group sd__(In~   0.103         NA        NA
4 distant            ran_pars Residual     sd__Obs~   0.963         NA        NA
5 immediate          ran_pars ID           sd__(In~   0.305         NA        NA
6 immediate          ran_pars Follower_ID  sd__(In~   0.213         NA        NA
7 immediate          ran_pars Social_Group sd__(In~   0.0309        NA        NA
8 immediate          ran_pars Residual     sd__Obs~   1.23          NA        NA
#| warning: true
#| echo: true

umbral <- 180

data_PIC_pvalues_3 <- data_PIC_pvalues %>%
  mutate(time_between_group = case_when(
    time_between <= umbral ~ "immediate",
    time_between > umbral ~ "distant"
  ))%>% group_by(time_between_group) %>%
  group_modify( ~ broom.mixed::tidy(lme4::lmer(L_time ~ (1|ID) + (1|Follower_ID) + (1|Social_Group) + as.factor(Hour_ENTRY) , data = .x)))%>% filter(., effect == "ran_pars") 

data_PIC_pvalues_3
# A tibble: 8 x 7
# Groups:   time_between_group [2]
  time_between_group effect   group        term     estimate std.error statistic
  <chr>              <chr>    <chr>        <chr>       <dbl>     <dbl>     <dbl>
1 distant            ran_pars ID           sd__(In~   0.227         NA        NA
2 distant            ran_pars Follower_ID  sd__(In~   0.115         NA        NA
3 distant            ran_pars Social_Group sd__(In~   0.0970        NA        NA
4 distant            ran_pars Residual     sd__Obs~   0.906         NA        NA
5 immediate          ran_pars ID           sd__(In~   0.298         NA        NA
6 immediate          ran_pars Follower_ID  sd__(In~   0.185         NA        NA
7 immediate          ran_pars Social_Group sd__(In~   0.0867        NA        NA
8 immediate          ran_pars Residual     sd__Obs~   1.20          NA        NA
umbral <- 240

data_PIC_pvalues_4 <- data_PIC_pvalues %>%
  mutate(time_between_group = case_when(
    time_between <= umbral ~ "immediate",
    time_between > umbral ~ "distant"
  ))%>% group_by(time_between_group) %>%
  group_modify( ~ broom.mixed::tidy(lme4::lmer(L_time ~ (1|ID) + (1|Follower_ID) + (1|Social_Group) + as.factor(Hour_ENTRY) , data = .x)))%>% filter(., effect == "ran_pars") 

data_PIC_pvalues_4 
# A tibble: 8 x 7
# Groups:   time_between_group [2]
  time_between_group effect   group        term     estimate std.error statistic
  <chr>              <chr>    <chr>        <chr>       <dbl>     <dbl>     <dbl>
1 distant            ran_pars ID           sd__(In~   0.225         NA        NA
2 distant            ran_pars Follower_ID  sd__(In~   0.102         NA        NA
3 distant            ran_pars Social_Group sd__(In~   0.0942        NA        NA
4 distant            ran_pars Residual     sd__Obs~   0.862         NA        NA
5 immediate          ran_pars ID           sd__(In~   0.295         NA        NA
6 immediate          ran_pars Follower_ID  sd__(In~   0.163         NA        NA
7 immediate          ran_pars Social_Group sd__(In~   0.127         NA        NA
8 immediate          ran_pars Residual     sd__Obs~   1.20          NA        NA
umbral <- 300

data_PIC_pvalues_5 <- data_PIC_pvalues %>%
  mutate(time_between_group = case_when(
    time_between <= umbral ~ "immediate",
    time_between > umbral ~ "distant"
  ))%>% group_by(time_between_group) %>%
  group_modify( ~ broom.mixed::tidy(lme4::lmer(L_time ~ (1|ID) + (1|Follower_ID) + (1|Social_Group) + as.factor(Hour_ENTRY) , data = .x)))%>% filter(., effect == "ran_pars") 

data_PIC_pvalues_5
# A tibble: 8 x 7
# Groups:   time_between_group [2]
  time_between_group effect   group        term     estimate std.error statistic
  <chr>              <chr>    <chr>        <chr>       <dbl>     <dbl>     <dbl>
1 distant            ran_pars ID           sd__(In~   0.223         NA        NA
2 distant            ran_pars Follower_ID  sd__(In~   0.0921        NA        NA
3 distant            ran_pars Social_Group sd__(In~   0.0968        NA        NA
4 distant            ran_pars Residual     sd__Obs~   0.829         NA        NA
5 immediate          ran_pars ID           sd__(In~   0.296         NA        NA
6 immediate          ran_pars Follower_ID  sd__(In~   0.163         NA        NA
7 immediate          ran_pars Social_Group sd__(In~   0.155         NA        NA
8 immediate          ran_pars Residual     sd__Obs~   1.21          NA        NA
pedigree_PIC1 <- cbind(data_PIC_pvalues$ID, data_PIC_pvalues$SIRE, data_PIC_pvalues$DAM)


pedigree_PIC1 <- as_tibble(pedigree_PIC1)
Warning: The `x` argument of `as_tibble.matrix()` must have unique column names if
`.name_repair` is omitted as of tibble 2.0.0.
i Using compatibility `.name_repair`.
pedigree_PIC1 <- pedigree_PIC1 %>%
  rename(label = V1, sire = V2, dam = V3)

pedigree_PIC1 <- pedigree_PIC1[!duplicated(pedigree_PIC1$label), ]

head(pedigree_PIC1)
# A tibble: 6 x 3
     label     sire      dam
     <int>    <int>    <int>
1 97900600 88153118 92202164
2 97900500 92013924 91517818
3 97887849 88291968 93371805
4 97887847 88291968 93371805
5 97900231 88291968 93704367
6 97916804 92001659 93679378
dim(pedigree_PIC1)
[1] 548   3

GetA matrix

head(pedigree_PIC1)
# A tibble: 6 x 3
     label     sire      dam
     <int>    <int>    <int>
1 97900600 88153118 92202164
2 97900500 92013924 91517818
3 97887849 88291968 93371805
4 97887847 88291968 93371805
5 97900231 88291968 93704367
6 97916804 92001659 93679378
parents <- unique(c(pedigree_PIC1$sire, pedigree_PIC1$dam))


length(parents)
[1] 291
parents[parents %in% pedigree_PIC1$label]
integer(0)
d <- pedigree(label = as.integer(c(parents, pedigree_PIC1$label)), sire = as.integer(c(rep (NA,length(parents)), pedigree_PIC1$sire)), dam = as.integer(c(rep (NA,length(parents)),pedigree_PIC1$dam)))

tail(d)
             sire      dam
97805279 92913144 89085527
97805268 92913144 89085527
97818574 92013824 93745051
97818711 89122431 92001654
97877792 90086235 91784754
97877789 90086235 91784754
dim(d)
NULL
class(d)
[1] "pedigree"
attr(,"package")
[1] "pedigreemm"
A <- getA(d)
'as(<dtTMatrix>, "dtCMatrix")' is deprecated.
Use 'as(., "CsparseMatrix")' instead.
See help("Deprecated") and help("Matrix-deprecated").
summary(A[upper.tri(A)])
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
0.000000 0.000000 0.000000 0.008621 0.000000 0.500000 
sum(A[upper.tri(A)]>0)
[1] 10535
length(A[upper.tri(A)] > 0 )
[1] 351541
summary(diag(A))
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
      1       1       1       1       1       1 

Pedigreemm models

#| warning: true
#| echo: true


# Creaando IDpe y Follower.pe en el data frame
data_PIC_pvalues_ped1 <- within(data_PIC_pvalues, {
  IDpe <- ID
  Follower.pe <- Follower_ID
  sdL_time <- L_time / sd(L_time)
})

# Modelo completo (fm2), efectos directos e indirectos ambientales y genetico
fm2 <- pedigreemm(
  L_time ~ as.factor(Hour_ENTRY) + (1 | ID) + (1 | Follower_ID) + (1 | IDpe) + (1 | Follower.pe) + (1 | Social_Group),
  data = data_PIC_pvalues_ped1,
  pedigree = list(ID = d, Follower_ID = d)
)
Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
unable to evaluate scaled gradient
Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
Model failed to converge: degenerate Hessian with 1 negative eigenvalues
Warning: Model failed to converge with 1 negative eigenvalue: -1.2e+00
summary(fm2)
Linear mixed model fit by REML ['lmerpedigreemm']
Formula: L_time ~ as.factor(Hour_ENTRY) + (1 | ID) + (1 | Follower_ID) +  
    (1 | IDpe) + (1 | Follower.pe) + (1 | Social_Group)
   Data: data_PIC_pvalues_ped1

REML criterion at convergence: 386274.2

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-4.5254 -0.2866  0.2714  0.6221  2.7755 

Random effects:
 Groups       Name        Variance Std.Dev.
 ID           (Intercept) 0.025220 0.15881 
 Follower_ID  (Intercept) 0.007685 0.08766 
 IDpe         (Intercept) 0.066680 0.25822 
 Follower.pe  (Intercept) 0.044025 0.20982 
 Social_Group (Intercept) 0.024964 0.15800 
 Residual                 1.685723 1.29835 
Number of obs: 114210, groups:  
ID, 548; Follower_ID, 548; IDpe, 548; Follower.pe, 548; Social_Group, 36

Fixed effects:
                        Estimate Std. Error t value
(Intercept)              6.98983    0.04313 162.059
as.factor(Hour_ENTRY)1   0.04022    0.03074   1.308
as.factor(Hour_ENTRY)2   0.02362    0.03059   0.772
as.factor(Hour_ENTRY)3   0.01323    0.03039   0.436
as.factor(Hour_ENTRY)4   0.03578    0.03020   1.185
as.factor(Hour_ENTRY)5  -0.05734    0.02930  -1.957
as.factor(Hour_ENTRY)6  -0.31315    0.02804 -11.167
as.factor(Hour_ENTRY)7  -0.22732    0.02819  -8.063
as.factor(Hour_ENTRY)8  -0.22273    0.02835  -7.857
as.factor(Hour_ENTRY)9  -0.22162    0.02836  -7.814
as.factor(Hour_ENTRY)10 -0.12841    0.02885  -4.451
as.factor(Hour_ENTRY)11 -0.17081    0.02884  -5.923
as.factor(Hour_ENTRY)12 -0.28070    0.02846  -9.863
as.factor(Hour_ENTRY)13 -0.36306    0.02825 -12.854
as.factor(Hour_ENTRY)14 -0.51299    0.02785 -18.419
as.factor(Hour_ENTRY)15 -0.39654    0.02799 -14.165
as.factor(Hour_ENTRY)16 -0.33297    0.02809 -11.856
as.factor(Hour_ENTRY)17 -0.20582    0.02851  -7.220
as.factor(Hour_ENTRY)18 -0.12654    0.02910  -4.348
as.factor(Hour_ENTRY)19 -0.07143    0.02933  -2.435
as.factor(Hour_ENTRY)20 -0.05879    0.02972  -1.978
as.factor(Hour_ENTRY)21 -0.04632    0.03017  -1.535
as.factor(Hour_ENTRY)22 -0.01909    0.03045  -0.627
as.factor(Hour_ENTRY)23 -0.01101    0.03060  -0.360

Correlation matrix not shown by default, as p = 24 > 12.
Use print(x, correlation=TRUE)  or
    vcov(x)        if you need it
# Modelos reducidos
# Modelo reducido para ID, efecto directo genetico
reduced_model_ID <- pedigreemm(
  L_time ~ as.factor(Hour_ENTRY) + (1 | ID) + (1 | Social_Group),
  data = data_PIC_pvalues_ped1,
  pedigree = list(ID = d)
)

# Modelo reducido para IDpe efectos directos ambientales y genetico 
reduced_model_IDpe <- pedigreemm(
  L_time ~ as.factor(Hour_ENTRY) + (1 | ID) + (1 | IDpe) + (1 | Social_Group),
  data = data_PIC_pvalues_ped1,
  pedigree = list(ID = d)
)
boundary (singular) fit: see ?isSingular
Warning: Model failed to converge with 1 negative eigenvalue: -5.2e+00
summary(reduced_model_IDpe)
Linear mixed model fit by REML ['lmerpedigreemm']
Formula: L_time ~ as.factor(Hour_ENTRY) + (1 | ID) + (1 | IDpe) + (1 |  
    Social_Group)
   Data: data_PIC_pvalues_ped1

REML criterion at convergence: 388585.9

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-4.2874 -0.2866  0.2860  0.6300  2.6211 

Random effects:
 Groups       Name        Variance Std.Dev.
 ID           (Intercept) 0.02627  0.1621  
 IDpe         (Intercept) 0.06707  0.2590  
 Social_Group (Intercept) 0.02970  0.1723  
 Residual                 1.73542  1.3174  
Number of obs: 114210, groups:  ID, 548; IDpe, 548; Social_Group, 36

Fixed effects:
                         Estimate Std. Error t value
(Intercept)              7.016809   0.042600 164.712
as.factor(Hour_ENTRY)1   0.036514   0.031130   1.173
as.factor(Hour_ENTRY)2   0.021523   0.030969   0.695
as.factor(Hour_ENTRY)3   0.006791   0.030738   0.221
as.factor(Hour_ENTRY)4   0.030983   0.030503   1.016
as.factor(Hour_ENTRY)5  -0.073353   0.029544  -2.483
as.factor(Hour_ENTRY)6  -0.347895   0.028201 -12.336
as.factor(Hour_ENTRY)7  -0.264929   0.028359  -9.342
as.factor(Hour_ENTRY)8  -0.255182   0.028524  -8.946
as.factor(Hour_ENTRY)9  -0.259550   0.028546  -9.092
as.factor(Hour_ENTRY)10 -0.165934   0.029019  -5.718
as.factor(Hour_ENTRY)11 -0.217798   0.028974  -7.517
as.factor(Hour_ENTRY)12 -0.340229   0.028584 -11.903
as.factor(Hour_ENTRY)13 -0.433719   0.028334 -15.307
as.factor(Hour_ENTRY)14 -0.581989   0.027921 -20.844
as.factor(Hour_ENTRY)15 -0.456343   0.028069 -16.258
as.factor(Hour_ENTRY)16 -0.377625   0.028210 -13.386
as.factor(Hour_ENTRY)17 -0.229053   0.028696  -7.982
as.factor(Hour_ENTRY)18 -0.148303   0.029350  -5.053
as.factor(Hour_ENTRY)19 -0.092012   0.029625  -3.106
as.factor(Hour_ENTRY)20 -0.071361   0.030043  -2.375
as.factor(Hour_ENTRY)21 -0.054179   0.030526  -1.775
as.factor(Hour_ENTRY)22 -0.025068   0.030824  -0.813
as.factor(Hour_ENTRY)23 -0.016638   0.030982  -0.537

Correlation matrix not shown by default, as p = 24 > 12.
Use print(x, correlation=TRUE)  or
    vcov(x)        if you need it
# Modelo reducido para Follower efectos geneticos
reduced_model_Follower <- pedigreemm(
  L_time ~ as.factor(Hour_ENTRY) +  (1 | ID) +  (1 | Follower_ID) + (1 | Social_Group),
  data = data_PIC_pvalues_ped1,
  pedigree = list(ID = d, Follower_ID = d)
)

summary(reduced_model_Follower)
Linear mixed model fit by REML ['lmerpedigreemm']
Formula: L_time ~ as.factor(Hour_ENTRY) + (1 | ID) + (1 | Follower_ID) +  
    (1 | Social_Group)
   Data: data_PIC_pvalues_ped1

REML criterion at convergence: 386341.1

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-4.4963 -0.2861  0.2717  0.6221  2.7629 

Random effects:
 Groups       Name        Variance Std.Dev.
 ID           (Intercept) 0.12626  0.3553  
 Follower_ID  (Intercept) 0.07404  0.2721  
 Social_Group (Intercept) 0.01866  0.1366  
 Residual                 1.68594  1.2984  
Number of obs: 114210, groups:  ID, 548; Follower_ID, 548; Social_Group, 36

Fixed effects:
                        Estimate Std. Error t value
(Intercept)              6.99967    0.05853 119.592
as.factor(Hour_ENTRY)1   0.04047    0.03074   1.316
as.factor(Hour_ENTRY)2   0.02375    0.03059   0.776
as.factor(Hour_ENTRY)3   0.01318    0.03039   0.434
as.factor(Hour_ENTRY)4   0.03567    0.03020   1.181
as.factor(Hour_ENTRY)5  -0.05718    0.02930  -1.952
as.factor(Hour_ENTRY)6  -0.31247    0.02804 -11.142
as.factor(Hour_ENTRY)7  -0.22695    0.02820  -8.049
as.factor(Hour_ENTRY)8  -0.22237    0.02835  -7.844
as.factor(Hour_ENTRY)9  -0.22132    0.02837  -7.802
as.factor(Hour_ENTRY)10 -0.12769    0.02886  -4.425
as.factor(Hour_ENTRY)11 -0.17002    0.02884  -5.895
as.factor(Hour_ENTRY)12 -0.28072    0.02846  -9.862
as.factor(Hour_ENTRY)13 -0.36267    0.02825 -12.838
as.factor(Hour_ENTRY)14 -0.51274    0.02785 -18.408
as.factor(Hour_ENTRY)15 -0.39592    0.02800 -14.142
as.factor(Hour_ENTRY)16 -0.33209    0.02809 -11.824
as.factor(Hour_ENTRY)17 -0.20516    0.02851  -7.197
as.factor(Hour_ENTRY)18 -0.12564    0.02911  -4.317
as.factor(Hour_ENTRY)19 -0.07057    0.02934  -2.406
as.factor(Hour_ENTRY)20 -0.05832    0.02972  -1.963
as.factor(Hour_ENTRY)21 -0.04603    0.03017  -1.526
as.factor(Hour_ENTRY)22 -0.01874    0.03045  -0.616
as.factor(Hour_ENTRY)23 -0.01083    0.03060  -0.354

Correlation matrix not shown by default, as p = 24 > 12.
Use print(x, correlation=TRUE)  or
    vcov(x)        if you need it
## modelo sin pedigree modelo original efectos directos e indirectos

reduced_model_Follower.pe <- lmer(
  L_time ~ as.factor(Hour_ENTRY) +  (1 | ID) +  (1 | Follower_ID) + (1 | Social_Group),
  data = data_PIC_pvalues_ped1
)


##

reduced_model_Follower <- pedigreemm(
  L_time ~ as.factor(Hour_ENTRY) +  (1 | ID) +  (1 | Follower_ID) + (1 | Social_Group),
  data = data_PIC_pvalues,
  pedigree = list(ID = d, Follower_ID = d)
)


## modelo sin pedigree modelo original efectos directos e indirectos

reduced_model_Follower.pe <- lmer(
  L_time ~ as.factor(Hour_ENTRY) +  (1 | ID) +  (1 | Follower_ID) + (1 | Social_Group),
  data = data_PIC_pvalues
)

## full model usando lmer y sin ambiente permanent del follower
fm.lmer <- lmer(
  L_time ~ as.factor(Hour_ENTRY) + (1 | ID) + (1 | Follower_ID) + (1 | IDpe) + (1 | Social_Group),
   data = data_PIC_pvalues_ped1
   )
Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
Model failed to converge with max|grad| = 0.0559996 (tol = 0.002, component 1)
Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, : Model is nearly unidentifiable: large eigenvalue ratio
 - Rescale variables?
## full model usando lmer y sin ambiente permanente del id
fm.lmer2 <- lmer(
  L_time ~ as.factor(Hour_ENTRY) + (1 | ID) + (1 | Follower_ID) + (1 | Follower.pe) + (1 | Social_Group), 
  data = data_PIC_pvalues_ped1
    )
Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
Model failed to converge with max|grad| = 0.0223521 (tol = 0.002, component 1)
# Imprimir los modelos
summary(fm2)
Linear mixed model fit by REML ['lmerpedigreemm']
Formula: L_time ~ as.factor(Hour_ENTRY) + (1 | ID) + (1 | Follower_ID) +  
    (1 | IDpe) + (1 | Follower.pe) + (1 | Social_Group)
   Data: data_PIC_pvalues_ped1

REML criterion at convergence: 386274.2

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-4.5254 -0.2866  0.2714  0.6221  2.7755 

Random effects:
 Groups       Name        Variance Std.Dev.
 ID           (Intercept) 0.025220 0.15881 
 Follower_ID  (Intercept) 0.007685 0.08766 
 IDpe         (Intercept) 0.066680 0.25822 
 Follower.pe  (Intercept) 0.044025 0.20982 
 Social_Group (Intercept) 0.024964 0.15800 
 Residual                 1.685723 1.29835 
Number of obs: 114210, groups:  
ID, 548; Follower_ID, 548; IDpe, 548; Follower.pe, 548; Social_Group, 36

Fixed effects:
                        Estimate Std. Error t value
(Intercept)              6.98983    0.04313 162.059
as.factor(Hour_ENTRY)1   0.04022    0.03074   1.308
as.factor(Hour_ENTRY)2   0.02362    0.03059   0.772
as.factor(Hour_ENTRY)3   0.01323    0.03039   0.436
as.factor(Hour_ENTRY)4   0.03578    0.03020   1.185
as.factor(Hour_ENTRY)5  -0.05734    0.02930  -1.957
as.factor(Hour_ENTRY)6  -0.31315    0.02804 -11.167
as.factor(Hour_ENTRY)7  -0.22732    0.02819  -8.063
as.factor(Hour_ENTRY)8  -0.22273    0.02835  -7.857
as.factor(Hour_ENTRY)9  -0.22162    0.02836  -7.814
as.factor(Hour_ENTRY)10 -0.12841    0.02885  -4.451
as.factor(Hour_ENTRY)11 -0.17081    0.02884  -5.923
as.factor(Hour_ENTRY)12 -0.28070    0.02846  -9.863
as.factor(Hour_ENTRY)13 -0.36306    0.02825 -12.854
as.factor(Hour_ENTRY)14 -0.51299    0.02785 -18.419
as.factor(Hour_ENTRY)15 -0.39654    0.02799 -14.165
as.factor(Hour_ENTRY)16 -0.33297    0.02809 -11.856
as.factor(Hour_ENTRY)17 -0.20582    0.02851  -7.220
as.factor(Hour_ENTRY)18 -0.12654    0.02910  -4.348
as.factor(Hour_ENTRY)19 -0.07143    0.02933  -2.435
as.factor(Hour_ENTRY)20 -0.05879    0.02972  -1.978
as.factor(Hour_ENTRY)21 -0.04632    0.03017  -1.535
as.factor(Hour_ENTRY)22 -0.01909    0.03045  -0.627
as.factor(Hour_ENTRY)23 -0.01101    0.03060  -0.360

Correlation matrix not shown by default, as p = 24 > 12.
Use print(x, correlation=TRUE)  or
    vcov(x)        if you need it
summary(reduced_model_ID)
Linear mixed model fit by REML ['lmerpedigreemm']
Formula: L_time ~ as.factor(Hour_ENTRY) + (1 | ID) + (1 | Social_Group)
   Data: data_PIC_pvalues_ped1

REML criterion at convergence: 388611.6

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-4.2781 -0.2863  0.2858  0.6297  2.6203 

Random effects:
 Groups       Name        Variance Std.Dev.
 ID           (Intercept) 0.12773  0.3574  
 Social_Group (Intercept) 0.02593  0.1610  
 Residual                 1.73549  1.3174  
Number of obs: 114210, groups:  ID, 548; Social_Group, 36

Fixed effects:
                         Estimate Std. Error t value
(Intercept)              7.027783   0.052603 133.602
as.factor(Hour_ENTRY)1   0.036812   0.031131   1.182
as.factor(Hour_ENTRY)2   0.021838   0.030969   0.705
as.factor(Hour_ENTRY)3   0.007048   0.030738   0.229
as.factor(Hour_ENTRY)4   0.031076   0.030503   1.019
as.factor(Hour_ENTRY)5  -0.073211   0.029544  -2.478
as.factor(Hour_ENTRY)6  -0.347862   0.028202 -12.335
as.factor(Hour_ENTRY)7  -0.264917   0.028360  -9.341
as.factor(Hour_ENTRY)8  -0.255256   0.028524  -8.949
as.factor(Hour_ENTRY)9  -0.259587   0.028546  -9.094
as.factor(Hour_ENTRY)10 -0.166096   0.029020  -5.724
as.factor(Hour_ENTRY)11 -0.217709   0.028975  -7.514
as.factor(Hour_ENTRY)12 -0.340686   0.028584 -11.919
as.factor(Hour_ENTRY)13 -0.434149   0.028335 -15.322
as.factor(Hour_ENTRY)14 -0.582142   0.027922 -20.849
as.factor(Hour_ENTRY)15 -0.456461   0.028069 -16.262
as.factor(Hour_ENTRY)16 -0.377217   0.028210 -13.372
as.factor(Hour_ENTRY)17 -0.228318   0.028696  -7.957
as.factor(Hour_ENTRY)18 -0.147659   0.029350  -5.031
as.factor(Hour_ENTRY)19 -0.091502   0.029625  -3.089
as.factor(Hour_ENTRY)20 -0.071099   0.030043  -2.367
as.factor(Hour_ENTRY)21 -0.053829   0.030526  -1.763
as.factor(Hour_ENTRY)22 -0.025041   0.030824  -0.812
as.factor(Hour_ENTRY)23 -0.016426   0.030982  -0.530

Correlation matrix not shown by default, as p = 24 > 12.
Use print(x, correlation=TRUE)  or
    vcov(x)        if you need it
summary(reduced_model_IDpe)
Linear mixed model fit by REML ['lmerpedigreemm']
Formula: L_time ~ as.factor(Hour_ENTRY) + (1 | ID) + (1 | IDpe) + (1 |  
    Social_Group)
   Data: data_PIC_pvalues_ped1

REML criterion at convergence: 388585.9

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-4.2874 -0.2866  0.2860  0.6300  2.6211 

Random effects:
 Groups       Name        Variance Std.Dev.
 ID           (Intercept) 0.02627  0.1621  
 IDpe         (Intercept) 0.06707  0.2590  
 Social_Group (Intercept) 0.02970  0.1723  
 Residual                 1.73542  1.3174  
Number of obs: 114210, groups:  ID, 548; IDpe, 548; Social_Group, 36

Fixed effects:
                         Estimate Std. Error t value
(Intercept)              7.016809   0.042600 164.712
as.factor(Hour_ENTRY)1   0.036514   0.031130   1.173
as.factor(Hour_ENTRY)2   0.021523   0.030969   0.695
as.factor(Hour_ENTRY)3   0.006791   0.030738   0.221
as.factor(Hour_ENTRY)4   0.030983   0.030503   1.016
as.factor(Hour_ENTRY)5  -0.073353   0.029544  -2.483
as.factor(Hour_ENTRY)6  -0.347895   0.028201 -12.336
as.factor(Hour_ENTRY)7  -0.264929   0.028359  -9.342
as.factor(Hour_ENTRY)8  -0.255182   0.028524  -8.946
as.factor(Hour_ENTRY)9  -0.259550   0.028546  -9.092
as.factor(Hour_ENTRY)10 -0.165934   0.029019  -5.718
as.factor(Hour_ENTRY)11 -0.217798   0.028974  -7.517
as.factor(Hour_ENTRY)12 -0.340229   0.028584 -11.903
as.factor(Hour_ENTRY)13 -0.433719   0.028334 -15.307
as.factor(Hour_ENTRY)14 -0.581989   0.027921 -20.844
as.factor(Hour_ENTRY)15 -0.456343   0.028069 -16.258
as.factor(Hour_ENTRY)16 -0.377625   0.028210 -13.386
as.factor(Hour_ENTRY)17 -0.229053   0.028696  -7.982
as.factor(Hour_ENTRY)18 -0.148303   0.029350  -5.053
as.factor(Hour_ENTRY)19 -0.092012   0.029625  -3.106
as.factor(Hour_ENTRY)20 -0.071361   0.030043  -2.375
as.factor(Hour_ENTRY)21 -0.054179   0.030526  -1.775
as.factor(Hour_ENTRY)22 -0.025068   0.030824  -0.813
as.factor(Hour_ENTRY)23 -0.016638   0.030982  -0.537

Correlation matrix not shown by default, as p = 24 > 12.
Use print(x, correlation=TRUE)  or
    vcov(x)        if you need it
summary(reduced_model_Follower)
Linear mixed model fit by REML ['lmerpedigreemm']
Formula: L_time ~ as.factor(Hour_ENTRY) + (1 | ID) + (1 | Follower_ID) +  
    (1 | Social_Group)
   Data: data_PIC_pvalues

REML criterion at convergence: 386341.1

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-4.4963 -0.2861  0.2717  0.6221  2.7629 

Random effects:
 Groups       Name        Variance Std.Dev.
 ID           (Intercept) 0.12626  0.3553  
 Follower_ID  (Intercept) 0.07404  0.2721  
 Social_Group (Intercept) 0.01866  0.1366  
 Residual                 1.68594  1.2984  
Number of obs: 114210, groups:  ID, 548; Follower_ID, 548; Social_Group, 36

Fixed effects:
                        Estimate Std. Error t value
(Intercept)              6.99967    0.05853 119.592
as.factor(Hour_ENTRY)1   0.04047    0.03074   1.316
as.factor(Hour_ENTRY)2   0.02375    0.03059   0.776
as.factor(Hour_ENTRY)3   0.01318    0.03039   0.434
as.factor(Hour_ENTRY)4   0.03567    0.03020   1.181
as.factor(Hour_ENTRY)5  -0.05718    0.02930  -1.952
as.factor(Hour_ENTRY)6  -0.31247    0.02804 -11.142
as.factor(Hour_ENTRY)7  -0.22695    0.02820  -8.049
as.factor(Hour_ENTRY)8  -0.22237    0.02835  -7.844
as.factor(Hour_ENTRY)9  -0.22132    0.02837  -7.802
as.factor(Hour_ENTRY)10 -0.12769    0.02886  -4.425
as.factor(Hour_ENTRY)11 -0.17002    0.02884  -5.895
as.factor(Hour_ENTRY)12 -0.28072    0.02846  -9.862
as.factor(Hour_ENTRY)13 -0.36267    0.02825 -12.838
as.factor(Hour_ENTRY)14 -0.51274    0.02785 -18.408
as.factor(Hour_ENTRY)15 -0.39592    0.02800 -14.142
as.factor(Hour_ENTRY)16 -0.33209    0.02809 -11.824
as.factor(Hour_ENTRY)17 -0.20516    0.02851  -7.197
as.factor(Hour_ENTRY)18 -0.12564    0.02911  -4.317
as.factor(Hour_ENTRY)19 -0.07057    0.02934  -2.406
as.factor(Hour_ENTRY)20 -0.05832    0.02972  -1.963
as.factor(Hour_ENTRY)21 -0.04603    0.03017  -1.526
as.factor(Hour_ENTRY)22 -0.01874    0.03045  -0.616
as.factor(Hour_ENTRY)23 -0.01083    0.03060  -0.354

Correlation matrix not shown by default, as p = 24 > 12.
Use print(x, correlation=TRUE)  or
    vcov(x)        if you need it
summary(reduced_model_Follower.pe)
Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula: L_time ~ as.factor(Hour_ENTRY) + (1 | ID) + (1 | Follower_ID) +  
    (1 | Social_Group)
   Data: data_PIC_pvalues

REML criterion at convergence: 386292.9

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-4.5289 -0.2869  0.2713  0.6219  2.7759 

Random effects:
 Groups       Name        Variance Std.Dev.
 ID           (Intercept) 0.08969  0.2995  
 Follower_ID  (Intercept) 0.05122  0.2263  
 Social_Group (Intercept) 0.02810  0.1676  
 Residual                 1.68573  1.2984  
Number of obs: 114210, groups:  ID, 548; Follower_ID, 548; Social_Group, 36

Fixed effects:
                          Estimate Std. Error         df t value Pr(>|t|)    
(Intercept)              6.972e+00  3.896e-02  7.251e+01 178.942  < 2e-16 ***
as.factor(Hour_ENTRY)1   4.005e-02  3.074e-02  1.134e+05   1.303   0.1927    
as.factor(Hour_ENTRY)2   2.342e-02  3.059e-02  1.134e+05   0.766   0.4439    
as.factor(Hour_ENTRY)3   1.304e-02  3.039e-02  1.134e+05   0.429   0.6677    
as.factor(Hour_ENTRY)4   3.552e-02  3.020e-02  1.136e+05   1.176   0.2396    
as.factor(Hour_ENTRY)5  -5.768e-02  2.930e-02  1.137e+05  -1.969   0.0490 *  
as.factor(Hour_ENTRY)6  -3.139e-01  2.804e-02  1.139e+05 -11.196  < 2e-16 ***
as.factor(Hour_ENTRY)7  -2.280e-01  2.819e-02  1.139e+05  -8.087 6.16e-16 ***
as.factor(Hour_ENTRY)8  -2.233e-01  2.835e-02  1.139e+05  -7.876 3.40e-15 ***
as.factor(Hour_ENTRY)9  -2.222e-01  2.836e-02  1.139e+05  -7.833 4.80e-15 ***
as.factor(Hour_ENTRY)10 -1.289e-01  2.885e-02  1.139e+05  -4.468 7.89e-06 ***
as.factor(Hour_ENTRY)11 -1.714e-01  2.884e-02  1.140e+05  -5.943 2.80e-09 ***
as.factor(Hour_ENTRY)12 -2.810e-01  2.846e-02  1.140e+05  -9.874  < 2e-16 ***
as.factor(Hour_ENTRY)13 -3.634e-01  2.825e-02  1.140e+05 -12.865  < 2e-16 ***
as.factor(Hour_ENTRY)14 -5.135e-01  2.785e-02  1.141e+05 -18.437  < 2e-16 ***
as.factor(Hour_ENTRY)15 -3.972e-01  2.799e-02  1.141e+05 -14.189  < 2e-16 ***
as.factor(Hour_ENTRY)16 -3.337e-01  2.809e-02  1.140e+05 -11.884  < 2e-16 ***
as.factor(Hour_ENTRY)17 -2.068e-01  2.851e-02  1.139e+05  -7.253 4.09e-13 ***
as.factor(Hour_ENTRY)18 -1.276e-01  2.910e-02  1.138e+05  -4.383 1.17e-05 ***
as.factor(Hour_ENTRY)19 -7.231e-02  2.933e-02  1.137e+05  -2.465   0.0137 *  
as.factor(Hour_ENTRY)20 -5.936e-02  2.972e-02  1.135e+05  -1.998   0.0458 *  
as.factor(Hour_ENTRY)21 -4.678e-02  3.017e-02  1.135e+05  -1.550   0.1210    
as.factor(Hour_ENTRY)22 -1.932e-02  3.045e-02  1.134e+05  -0.635   0.5257    
as.factor(Hour_ENTRY)23 -1.130e-02  3.060e-02  1.134e+05  -0.369   0.7119    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Correlation matrix not shown by default, as p = 24 > 12.
Use print(x, correlation=TRUE)  or
    vcov(x)        if you need it
summary(reduced_model_Follower)
Linear mixed model fit by REML ['lmerpedigreemm']
Formula: L_time ~ as.factor(Hour_ENTRY) + (1 | ID) + (1 | Follower_ID) +  
    (1 | Social_Group)
   Data: data_PIC_pvalues

REML criterion at convergence: 386341.1

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-4.4963 -0.2861  0.2717  0.6221  2.7629 

Random effects:
 Groups       Name        Variance Std.Dev.
 ID           (Intercept) 0.12626  0.3553  
 Follower_ID  (Intercept) 0.07404  0.2721  
 Social_Group (Intercept) 0.01866  0.1366  
 Residual                 1.68594  1.2984  
Number of obs: 114210, groups:  ID, 548; Follower_ID, 548; Social_Group, 36

Fixed effects:
                        Estimate Std. Error t value
(Intercept)              6.99967    0.05853 119.592
as.factor(Hour_ENTRY)1   0.04047    0.03074   1.316
as.factor(Hour_ENTRY)2   0.02375    0.03059   0.776
as.factor(Hour_ENTRY)3   0.01318    0.03039   0.434
as.factor(Hour_ENTRY)4   0.03567    0.03020   1.181
as.factor(Hour_ENTRY)5  -0.05718    0.02930  -1.952
as.factor(Hour_ENTRY)6  -0.31247    0.02804 -11.142
as.factor(Hour_ENTRY)7  -0.22695    0.02820  -8.049
as.factor(Hour_ENTRY)8  -0.22237    0.02835  -7.844
as.factor(Hour_ENTRY)9  -0.22132    0.02837  -7.802
as.factor(Hour_ENTRY)10 -0.12769    0.02886  -4.425
as.factor(Hour_ENTRY)11 -0.17002    0.02884  -5.895
as.factor(Hour_ENTRY)12 -0.28072    0.02846  -9.862
as.factor(Hour_ENTRY)13 -0.36267    0.02825 -12.838
as.factor(Hour_ENTRY)14 -0.51274    0.02785 -18.408
as.factor(Hour_ENTRY)15 -0.39592    0.02800 -14.142
as.factor(Hour_ENTRY)16 -0.33209    0.02809 -11.824
as.factor(Hour_ENTRY)17 -0.20516    0.02851  -7.197
as.factor(Hour_ENTRY)18 -0.12564    0.02911  -4.317
as.factor(Hour_ENTRY)19 -0.07057    0.02934  -2.406
as.factor(Hour_ENTRY)20 -0.05832    0.02972  -1.963
as.factor(Hour_ENTRY)21 -0.04603    0.03017  -1.526
as.factor(Hour_ENTRY)22 -0.01874    0.03045  -0.616
as.factor(Hour_ENTRY)23 -0.01083    0.03060  -0.354

Correlation matrix not shown by default, as p = 24 > 12.
Use print(x, correlation=TRUE)  or
    vcov(x)        if you need it
summary(reduced_model_Follower.pe)
Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula: L_time ~ as.factor(Hour_ENTRY) + (1 | ID) + (1 | Follower_ID) +  
    (1 | Social_Group)
   Data: data_PIC_pvalues

REML criterion at convergence: 386292.9

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-4.5289 -0.2869  0.2713  0.6219  2.7759 

Random effects:
 Groups       Name        Variance Std.Dev.
 ID           (Intercept) 0.08969  0.2995  
 Follower_ID  (Intercept) 0.05122  0.2263  
 Social_Group (Intercept) 0.02810  0.1676  
 Residual                 1.68573  1.2984  
Number of obs: 114210, groups:  ID, 548; Follower_ID, 548; Social_Group, 36

Fixed effects:
                          Estimate Std. Error         df t value Pr(>|t|)    
(Intercept)              6.972e+00  3.896e-02  7.251e+01 178.942  < 2e-16 ***
as.factor(Hour_ENTRY)1   4.005e-02  3.074e-02  1.134e+05   1.303   0.1927    
as.factor(Hour_ENTRY)2   2.342e-02  3.059e-02  1.134e+05   0.766   0.4439    
as.factor(Hour_ENTRY)3   1.304e-02  3.039e-02  1.134e+05   0.429   0.6677    
as.factor(Hour_ENTRY)4   3.552e-02  3.020e-02  1.136e+05   1.176   0.2396    
as.factor(Hour_ENTRY)5  -5.768e-02  2.930e-02  1.137e+05  -1.969   0.0490 *  
as.factor(Hour_ENTRY)6  -3.139e-01  2.804e-02  1.139e+05 -11.196  < 2e-16 ***
as.factor(Hour_ENTRY)7  -2.280e-01  2.819e-02  1.139e+05  -8.087 6.16e-16 ***
as.factor(Hour_ENTRY)8  -2.233e-01  2.835e-02  1.139e+05  -7.876 3.40e-15 ***
as.factor(Hour_ENTRY)9  -2.222e-01  2.836e-02  1.139e+05  -7.833 4.80e-15 ***
as.factor(Hour_ENTRY)10 -1.289e-01  2.885e-02  1.139e+05  -4.468 7.89e-06 ***
as.factor(Hour_ENTRY)11 -1.714e-01  2.884e-02  1.140e+05  -5.943 2.80e-09 ***
as.factor(Hour_ENTRY)12 -2.810e-01  2.846e-02  1.140e+05  -9.874  < 2e-16 ***
as.factor(Hour_ENTRY)13 -3.634e-01  2.825e-02  1.140e+05 -12.865  < 2e-16 ***
as.factor(Hour_ENTRY)14 -5.135e-01  2.785e-02  1.141e+05 -18.437  < 2e-16 ***
as.factor(Hour_ENTRY)15 -3.972e-01  2.799e-02  1.141e+05 -14.189  < 2e-16 ***
as.factor(Hour_ENTRY)16 -3.337e-01  2.809e-02  1.140e+05 -11.884  < 2e-16 ***
as.factor(Hour_ENTRY)17 -2.068e-01  2.851e-02  1.139e+05  -7.253 4.09e-13 ***
as.factor(Hour_ENTRY)18 -1.276e-01  2.910e-02  1.138e+05  -4.383 1.17e-05 ***
as.factor(Hour_ENTRY)19 -7.231e-02  2.933e-02  1.137e+05  -2.465   0.0137 *  
as.factor(Hour_ENTRY)20 -5.936e-02  2.972e-02  1.135e+05  -1.998   0.0458 *  
as.factor(Hour_ENTRY)21 -4.678e-02  3.017e-02  1.135e+05  -1.550   0.1210    
as.factor(Hour_ENTRY)22 -1.932e-02  3.045e-02  1.134e+05  -0.635   0.5257    
as.factor(Hour_ENTRY)23 -1.130e-02  3.060e-02  1.134e+05  -0.369   0.7119    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Correlation matrix not shown by default, as p = 24 > 12.
Use print(x, correlation=TRUE)  or
    vcov(x)        if you need it
summary(fm.lmer)
Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula: L_time ~ as.factor(Hour_ENTRY) + (1 | ID) + (1 | Follower_ID) +  
    (1 | IDpe) + (1 | Social_Group)
   Data: data_PIC_pvalues_ped1

REML criterion at convergence: 386292.9

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-4.5289 -0.2869  0.2713  0.6219  2.7759 

Random effects:
 Groups       Name        Variance Std.Dev.
 ID           (Intercept) 0.01034  0.1017  
 Follower_ID  (Intercept) 0.05122  0.2263  
 IDpe         (Intercept) 0.07934  0.2817  
 Social_Group (Intercept) 0.02810  0.1676  
 Residual                 1.68573  1.2984  
Number of obs: 114210, groups:  
ID, 548; Follower_ID, 548; IDpe, 548; Social_Group, 36

Fixed effects:
                          Estimate Std. Error         df t value Pr(>|t|)    
(Intercept)              6.972e+00  3.896e-02  7.250e+01 178.941  < 2e-16 ***
as.factor(Hour_ENTRY)1   4.005e-02  3.074e-02  1.134e+05   1.303   0.1927    
as.factor(Hour_ENTRY)2   2.342e-02  3.059e-02  1.134e+05   0.766   0.4439    
as.factor(Hour_ENTRY)3   1.304e-02  3.039e-02  1.134e+05   0.429   0.6677    
as.factor(Hour_ENTRY)4   3.552e-02  3.020e-02  1.136e+05   1.176   0.2396    
as.factor(Hour_ENTRY)5  -5.768e-02  2.930e-02  1.137e+05  -1.969   0.0490 *  
as.factor(Hour_ENTRY)6  -3.139e-01  2.804e-02  1.139e+05 -11.196  < 2e-16 ***
as.factor(Hour_ENTRY)7  -2.280e-01  2.819e-02  1.139e+05  -8.087 6.16e-16 ***
as.factor(Hour_ENTRY)8  -2.233e-01  2.835e-02  1.139e+05  -7.876 3.40e-15 ***
as.factor(Hour_ENTRY)9  -2.222e-01  2.836e-02  1.139e+05  -7.833 4.80e-15 ***
as.factor(Hour_ENTRY)10 -1.289e-01  2.885e-02  1.139e+05  -4.468 7.89e-06 ***
as.factor(Hour_ENTRY)11 -1.714e-01  2.884e-02  1.140e+05  -5.943 2.80e-09 ***
as.factor(Hour_ENTRY)12 -2.810e-01  2.846e-02  1.140e+05  -9.874  < 2e-16 ***
as.factor(Hour_ENTRY)13 -3.634e-01  2.825e-02  1.140e+05 -12.865  < 2e-16 ***
as.factor(Hour_ENTRY)14 -5.135e-01  2.785e-02  1.141e+05 -18.437  < 2e-16 ***
as.factor(Hour_ENTRY)15 -3.972e-01  2.799e-02  1.141e+05 -14.189  < 2e-16 ***
as.factor(Hour_ENTRY)16 -3.337e-01  2.809e-02  1.140e+05 -11.884  < 2e-16 ***
as.factor(Hour_ENTRY)17 -2.068e-01  2.851e-02  1.139e+05  -7.253 4.09e-13 ***
as.factor(Hour_ENTRY)18 -1.276e-01  2.910e-02  1.138e+05  -4.383 1.17e-05 ***
as.factor(Hour_ENTRY)19 -7.231e-02  2.933e-02  1.137e+05  -2.465   0.0137 *  
as.factor(Hour_ENTRY)20 -5.936e-02  2.972e-02  1.135e+05  -1.998   0.0458 *  
as.factor(Hour_ENTRY)21 -4.678e-02  3.017e-02  1.135e+05  -1.550   0.1210    
as.factor(Hour_ENTRY)22 -1.932e-02  3.045e-02  1.134e+05  -0.635   0.5257    
as.factor(Hour_ENTRY)23 -1.130e-02  3.060e-02  1.134e+05  -0.369   0.7119    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Correlation matrix not shown by default, as p = 24 > 12.
Use print(x, correlation=TRUE)  or
    vcov(x)        if you need it
optimizer (nloptwrap) convergence code: 0 (OK)
Model failed to converge with max|grad| = 0.0559996 (tol = 0.002, component 1)
Model is nearly unidentifiable: large eigenvalue ratio
 - Rescale variables?
summary(fm.lmer2)
Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula: L_time ~ as.factor(Hour_ENTRY) + (1 | ID) + (1 | Follower_ID) +  
    (1 | Follower.pe) + (1 | Social_Group)
   Data: data_PIC_pvalues_ped1

REML criterion at convergence: 386292.9

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-4.5289 -0.2869  0.2713  0.6219  2.7759 

Random effects:
 Groups       Name        Variance Std.Dev.
 ID           (Intercept) 0.089687 0.29948 
 Follower_ID  (Intercept) 0.002384 0.04883 
 Follower.pe  (Intercept) 0.048835 0.22099 
 Social_Group (Intercept) 0.028115 0.16767 
 Residual                 1.685734 1.29836 
Number of obs: 114210, groups:  
ID, 548; Follower_ID, 548; Follower.pe, 548; Social_Group, 36

Fixed effects:
                          Estimate Std. Error         df t value Pr(>|t|)    
(Intercept)              6.972e+00  3.897e-02  7.247e+01 178.924  < 2e-16 ***
as.factor(Hour_ENTRY)1   4.005e-02  3.074e-02  1.134e+05   1.303   0.1927    
as.factor(Hour_ENTRY)2   2.342e-02  3.059e-02  1.134e+05   0.766   0.4439    
as.factor(Hour_ENTRY)3   1.304e-02  3.039e-02  1.134e+05   0.429   0.6677    
as.factor(Hour_ENTRY)4   3.552e-02  3.020e-02  1.136e+05   1.176   0.2396    
as.factor(Hour_ENTRY)5  -5.768e-02  2.930e-02  1.137e+05  -1.969   0.0490 *  
as.factor(Hour_ENTRY)6  -3.139e-01  2.804e-02  1.139e+05 -11.196  < 2e-16 ***
as.factor(Hour_ENTRY)7  -2.280e-01  2.819e-02  1.139e+05  -8.087 6.16e-16 ***
as.factor(Hour_ENTRY)8  -2.233e-01  2.835e-02  1.139e+05  -7.876 3.40e-15 ***
as.factor(Hour_ENTRY)9  -2.222e-01  2.836e-02  1.139e+05  -7.833 4.80e-15 ***
as.factor(Hour_ENTRY)10 -1.289e-01  2.885e-02  1.139e+05  -4.468 7.89e-06 ***
as.factor(Hour_ENTRY)11 -1.714e-01  2.884e-02  1.140e+05  -5.943 2.80e-09 ***
as.factor(Hour_ENTRY)12 -2.810e-01  2.846e-02  1.140e+05  -9.874  < 2e-16 ***
as.factor(Hour_ENTRY)13 -3.634e-01  2.825e-02  1.140e+05 -12.865  < 2e-16 ***
as.factor(Hour_ENTRY)14 -5.135e-01  2.785e-02  1.141e+05 -18.437  < 2e-16 ***
as.factor(Hour_ENTRY)15 -3.972e-01  2.799e-02  1.141e+05 -14.189  < 2e-16 ***
as.factor(Hour_ENTRY)16 -3.337e-01  2.809e-02  1.140e+05 -11.884  < 2e-16 ***
as.factor(Hour_ENTRY)17 -2.068e-01  2.851e-02  1.139e+05  -7.253 4.09e-13 ***
as.factor(Hour_ENTRY)18 -1.276e-01  2.910e-02  1.138e+05  -4.383 1.17e-05 ***
as.factor(Hour_ENTRY)19 -7.231e-02  2.933e-02  1.137e+05  -2.465   0.0137 *  
as.factor(Hour_ENTRY)20 -5.936e-02  2.972e-02  1.135e+05  -1.998   0.0458 *  
as.factor(Hour_ENTRY)21 -4.678e-02  3.017e-02  1.135e+05  -1.550   0.1210    
as.factor(Hour_ENTRY)22 -1.932e-02  3.045e-02  1.134e+05  -0.635   0.5257    
as.factor(Hour_ENTRY)23 -1.130e-02  3.060e-02  1.134e+05  -0.369   0.7119    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Correlation matrix not shown by default, as p = 24 > 12.
Use print(x, correlation=TRUE)  or
    vcov(x)        if you need it
optimizer (nloptwrap) convergence code: 0 (OK)
Model failed to converge with max|grad| = 0.0223521 (tol = 0.002, component 1)
print(VarCorr(reduced_model_Follower.pe), comp = "Variance")
 Groups       Name        Variance
 ID           (Intercept) 0.089685
 Follower_ID  (Intercept) 0.051219
 Social_Group (Intercept) 0.028104
 Residual                 1.685735
AIC(reduced_model_Follower.pe)
[1] 386348.9
AIC(reduced_model_Follower)
[1] 386397.1
AIC(fm2)
[1] 386334.2
AIC(reduced_model_ID)
[1] 388665.6
AIC(reduced_model_IDpe)
[1] 388641.9

Variance componets, REML, AIC table

#| warning: true
#| echo: true


results_table <- data.frame(
  Model = c("fm2", "reduced_model_ID", "reduced_model_IDpe", "reduced_model_Follower", "reduced_model_Follower.pe", "fm.lmer", "fm.lmer2"),
  v_ID = numeric(7),
  v_Follower_ID = numeric(7),
  v_IDpe = numeric(7),
  v_Follower_pe = numeric(7), 
  v_Social_Group = numeric(7),
  REML_Crit = numeric(7),
  AIC = numeric(7)
)

calculate_reml_aic <- function(model) {
  reml <- -2 * logLik(model)[1]
  aic <- AIC(model)
  return(c(reml, aic))
}

for (i in 1:7) {
  model_name <- results_table$Model[i]
  if (exists(model_name)) {
    model <- get(model_name)

    variance_components <- as.data.frame(VarCorr(model))
    results_table[i, 2:6] <- rep(NA, 5)
    
    terms <- c("ID", "Follower_ID", "IDpe", "Follower.pe", "Social_Group")
    for (term in terms) {
      if (term %in% variance_components$grp) {
        results_table[i, paste0("v_", term)] <- variance_components[variance_components$grp == term, "vcov"]
      }
    }

    results_table[i, 7:8] <- calculate_reml_aic(model)
  } else {
    warning(paste("Model", model_name, "not found. Skipping..."))
  }
}


results_table$v_Follower_pe <- NULL

names(results_table)[names(results_table) == "v_Follower.pe"] <- "v_Follower_pe"

print(results_table)
                      Model       v_ID v_Follower_ID     v_IDpe v_Social_Group
1                       fm2 0.02522017   0.007684705 0.06667973     0.02496378
2          reduced_model_ID 0.12772712            NA         NA     0.02592884
3        reduced_model_IDpe 0.02627113            NA 0.06707291     0.02969518
4    reduced_model_Follower 0.12625559   0.074042627         NA     0.01865794
5 reduced_model_Follower.pe 0.08968540   0.051219296         NA     0.02810361
6                   fm.lmer 0.01034091   0.051219299 0.07934482     0.02810431
7                  fm.lmer2 0.08968657   0.002383900         NA     0.02811453
  REML_Crit      AIC v_Follower_pe
1  386274.2 386334.2    0.04402540
2  388611.6 388665.6            NA
3  388585.9 388641.9            NA
4  386341.1 386397.1            NA
5  386292.9 386348.9            NA
6  386292.9 386350.9            NA
7  386292.9 386350.9    0.04883549