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" ),
EXIT_DATE = as_date (mdy_hm (EXIT_TIME, tz = "UTC" )),
EXIT = mdy_hm (EXIT_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_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 ())
head (data_PIC.arrange)
# A tibble: 6 x 22
# 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 12 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>, EXIT_DATE <date>, EXIT <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
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 - EXIT, unit= "secs" ))%>%
filter (time_between < 36000 ,time_between>= 0 )
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: 113,056 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 113,046 more rows
[1] "grouped_df" "tbl_df" "tbl" "data.frame"
data_PIC_pvalues_morethan_240 <- as.numeric (data_PIC$ time_between)
data_PIC_pvalues_morethan_240 <- filter (data_PIC, time_between > 240 ) %>%
mutate (TIME_FEEDER = as.numeric (STAY_IN))
dim (data_PIC_pvalues_morethan_240)
summary (data_PIC_pvalues_morethan_240$ TIME_FEEDER)
Min. 1st Qu. Median Mean 3rd Qu. Max.
5 597 1247 1373 1964 7200
head (data_PIC_pvalues_morethan_240)
# A tibble: 6 x 28
# 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~ 469
2 97887847 65 88291968 9.34e7 7.90e7 B0111 774 3/15/2023~ 3/15/202~ 7
3 97887847 65 88291968 9.34e7 7.90e7 B0111 774 3/15/2023~ 3/15/202~ 24
4 97900489 65 88291968 9.18e7 7.90e7 B0111 774 3/15/2023~ 3/15/202~ 605
5 97900600 65 88153118 9.22e7 7.90e7 B0111 774 3/15/2023~ 3/15/202~ 313
6 97887845 65 88291968 9.34e7 7.90e7 B0111 774 3/15/2023~ 3/15/202~ 199
# i 18 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>, EXIT_DATE <date>, EXIT <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_pvalues240 <- data_PIC_pvalues_morethan_240 %>%
mutate (L_time = log (TIME_FEEDER))
head (data_PIC_pvalues240)
# A tibble: 6 x 29
# 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~ 469
2 97887847 65 88291968 9.34e7 7.90e7 B0111 774 3/15/2023~ 3/15/202~ 7
3 97887847 65 88291968 9.34e7 7.90e7 B0111 774 3/15/2023~ 3/15/202~ 24
4 97900489 65 88291968 9.18e7 7.90e7 B0111 774 3/15/2023~ 3/15/202~ 605
5 97900600 65 88153118 9.22e7 7.90e7 B0111 774 3/15/2023~ 3/15/202~ 313
6 97887845 65 88291968 9.34e7 7.90e7 B0111 774 3/15/2023~ 3/15/202~ 199
# i 19 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>, EXIT_DATE <date>, EXIT <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>,
# L_time <dbl>
umbral <- 240
total_counts3 <- data_PIC_pvalues240 %>%
mutate (time_between_group = case_when (
time_between <= umbral ~ "immediate" ,
time_between > umbral ~ "distant"
)) %>% group_by (time_between_group) %>%
summarise (total = n ())
print (total_counts3)
# A tibble: 1 x 2
time_between_group total
<chr> <int>
1 distant 22683
reduced_model_Follower.lmer_240 <- lmer (
L_time ~ as.factor (Hour_ENTRY) + (1 | ID) + (1 | Follower_ID) + (1 | Social_Group),
data = data_PIC_pvalues240
)
summary (reduced_model_Follower.lmer_240)
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_pvalues240
REML criterion at convergence: 77149.3
Scaled residuals:
Min 1Q Median 3Q Max
-4.2695 -0.2705 0.2424 0.6177 2.1801
Random effects:
Groups Name Variance Std.Dev.
ID (Intercept) 0.09029 0.3005
Follower_ID (Intercept) 0.02547 0.1596
Social_Group (Intercept) 0.04051 0.2013
Residual 1.68124 1.2966
Number of obs: 22683, groups: ID, 548; Follower_ID, 548; Social_Group, 36
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 6.876e+00 5.146e-02 1.204e+02 133.611 < 2e-16 ***
as.factor(Hour_ENTRY)1 2.657e-02 5.016e-02 2.227e+04 0.530 0.59634
as.factor(Hour_ENTRY)2 3.923e-02 5.101e-02 2.228e+04 0.769 0.44184
as.factor(Hour_ENTRY)3 1.594e-02 5.130e-02 2.236e+04 0.311 0.75600
as.factor(Hour_ENTRY)4 3.681e-02 5.308e-02 2.244e+04 0.694 0.48797
as.factor(Hour_ENTRY)5 -1.682e-01 5.795e-02 2.250e+04 -2.902 0.00371 **
as.factor(Hour_ENTRY)6 -5.676e-01 6.109e-02 2.254e+04 -9.291 < 2e-16 ***
as.factor(Hour_ENTRY)7 -4.806e-01 6.277e-02 2.255e+04 -7.657 1.97e-14 ***
as.factor(Hour_ENTRY)8 -4.264e-01 6.369e-02 2.253e+04 -6.696 2.19e-11 ***
as.factor(Hour_ENTRY)9 -4.052e-01 6.583e-02 2.249e+04 -6.156 7.60e-10 ***
as.factor(Hour_ENTRY)10 -4.819e-01 6.714e-02 2.250e+04 -7.178 7.30e-13 ***
as.factor(Hour_ENTRY)11 -5.066e-01 6.986e-02 2.252e+04 -7.251 4.28e-13 ***
as.factor(Hour_ENTRY)12 -6.388e-01 6.752e-02 2.252e+04 -9.460 < 2e-16 ***
as.factor(Hour_ENTRY)13 -5.978e-01 6.774e-02 2.254e+04 -8.825 < 2e-16 ***
as.factor(Hour_ENTRY)14 -7.619e-01 6.509e-02 2.251e+04 -11.705 < 2e-16 ***
as.factor(Hour_ENTRY)15 -6.019e-01 6.583e-02 2.256e+04 -9.142 < 2e-16 ***
as.factor(Hour_ENTRY)16 -3.193e-01 6.220e-02 2.252e+04 -5.134 2.86e-07 ***
as.factor(Hour_ENTRY)17 -1.017e-01 5.586e-02 2.255e+04 -1.821 0.06860 .
as.factor(Hour_ENTRY)18 -1.986e-02 5.389e-02 2.247e+04 -0.368 0.71252
as.factor(Hour_ENTRY)19 4.592e-02 5.207e-02 2.242e+04 0.882 0.37788
as.factor(Hour_ENTRY)20 1.557e-02 5.093e-02 2.240e+04 0.306 0.75984
as.factor(Hour_ENTRY)21 -1.173e-02 4.996e-02 2.235e+04 -0.235 0.81431
as.factor(Hour_ENTRY)22 1.611e-02 4.997e-02 2.230e+04 0.322 0.74720
as.factor(Hour_ENTRY)23 -1.454e-02 5.040e-02 2.233e+04 -0.289 0.77292
---
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
print (VarCorr (reduced_model_Follower.lmer_240), comp = "Variance" )
Groups Name Variance
ID (Intercept) 0.090286
Follower_ID (Intercept) 0.025466
Social_Group (Intercept) 0.040512
Residual 1.681239
hist (data_PIC$ time_between)
hist (data_PIC$ time_between[data_PIC$ time_between< 7200 ])
hist (data_PIC$ time_between[data_PIC$ time_between< 3600 ])
table (data_PIC$ time_between<= 3600 )
table (data_PIC$ time_between > 240 )