-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
142 lines (111 loc) · 5.77 KB
/
README.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# gamvinereg: D-Vine GAM Copula based Quantile Regression
<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/gamvinereg)](https://CRAN.R-project.org/package=gamvinereg)
[![R-CMD-check](https://github.com/jobstdavid/gamvinereg/workflows/R-CMD-check/badge.svg)](https://github.com/jobstdavid/gamvinereg/actions)
[![version](https://img.shields.io/badge/version-0.2.0-green.svg?style=flat)](https://github.com/jobstdavid/gamvinereg)
<!-- badges: end -->
An R package for D-vine copula based quantile regression using bivariate conditional copulas as described in the references.
It depends on the R-packages:
- [VineCopula](https://cran.r-project.org/web/packages/VineCopula/index.html), [gamCopula](https://cran.r-project.org/web/packages/gamCopula/index.html): Including bivariate conditional copulas, where Kendall's $\tau$ or the copula parameter is linked to a partially linear model using GAM and/or spline smoothing. The bivariate conditional copula family set for modeling the dependencies consists of the Gaussian, Student-t, double Clayton type I-IV and double Gumbel type I-IV copula as implemented in the R-package [gamCopula](https://cran.r-project.org/web/packages/gamCopula/index.html). The double Clayton and Gumbel copula type consist of additional rotated versions of the Clayton and Gumbel copula, respectively to cover negative dependence as well.
- [gamlss](https://cran.r-project.org/web/packages/gamlss/index.html): Margins can be selected from a large set of parametric distribution families using generalized additive models for location, scale and shape (GAMLSS).
- [gamlss.tr](https://cran.r-project.org/web/packages/gamlss.tr/index.html): GAMLSS extension to allow for truncated distribution families.
- [gamlss.cens](https://cran.r-project.org/web/packages/gamlss.cens/index.html): GAMLSS extension to allow for censored distribution families.
- [gamlss.dist](https://cran.r-project.org/web/packages/gamlss.dist/index.html): GAMLSS extension to allow for distribution families with transformed response.
## Installation
You can install the development version from GitHub with:
``` r
# install.packages("remotes")
remotes::install_github("jobstdavid/gamvinereg")
```
## Package overview
Below is an overview of the most important functions:
- ``gamvinereg``: selects most relevant predictor variables from the given data to make predictions based on a D-vine GAM copula. It returns an object of class ``gamvinereg``. The class has the following methods:
- ``print``: a brief overview of the model statistics.
- ``summary``: a more detailed overview of the selected response margin distribution and bivariate conditional copulas.
- ``predict``: make predictions at a given quantile level.
- ``cpit``: calculate the conditional probabililty integral transformed (PIT) values for the response given the predictor variables.
- ``cpdf``: calculate the conditional density values for the response given the predictor variables.
- ``gam_control``: configuration of the bivariate conditional copula.
## Example
### Load R-package and data
```{r example1}
# load package
library(gamvinereg)
# load data for station Hannover
data(station)
```
### Specify margins
```{r example2}
## generate margin distributions
# generate left-truncated at 0 normal distribution
gen.trun(par = 0, family = "NO", type = "left")
# generate left-censored normal distribution
gen.cens(family = "NO", type = "left")
# generate log-normal distribution
gen.Family(family = "NO", type = "log")
## margin specifications to select from
margins <- list(
# margin for variable obs (normal distribution)
list(list(family = NO(),
mu.formula = obs ~ sin1 + cos1,
sigma.formula = ~ sin1 + cos1)),
# margin for variable t2m_mean (normal distribution)
list(list(family = NO(),
mu.formula = t2m_mean ~ sin1 + cos1,
sigma.formula = ~ sin1 + cos1)),
# margins for variable t2m_sd (log-normal, left-truncated/censored at 0 normal distribution)
list(list(family = logNO(),
mu.formula = t2m_sd ~ sin1 + cos1,
sigma.formula = ~ sin1 + cos1),
list(family = NOtr(),
mu.formula = t2m_sd ~ sin1 + cos1,
sigma.formula = ~ sin1 + cos1),
list(family = NOlc(),
mu.formula = Surv(t2m_sd, t2m_sd > 0, type = "left") ~ sin1 + cos1,
sigma.formula = ~ sin1 + cos1))
)
```
### Fit gamvinereg
```{r example3}
# fit gamvinereg with time-dependent linear correlation model
(object <- gamvinereg(formula = obs ~ t2m_mean + t2m_sd,
data = station,
control = gam_control(formula = ~ sin1 + cos1),
margins = margins))
```
### Make quantile predictions
```{r example4}
# predict median
med <- predict(object, newdata = station, alpha = 0.5)
# predict deciles
dec <- predict(object, newdata = station, alpha = 1:9/10)
```
### Calculate conditional PIT values
```{r example5, fig.align = "center", out.width = "75%"}
# calculate conditional PIT values
u <- cpit(object, newdata = station)
# should be approximately uniform
hist(u, probability = TRUE)
```
### Calculate conditional density values
```{r example6, fig.align = "center", out.width = "75%"}
# calculate conditional density values
d <- cpdf(object)
# calculate log-likelihood
sum(log(d))
```
## Contact
Feel free to contact [[email protected]](mailto:[email protected]) if you have any questions or suggestions.
## References
Jobst, D., Möller, A., and Groß, J. (2023). D-Vine GAM Copula based Quantile Regression with Application to Ensemble Postprocessing. doi: [10.48550/arXiv.2309.05603](https://arxiv.org/abs/2309.05603).