Sample report for firefeeders

This is just an illustration of the use of FIRE feeder event data from first 24 hours of use.

setwd("C:/Users/Admin/OneDrive/Documents/phenomics/FIRE")
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 3.4.3
## -- Attaching packages --------------------------------------------------------------------------------------------------------------------------------------------------------------- tidyverse 1.2.1 --
## v ggplot2 2.2.1     v purrr   0.2.4
## v tibble  1.4.2     v dplyr   0.7.4
## v tidyr   0.8.0     v stringr 1.2.0
## v readr   1.1.1     v forcats 0.3.0
## Warning: package 'tibble' was built under R version 3.4.3
## Warning: package 'tidyr' was built under R version 3.4.3
## Warning: package 'readr' was built under R version 3.4.3
## Warning: package 'purrr' was built under R version 3.4.3
## Warning: package 'dplyr' was built under R version 3.4.3
## Warning: package 'forcats' was built under R version 3.4.3
## -- Conflicts ------------------------------------------------------------------------------------------------------------------------------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
fire_file<-"FIRE_03_30_18.csv"
fire_data<-read_csv(fire_file)
## Parsed with column specification:
## cols(
##   Location = col_integer(),
##   Tag = col_character(),
##   Date = col_character(),
##   Entry = col_time(format = ""),
##   Exit = col_time(format = ""),
##   `Ent Wt` = col_double(),
##   `Ext Wt` = col_double(),
##   Consumed = col_double(),
##   Weight = col_double(),
##   `Topup Amount` = col_double()
## )
fire_data
## # A tibble: 144 x 10
##    Location Tag       Date   Entry Exit  `Ent Wt` `Ext Wt` Consumed Weight
##       <int> <chr>     <chr>  <tim> <tim>    <dbl>    <dbl>    <dbl>  <dbl>
##  1        1 00000000~ 3/28/~ 15:24 15:24  0.       0.00200 -0.00200    0. 
##  2        1 00000000~ 3/28/~ 15:37 15:38 -0.00200 -0.00400  0.00200    0. 
##  3        1 00000000~ 3/29/~ 08:25 08:26 -0.00300 -0.00300  0.         0. 
##  4        1 00000000~ 3/29/~ 08:31 08:33 -0.00100 -0.00500  0.00400    0. 
##  5        1 00000000~ 3/29/~ 08:37 08:37 -0.00600 -0.00800  0.00200    0. 
##  6        1 00000000~ 3/29/~ 08:50 08:50 -0.00700 -0.00800  0.00100    0. 
##  7        1 98515201~ 3/29/~ 08:51 08:55  0.433   -0.00800  0.441      0. 
##  8        1 98515201~ 3/29/~ 10:59 10:59  0.815    0.810    0.00500   82.2
##  9        1 98515201~ 3/29/~ 11:01 11:07  0.810    0.779    0.0310    64.0
## 10        1 98515201~ 3/29/~ 11:09 11:09  0.779    0.774    0.00500   82.2
## # ... with 134 more rows, and 1 more variable: `Topup Amount` <dbl>
key<-read_csv("FIRE_key.csv")
## Parsed with column specification:
## cols(
##   unit = col_integer(),
##   pen = col_integer(),
##   ear_notch = col_character(),
##   RFID_tag = col_integer()
## )
key
## # A tibble: 24 x 4
##     unit   pen ear_notch RFID_tag
##    <int> <int> <chr>        <int>
##  1     1     2 Y67-14         693
##  2     1     2 Y69-12         703
##  3     1     2 Y66-12         704
##  4     1     2 Y70-13         700
##  5     1     2 Y71-12         699
##  6     1     2 Y64-16         697
##  7     1     2 Y64-17         706
##  8     1     2 Y77-11         701
##  9     1     2 Y77-10         705
## 10     1     2 Y68-11         708
## # ... with 14 more rows
#zerotags
filter(fire_data,Tag=="000000000000000")
## Warning: package 'bindrcpp' was built under R version 3.4.3
## # A tibble: 7 x 10
##   Location Tag       Date    Entry Exit  `Ent Wt` `Ext Wt` Consumed Weight
##      <int> <chr>     <chr>   <tim> <tim>    <dbl>    <dbl>    <dbl>  <dbl>
## 1        1 00000000~ 3/28/2~ 15:24 15:24  0.       0.00200 -0.00200     0.
## 2        1 00000000~ 3/28/2~ 15:37 15:38 -0.00200 -0.00400  0.00200     0.
## 3        1 00000000~ 3/29/2~ 08:25 08:26 -0.00300 -0.00300  0.          0.
## 4        1 00000000~ 3/29/2~ 08:31 08:33 -0.00100 -0.00500  0.00400     0.
## 5        1 00000000~ 3/29/2~ 08:37 08:37 -0.00600 -0.00800  0.00200     0.
## 6        1 00000000~ 3/29/2~ 08:50 08:50 -0.00700 -0.00800  0.00100     0.
## 7        2 00000000~ 3/29/2~ 08:08 08:08  0.555    0.552    0.00300     0.
## # ... with 1 more variable: `Topup Amount` <dbl>
fire_data<-filter(fire_data,Tag!="000000000000000")

ffd<-mutate(fire_data,visit_length=Exit-Entry,ID=round(as.numeric(Tag)-1000*985152014209))


idx<-match(ffd$ID,key$RFID_tag)
ffd<-(mutate(ffd,earnotch=key$ear_notch[idx]))

sum_per_animal<-ffd %>%group_by(earnotch)%>% summarize(med_weight=median(Weight),total_feed=sum(Consumed),visits=sum(Weight*0+1),total_time=as.numeric(sum(visit_length)/60))
idr<-match(key$ear_notch,sum_per_animal$earnotch)

animal_report<-cbind(key,sum_per_animal[idr,-1])
animal_report<-animal_report[order(animal_report$total_time),]
write.csv(animal_report[order(animal_report$total_time),],file=paste("animal_report",fire_file,sep="_"))
            
ggplot(ffd,aes(x=visit_length,y=Consumed,color=earnotch))+geom_point()
## Don't know how to automatically pick scale for object of type difftime. Defaulting to continuous.

print(animal_report)
##    unit pen ear_notch RFID_tag med_weight total_feed visits total_time
## 7     1   2    Y64-17      706       74.0      0.389      1   13.95000
## 9     1   2    Y77-10      705       37.4      0.665      2   19.33333
## 1     1   2    Y67-14      693       37.6      1.370      8   51.06667
## 6     1   2    Y64-16      697       76.2      2.050      7   51.86667
## 19    2   5    Y74-14      689       68.6      1.117      2   53.30000
## 24    2   5    Y76-15      696       61.7      1.615      4   63.90000
## 11    1   2    Y66-14      702       76.3      1.718     10   71.60000
## 2     1   2    Y69-12      703       80.9      1.603      8   71.83333
## 13    2   5    Y64-14      686       69.8      2.358      5   73.21667
## 14    2   5    Y65-10      694       71.7      1.637      4   76.81667
## 20    2   5    Y68-14      687       72.4      2.257     10   86.30000
## 4     1   2    Y70-13      700       74.0      2.338     11   88.05000
## 15    2   5    Y66-10      688       77.5      2.390     12   88.06667
## 10    1   2    Y68-11      708       72.8      1.889      8   96.23333
## 5     1   2    Y71-12      699       63.8      2.111     16  119.66667
## 22    2   5    Y76-13      685       72.7      2.440     14  124.26667
## 17    2   5    Y77-12      692       78.4      2.700     14  130.20000
## 3     1   2    Y66-12      704         NA         NA     NA         NA
## 8     1   2    Y77-11      701         NA         NA     NA         NA
## 12    1   2    Y68-12      707         NA         NA     NA         NA
## 16    2   5    Y70-12      690         NA         NA     NA         NA
## 18    2   5    Y70-11      695         NA         NA     NA         NA
## 21    2   5    Y67-11      698         NA         NA     NA         NA
## 23    2   5    Y77-13      691         NA         NA     NA         NA

Notice: 1) ammount consumed and time in the feeder correlate very well, 2) some animals with NA in the summary have not gone through the feeder in the first 24 hrs in the pen, 3) scale seems to be off for some animals (too light)