
<!-- README.md is generated from README.Rmd. Please edit that file -->

# vinereg

[![R-CMD-check](https://github.com/tnagler/vinereg/actions/workflows/R-CMD-check.yaml/badge.svg?branch=main)](https://github.com/tnagler/vinereg/actions/workflows/R-CMD-check.yaml)
[![Coverage
status](https://codecov.io/gh/tnagler/vinereg/branch/main/graph/badge.svg)](https://app.codecov.io/github/tnagler/vinereg?branch=main)
[![CRAN
status](https://www.r-pkg.org/badges/version/vinereg)](https://cran.r-project.org/package=vinereg)

Fit D-vine copula regression models for conditional mean and quantile
prediction with continuous or discrete variables.

## How to install

  - the stable release from CRAN:

    ``` r
    install.packages("vinereg")
    ```

  - the latest development version:

    ``` r
    # install.packages("remotes")
    remotes::install_github("tnagler/vinereg", build_vignettes = TRUE)
    ```

## Functionality

`vinereg` provides:

  - automatic covariate selection or a user-specified D-vine order;
  - parametric and nonparametric pair-copula families;
  - conditional mean, quantile, distribution, and density predictions;
  - support for continuous, ordered, and unordered variables; and
  - standard model summaries, information criteria, and marginal effect
    plots.

See the [package website](https://tnagler.github.io/vinereg/) for the
complete reference and worked examples.

## Example

``` r
set.seed(5)
library(vinereg)
data(mtcars)

# declare factors and discrete variables
for (var in c("cyl", "vs", "gear", "carb"))
    mtcars[[var]] <- as.ordered(mtcars[[var]])
mtcars[["am"]] <- as.factor(mtcars[["am"]])

# fit model
(fit <- vinereg(mpg ~ ., family_set = "nonpar", data = mtcars))
#> D-vine regression model: mpg | wt, qsec, drat
#> nobs = 32, edf = 20.35, cll = -57.42, caic = 155.54, cbic = 185.36

summary(fit)
#>    var      edf         cll       caic       cbic      p_value
#> 1  mpg 3.803013 -100.046939 207.699904 213.274116           NA
#> 2   wt 9.871177   29.583463 -39.424574 -24.956036 4.600863e-09
#> 3 qsec 5.389674    7.422915  -4.066482   3.833357 1.449560e-02
#> 4 drat 1.282135    5.617764  -8.671258  -6.791987 1.321129e-03
AIC(fit)
#> [1] 155.5376

# show marginal effects for all selected variables
plot_effects(fit)
```

<img src="man/figures/README-unnamed-chunk-1-1.png" alt="" width="100%" />

``` r

# predict mean and median
head(predict(fit, mtcars, alpha = c(NA, 0.5)), 4)
#>       mean      0.5
#> 1 22.57023 22.28455
#> 2 21.76349 21.46394
#> 3 25.51574 25.26815
#> 4 20.18286 20.17140
```

## Vignettes

For more examples, have a look at the vignettes with

``` r
vignette("abalone-example", package = "vinereg")
vignette("bike-rental", package = "vinereg")
```

### References

Kraus and Czado (2017). D-vine copula based quantile regression.
*Computational Statistics & Data Analysis*, 110, 1-18.
[link](https://doi.org/10.1016/j.csda.2016.12.009),
[preprint](https://arxiv.org/abs/1510.04161)

Schallhorn, N., Kraus, D., Nagler, T., Czado, C. (2017). D-vine quantile
regression with discrete variables. arXiv preprint,
[preprint](https://arxiv.org/abs/1705.08310).
