---
title: "Example: Replicating st0399 results"
author: "Lars Børty Nielsen, Martin Bøgsted, and Rasmus Brøndum"
output: rmarkdown::html_vignette
bibliography: ../inst/REFERENCES.bib
vignette: >
  %\VignetteIndexEntry{Example: Replicating st0399 results}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

```{r setup}
library(ccostr)
```

The ccostr package includes a dataset called "hcost". The dataset comes from the Stata package of the same name [@Chen2015], and we can therefore use it both as an example and to verify that the two packages reach similar estimates. First we look at the data:

```{r}
head(hcost)
```

Now we use the ccmean function with a limit of 4 years (1461 days), we also add the interpolation term which affects the interpolation of cost between two observed time points. By default this parameter is set to zero, but to replicate the results of the Stata implementation we set it to 1.

```{r hcost}
est <- ccmean(hcost, L = 1461, addInterPol = 1)
est
```

These estimates are similar to what is found with the hcost Stata package. We can also plot these with the included generic plot function:

```{r fig.height=3, fig.width=7}
plot(est)
```

### References