1. Plots visit length, median weight, hour entry and Cosumed

# Plot 
ggplot(trial1.event,aes(x=wt_md,y=visit.length))+
  geom_point()+geom_smooth(method="lm")+
  labs(title = "Median weight vs visit length")+
  xlab("Median weight (kg)")+ylab("Visit length (min)")

ggplot(trial1.event,aes(x=wt_md,y=visit.length,color=Location))+
  geom_point()+geom_smooth(method="lm")+
  scale_color_brewer(type = "qual", palette = "Paired",direction = -1)+
  scale_fill_brewer(direction = -1)+
  labs(title = "Median weight vs visit length by location")+
  xlab("Hour entry feeder")+ylab("Visit length (min)")

ggplot(trial1.event,aes(x=wt_md,y=Consumed,color=Location))+
  geom_point()+geom_smooth(aes(color = Location, fill = Location),method="lm")+
  scale_color_brewer(type = "qual", palette = "Paired",direction = -1)+
  scale_fill_brewer(direction = -1)+
  labs(title = "Median weight vs Cosumed by location")+
  xlab("Hour entry feeder")+ylab("Consumed (kg)")

ggplot(trial1.event,aes(x=as.numeric(hour.entry),y=visit.length))+
  geom_point()+geom_smooth()+
  labs(title = "Horur entry feder vs visit length")+
  xlab("Hour entry feeder")+ylab("Visit length (min)")
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'

ggplot(trial1.event,aes(x=as.numeric(hour.entry),y=visit.length,color=Location))+
  geom_point()+geom_smooth()+
  labs(title = "Horur entry feder vs visit length by location")+
  xlab("Hour entry feeder")+ylab("Visit length (min)")
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'

2. Mixed model with Eartag as random effect

###2.1. Mixed model: y= location + Eartag

m0<-lmer(visit.length ~ Location -1 + (1|Ear_Tag),data=trial1.event)
summary(m0)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: visit.length ~ Location - 1 + (1 | Ear_Tag)
##    Data: trial1.event
## 
## REML criterion at convergence: 35665.7
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.5654 -0.7303 -0.0977  0.6024  7.3232 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Ear_Tag  (Intercept) 12.13    3.484   
##  Residual             68.31    8.265   
## Number of obs: 5039, groups:  Ear_Tag, 24
## 
## Fixed effects:
##           Estimate Std. Error     df t value Pr(>|t|)    
## Location1   13.735      1.021 22.057   13.45 4.14e-12 ***
## Location2   11.720      1.019 21.839   11.51 9.72e-11 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##           Loctn1
## Location2 0.000

2.2. Mixed model: y= location + covariate median wt + Eartag

m1<-lmer(visit.length ~ Location -1 + wt_md+(1|Ear_Tag),data=trial1.event)
summary(m1)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: visit.length ~ Location - 1 + wt_md + (1 | Ear_Tag)
##    Data: trial1.event
## 
## REML criterion at convergence: 35643.5
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.6035 -0.7243 -0.0937  0.6150  7.2601 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Ear_Tag  (Intercept) 12.02    3.467   
##  Residual             67.93    8.242   
## Number of obs: 5039, groups:  Ear_Tag, 24
## 
## Fixed effects:
##             Estimate Std. Error         df t value Pr(>|t|)    
## Location1   20.82733    1.66696  157.33809  12.494  < 2e-16 ***
## Location2   18.84427    1.67020  158.54568  11.283  < 2e-16 ***
## wt_md       -0.08009    0.01492 5018.32995  -5.368 8.33e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##           Loctn1 Loctn2
## Location2  0.630       
## wt_md     -0.793 -0.795

2.3. Mixed model: y = location + hour day + covariate median wt + Eartag

m2<-lmer(visit.length ~ Location -1 + hour.entry+ wt_md+(1|Ear_Tag),data=trial1.event)
summary(m2)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: visit.length ~ Location - 1 + hour.entry + wt_md + (1 | Ear_Tag)
##    Data: trial1.event
## 
## REML criterion at convergence: 35329.9
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.9508 -0.7040 -0.0817  0.6047  7.0863 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Ear_Tag  (Intercept) 11.50    3.392   
##  Residual             64.38    8.024   
## Number of obs: 5039, groups:  Ear_Tag, 24
## 
## Fixed effects:
##                Estimate Std. Error         df t value Pr(>|t|)    
## Location1      21.10299    1.79839  230.12017  11.734  < 2e-16 ***
## Location2      19.35129    1.79909  230.46621  10.756  < 2e-16 ***
## hour.entry1    -0.47619    1.02404 4992.22429  -0.465 0.641945    
## hour.entry2    -1.05195    1.05669 4992.34400  -0.996 0.319534    
## hour.entry3    -1.18266    1.04306 4992.67211  -1.134 0.256914    
## hour.entry4    -0.73880    1.01192 4992.87460  -0.730 0.465366    
## hour.entry5    -2.13691    0.94220 4993.15316  -2.268 0.023372 *  
## hour.entry6    -2.22574    0.91388 4992.73261  -2.435 0.014906 *  
## hour.entry7    -3.76553    0.87497 4992.63822  -4.304 1.71e-05 ***
## hour.entry8    -4.48515    0.85793 4992.61771  -5.228 1.78e-07 ***
## hour.entry9    -2.47296    0.88235 4993.28125  -2.803 0.005087 ** 
## hour.entry10   -1.60769    0.88655 4993.08432  -1.813 0.069829 .  
## hour.entry11   -1.88934    0.88550 4992.90796  -2.134 0.032920 *  
## hour.entry12   -1.56941    0.88502 4992.87056  -1.773 0.076238 .  
## hour.entry13   -1.03938    0.88362 4993.05873  -1.176 0.239544    
## hour.entry14   -0.47700    0.90539 4992.81334  -0.527 0.598322    
## hour.entry15    0.01161    0.90927 4993.20493   0.013 0.989815    
## hour.entry16    3.54266    0.93594 4993.34525   3.785 0.000155 ***
## hour.entry17    3.52724    0.99554 4993.21432   3.543 0.000399 ***
## hour.entry18    1.82496    1.07246 4992.30787   1.702 0.088881 .  
## hour.entry19    2.21759    1.08121 4991.66008   2.051 0.040316 *  
## hour.entry20    0.74471    1.01730 4993.37340   0.732 0.464174    
## hour.entry21    0.62861    1.06520 4992.09771   0.590 0.555124    
## hour.entry22    0.01534    1.01374 4991.90134   0.015 0.987927    
## hour.entry23    0.22555    1.03545 4992.76654   0.218 0.827570    
## wt_md          -0.07338    0.01462 4995.46743  -5.018 5.41e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation matrix not shown by default, as p = 26 > 12.
## Use print(x, correlation=TRUE)  or
##     vcov(x)        if you need it

3. Mixed model with Eartag and follower as random effects

3.1. Mixed model: y= location + Eartag + follower

m3<-lmer(visit.length ~ Location -1 + (1|Ear_Tag) + (1|follower),data=trial1.event)
summary(m3)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: visit.length ~ Location - 1 + (1 | Ear_Tag) + (1 | follower)
##    Data: trial1.event
## 
## REML criterion at convergence: 35592.4
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.6507 -0.6941 -0.1099  0.6102  7.2796 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Ear_Tag  (Intercept) 12.017   3.467   
##  follower (Intercept)  1.163   1.078   
##  Residual             66.875   8.178   
## Number of obs: 5039, groups:  Ear_Tag, 24; follower, 24
## 
## Fixed effects:
##           Estimate Std. Error     df t value Pr(>|t|)    
## Location1   13.761      1.063 26.105   12.95 7.21e-13 ***
## Location2   12.086      1.061 25.927   11.39 1.37e-11 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##           Loctn1
## Location2 0.000

3.2. Mixed model: y= location + covariate median wt + Eartag

m4<-lmer(visit.length ~ Location -1 + wt_md+(1|Ear_Tag)+ (1|follower),data=trial1.event)
summary(m4)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: 
## visit.length ~ Location - 1 + wt_md + (1 | Ear_Tag) + (1 | follower)
##    Data: trial1.event
## 
## REML criterion at convergence: 35568.9
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.7038 -0.6941 -0.1054  0.6193  7.2122 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Ear_Tag  (Intercept) 11.905   3.450   
##  follower (Intercept)  1.178   1.085   
##  Residual             66.488   8.154   
## Number of obs: 5039, groups:  Ear_Tag, 24; follower, 24
## 
## Fixed effects:
##             Estimate Std. Error         df t value Pr(>|t|)    
## Location1   20.97874    1.68872  166.78265  12.423  < 2e-16 ***
## Location2   19.33585    1.69205  168.08361  11.427  < 2e-16 ***
## wt_md       -0.08152    0.01485 5017.88612  -5.487 4.28e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##           Loctn1 Loctn2
## Location2  0.608       
## wt_md     -0.779 -0.781

3.3. Mixed model: y = location + hour day + covariate median wt + Eartag + Follower

m5<-lmer(visit.length ~ Location -1 +hour.entry+ wt_md+(1|Ear_Tag) + (1|follower),
         data=trial1.event)
summary(m5)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: 
## visit.length ~ Location - 1 + hour.entry + wt_md + (1 | Ear_Tag) +  
##     (1 | follower)
##    Data: trial1.event
## 
## REML criterion at convergence: 35286.2
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.9973 -0.6916 -0.0862  0.6027  7.0395 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  Ear_Tag  (Intercept) 11.5331  3.3960  
##  follower (Intercept)  0.7558  0.8694  
##  Residual             63.4817  7.9675  
## Number of obs: 5039, groups:  Ear_Tag, 24; follower, 24
## 
## Fixed effects:
##                Estimate Std. Error         df t value Pr(>|t|)    
## Location1      20.91513    1.81325  235.05912  11.535  < 2e-16 ***
## Location2      19.40450    1.81336  235.14791  10.701  < 2e-16 ***
## hour.entry1    -0.39283    1.01806 4981.47448  -0.386 0.699618    
## hour.entry2    -1.00681    1.05200 4988.22184  -0.957 0.338591    
## hour.entry3    -1.12622    1.03723 4983.09136  -1.086 0.277624    
## hour.entry4    -0.67113    1.00828 4991.02125  -0.666 0.505691    
## hour.entry5    -1.75350    0.93961 4992.35173  -1.866 0.062073 .  
## hour.entry6    -1.82112    0.91150 4991.64401  -1.998 0.045776 *  
## hour.entry7    -3.33538    0.87215 4990.43677  -3.824 0.000133 ***
## hour.entry8    -4.15494    0.85464 4989.32832  -4.862 1.20e-06 ***
## hour.entry9    -2.08570    0.88030 4993.22789  -2.369 0.017859 *  
## hour.entry10   -1.06724    0.88551 4993.50225  -1.205 0.228177    
## hour.entry11   -1.41000    0.88333 4992.47259  -1.596 0.110499    
## hour.entry12   -1.11883    0.88254 4991.54195  -1.268 0.204953    
## hour.entry13   -0.62854    0.88086 4991.43946  -0.714 0.475539    
## hour.entry14   -0.06810    0.90213 4989.49457  -0.075 0.939826    
## hour.entry15    0.21716    0.90512 4988.45830   0.240 0.810397    
## hour.entry16    3.67875    0.93203 4990.11052   3.947 8.02e-05 ***
## hour.entry17    3.68154    0.99058 4986.61369   3.717 0.000204 ***
## hour.entry18    1.83706    1.06662 4983.51313   1.722 0.085074 .  
## hour.entry19    2.34890    1.07638 4987.02576   2.182 0.029139 *  
## hour.entry20    0.91457    1.01221 4987.00740   0.904 0.366283    
## hour.entry21    0.72096    1.05976 4984.77700   0.680 0.496343    
## hour.entry22    0.19344    1.00864 4985.36439   0.192 0.847922    
## hour.entry23    0.32981    1.03018 4985.95333   0.320 0.748874    
## wt_md          -0.07432    0.01461 4995.47327  -5.087 3.76e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation matrix not shown by default, as p = 26 > 12.
## Use print(x, correlation=TRUE)  or
##     vcov(x)        if you need it

3. Summary estimated variance components

a %>%
  kable() %>%
  kable_styling()
var Eartag var Follower var error -2loglike
loc + Eartag 12.13 68.31 35665.7
loc + wt + Eartag 12.02 67.93 35643.5
loc + wt + hour.ent + Eartag 11.5 64.38 35329.9
loc + Eartag + Foll 12.07 1.163 66.87 35592.4
loc + wt + Eartag + Foll 11.905 1.178 66.48 35568.9
loc + wt + + hour.ent + Eartag + Foll 11.53 0.75 63.48 35286.2