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_noon.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: 181 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 171 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
## 9     1   2    Y77-10      705       74.8      0.906      3   25.51667
## 7     1   2    Y64-17      706       74.0      0.935      2   28.15000
## 8     1   2    Y77-11      701       68.7      0.967      2   34.10000
## 18    2   5    Y70-11      695       71.2      0.980      1   39.25000
## 1     1   2    Y67-14      693       75.6      1.879     10   71.40000
## 6     1   2    Y64-16      697       77.2      3.004      9   75.41667
## 2     1   2    Y69-12      703       80.6      2.014     10   88.53333
## 14    2   5    Y65-10      694       71.6      1.895      5   90.78333
## 13    2   5    Y64-14      686       71.0      3.002      7   92.55000
## 11    1   2    Y66-14      702       76.1      2.309     12   95.91667
## 20    2   5    Y68-14      687       72.5      2.595     12   96.80000
## 19    2   5    Y74-14      689       68.6      2.134      5   98.30000
## 24    2   5    Y76-15      696       62.2      2.445      7  100.83333
## 4     1   2    Y70-13      700       74.4      2.763     13  102.45000
## 15    2   5    Y66-10      688       77.7      2.936     14  106.28333
## 22    2   5    Y76-13      685       72.4      2.813     17  141.75000
## 5     1   2    Y71-12      699       63.7      2.560     18  143.73333
## 10    1   2    Y68-11      708       72.8      2.736     11  144.05000
## 17    2   5    Y77-12      692       78.6      3.349     15  154.08333
## 3     1   2    Y66-12      704         NA         NA     NA         NA
## 12    1   2    Y68-12      707         NA         NA     NA         NA
## 16    2   5    Y70-12      690         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)