-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.Rmd
87 lines (67 loc) · 2.53 KB
/
index.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
---
title: "High resolution monitoring of antimicrobial consumption in Vietnamese small-scale chicken farms highlights discrepancies between study metrics"
output:
html_document:
theme: cosmo
toc: true
editor_options:
chunk_output_type: console
css: style.css
---
```{r general_options, include = FALSE}
knitr::knit_hooks$set(
margin = function(before, options, envir) {
if (before) par(mgp = c(1.5, .5, 0), bty = "n", plt = c(.105, .97, .13, .97))
else NULL
},
prompt = function(before, options, envir) {
options(prompt = if (options$engine %in% c("sh", "bash")) "$ " else "> ")
})
knitr::opts_chunk$set(margin = TRUE, prompt = TRUE, comment = "",
collapse = TRUE, cache = FALSE, autodep = TRUE,
dev.args = list(pointsize = 11), fig.height = 3.5,
fig.width = 4.24725, fig.retina = 2, fig.align = "center")
options(width = 137)
```
Here we show how to generate the
[ESVAC](https://www.ema.europa.eu/en/veterinary-regulatory/overview/antimicrobial-resistance/european-surveillance-veterinary-antimicrobial-consumption-esvac) data on the mg-to-IU and IU-to-mg
conversions as well as on the relationship between weight and age.
## Packages
Installing the required packages:
```{r}
required <- c("dplyr", "magrittr", "readr", "readxl", "tidyr")
to_install <- setdiff(required, row.names(installed.packages()))
if (length(to_install)) install.packages(to_install)
```
Loading `magrittr`:
```{r}
library(magrittr)
```
## Age-weight relationship
Data on chicken weights as a function of age were collected for a previous
study. The data are
[here](https://www.dropbox.com/s/5mmw31s2txbmgnx/Supplementary_Data_Frontiers.xlsx?dl=0):
```{r}
age_weight_data <- "https://www.dropbox.com/s/5mmw31s2txbmgnx/Supplementary_Data_Frontiers.xlsx?dl=0"
```
Let's dowload the excel file:
```{r}
tmp <- tempfile(fileext = ".xlsx")
download.file(sub("dl=0", "raw=1", age_weight_data), tmp)
```
Let's transform into a CSV file:
```{r}
if (!dir.exists("data")) dir.create("data")
tmp %>%
readxl::read_excel() %>%
tidyr::gather("week", "weight.kg", -FlockID, -Chicken) %>%
na.exclude() %>%
dplyr::mutate(week = sub("Week ", "", week)) %>%
dplyr::mutate_at(c("FlockID", "Chicken", "week"), as.integer) %>%
write.csv("data/age_weight.csv", quote = FALSE, row.names = FALSE)
```
The data can now be loaded by:
```{r}
age_weight <- readr::read_csv("https://raw.githubusercontent.com/viparc/amu_metrics/master/data/age_weight.csv",
col_types = "iiid")
```