---
title: "A-quick-tour-of-PWR"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{A-quick-tour-of-PWR}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include=FALSE}
library(knitr)
knitr::opts_chunk$set(
	fig.align = "center",
	fig.height = 5.5,
	fig.width = 6,
	warning = FALSE,
	collapse = TRUE,
	dev.args = list(pointsize = 10),
	out.width = "90%",
	par = TRUE
)
knit_hooks$set(par = function(before, options, envir)
  { if (before && options$fig.show != "none") 
       par(family = "sans", mar = c(4.1,4.1,1.1,1.1), mgp = c(3,1,0), tcl = -0.5)
})
```

```{r, message = FALSE, echo = FALSE}
library(samurais)
```

# Introduction

**PWR**: Piecewise Regression (PWR) for time series (or structured 
longitudinal data) modeling and optimal segmentation by using dynamic 
programming.

It was written in R Markdown, using the [knitr](https://cran.r-project.org/package=knitr)
package for production.

See `help(package="samurais")` for further details and references provided by `citation("samurais")`.

# Load data

```{r}
data("univtoydataset")
```

# Set up PWR model parameters

```{r}
K <- 5 # Number of segments
p <- 3 # Polynomial degree
```

# Estimation

```{r}
pwr <- fitPWRFisher(univtoydataset$x, univtoydataset$y, K, p)
```

# Summary

```{r}
pwr$summary()
```

# Plots

## Regressors

```{r}
pwr$plot(what = "regressors")
```

## Segmentation

```{r}
pwr$plot(what = "segmentation")
```
