Skip to content

Commit

Permalink
add conditional density function (#15)
Browse files Browse the repository at this point in the history
* add conditional density function

* update NEWS + website

---------

Co-authored-by: tnagler <thomas.nagler@tum.de>
  • Loading branch information
tnagler and tnagler committed Feb 9, 2024
1 parent 44c3a09 commit 2e0406c
Show file tree
Hide file tree
Showing 39 changed files with 617 additions and 333 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: vinereg
Type: Package
Title: D-Vine Quantile Regression
Version: 0.9.2
Version: 0.10.0
Authors@R: c(
person("Thomas", "Nagler",, "mail@tnagler.com", role = c("aut", "cre")),
person("Dani", "Kraus",,, role = c("ctb"))
Expand All @@ -26,7 +26,7 @@ LinkingTo:
wdm,
RcppThread,
kde1d
RoxygenNote: 7.1.2
RoxygenNote: 7.2.3
Roxygen: list(markdown = TRUE)
Suggests:
knitr,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ S3method(predict,vinereg)
S3method(print,vinereg)
S3method(summary,vinereg)
export(cll)
export(cpdf)
export(cpit)
export(plot_effects)
export(vinereg)
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# vinereg 0.10.0

NEW FEATURE

* New function `pdf()` to compute the conditional log-likelihood.


# vinereg 0.9.2

BUG FIX
Expand Down
4 changes: 4 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ cond_dist_cpp <- function(u, vinecop_r, num_threads) {
.Call(`_vinereg_cond_dist_cpp`, u, vinecop_r, num_threads)
}

cond_dens_cpp <- function(u, vinecop_r, num_threads) {
.Call(`_vinereg_cond_dens_cpp`, u, vinecop_r, num_threads)
}

cond_loglik_cpp <- function(u, vinecop_r, num_threads) {
.Call(`_vinereg_cond_loglik_cpp`, u, vinecop_r, num_threads)
}
Expand Down
35 changes: 35 additions & 0 deletions R/cpit.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,38 @@ cll <- function(object, newdata, cores = 1) {
ll_cop <- cond_loglik_cpp(newdata, object$vine, cores)
ll_cop + ll_marg
}

#' Conditional PDF
#'
#' Calculates the conditional density of the response given the covariates.
#'
#' @param object an object of class \code{vinereg}.
#' @param newdata matrix of response and covariate values for which to compute
#' the conditional density
#' @param cores integer; the number of cores to use for computations.
#'
#' @export
#'
#' @examples
#' \dontshow{
#' set.seed(1)
#' }
#' # simulate data
#' x <- matrix(rnorm(500), 250, 2)
#' y <- x %*% c(1, -2)
#' dat <- data.frame(y = y, x = x, z = as.factor(rbinom(250, 2, 0.5)))
#'
#' # fit vine regression model
#' fit <- vinereg(y ~ ., dat)
#'
#' cpdf(fit, dat)
cpdf <- function(object, newdata, cores = 1) {
newdata <- prepare_newdata(newdata, object, use_response = TRUE)
dens_marg <- if (inherits(object$margins[[1]], "kde1d")) {
kde1d::dkde1d(newdata[, 1], object$margins[[1]])
} else {
1
}
newdata <- to_uscale(newdata, object$margins)
cond_dens_cpp(newdata, object$vine, cores) * dens_marg
}
2 changes: 1 addition & 1 deletion docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/LICENSE-text.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

259 changes: 129 additions & 130 deletions docs/articles/abalone-example.html

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
251 changes: 125 additions & 126 deletions docs/articles/bike-rental.html

Large diffs are not rendered by default.

Binary file modified docs/articles/bike-rental_files/figure-html/count_with_trend-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/articles/bike-rental_files/figure-html/me_humidity-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/articles/bike-rental_files/figure-html/me_month-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/articles/bike-rental_files/figure-html/me_season-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/articles/bike-rental_files/figure-html/me_temperature-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/articles/bike-rental_files/figure-html/me_weekday-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/articles/bike-rental_files/figure-html/me_windspeed-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/articles/bike-rental_files/figure-html/me_workingday-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/articles/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions docs/authors.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 18 additions & 17 deletions docs/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2e0406c

Please sign in to comment.