---
title: "Input data"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Input data}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
```{r setup}
library(serosv)
library(magrittr)
```
## Input data format
All `*_model()` functions in `serosv` require `data` argument as the input data to be fitted.
The package can handle both linelisting and aggregated data, and it infers the format from the structure of the input data frame. This means that input data is [expected to follow a specific format.]{.underline}
For linelisting data: data must have 3 columns as follows
- the age vector (column name specified via `age_col` parameter)
- the vector of counts of sero positives of that age group (column name specified via `pos_col` parameter)
- the vector is the total population of that age group (column name specified via `tot_col` parameter)
For aggregated data: data must have 2 columns as follows
- the age vector of individuals
- is the vector indicating the serostatus of that individual (column name specified via `status_col` parameter)
**Example:** Fitting linelisting and aggregated data using `polynomial_model()`
```{r}
linelisting <- parvob19_fi_1997_1998[order(parvob19_fi_1997_1998$age), ]
aggregated <- hav_bg_1964
# View the 2 different data format
head(linelisting)
head(aggregated)
# fit with aggregated data
model1 <- polynomial_model(aggregated, k=1)
plot(model1)
# fit with linelisting data
model2 <- polynomial_model(linelisting, k=1, status_col = "seropositive")
plot(model2)
```
## Data transformation
`serosv` also offers function `transform_data()` to convert from linelisting to aggregated data. For more information, refer to [Data transformation](data_transformation.html)
```{r}
transform_data(
linelisting,
stratum_col="age",
status_col="seropositive") %>%
polynomial_model(k=1) %>%
plot()
```