Skip to content

Commit

Permalink
Incorporate plot functionality by Carlos
Browse files Browse the repository at this point in the history
Merge branch 'plot-feature' of https://github.com/CarlosPoses/densityratio into CarlosPoses-plot-feature

# Conflicts:
#	NAMESPACE
  • Loading branch information
thomvolker committed May 29, 2024
2 parents 3daa089 + 731382f commit 6620962
Show file tree
Hide file tree
Showing 10 changed files with 858 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.Rhistory
.RData
.Ruserdata

3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ LazyData: true
Imports:
quadprog,
Rcpp,
pbapply
pbapply,
ggplot2
LinkingTo:
Rcpp,
RcppArmadillo,
Expand Down
29 changes: 29 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Generated by roxygen2: do not edit by hand

S3method(plot,kliep)
S3method(plot,lhss)
S3method(plot,naivedensityratio)
S3method(plot,naivesubspacedensityratio)
S3method(plot,spectral)
S3method(plot,ulsif)
S3method(predict,kliep)
S3method(predict,lhss)
S3method(predict,naivedensityratio)
Expand Down Expand Up @@ -29,9 +35,32 @@ export(kmm)
export(lhss)
export(naive)
export(naivesubspace)
export(plot_bivariate)
export(plot_univariate)
export(spectral)
export(ulsif)
importFrom(Rcpp,sourceCpp)
importFrom(ggplot2,aes)
importFrom(ggplot2,facet_grid)
importFrom(ggplot2,facet_wrap)
importFrom(ggplot2,geom_histogram)
importFrom(ggplot2,geom_hline)
importFrom(ggplot2,geom_point)
importFrom(ggplot2,ggplot)
importFrom(ggplot2,ggplotGrob)
importFrom(ggplot2,labs)
importFrom(ggplot2,position_dodge2)
importFrom(ggplot2,scale_color_viridis_d)
importFrom(ggplot2,scale_colour_gradient2)
importFrom(ggplot2,scale_fill_viridis_d)
importFrom(ggplot2,scale_shape_manual)
importFrom(ggplot2,scale_x_continuous)
importFrom(ggplot2,scale_y_continuous)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_bw)
importFrom(grid,grid.draw)
importFrom(grid,grid.newpage)
importFrom(grid,nullGrob)
importFrom(parallel,detectCores)
importFrom(parallel,makeCluster)
importFrom(parallel,stopCluster)
Expand Down
50 changes: 50 additions & 0 deletions R/checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -439,3 +439,53 @@ check.newdata <- function(object, newdata) {
}
newdata
}

check.var.names <- function(vars, data){
if(!all(vars %in% names(data))) {
stop("Indicated variable (s) are not present in object. Check whether variable names are correct")
}
}

check.object.type <- function(object) {
models <- c(
"ulsif",
"kliep",
"lhss",
"spectral",
"naivedensityratio",
"naivesubspacedensityratio"
)

if (!attr(object, "class") %in% models) {
stop("Only densityratio objects can be plotted.")
}
}

check.logscale <- function(ext, logscale, tol){
if (logscale) {
# Convert values lower than tolerance to tol
negdr <- ext$dr < tol
ext$dr[negdr] <- tol
if (any(negdr)) {
warning(
paste(
"Negative estimated density ratios for", sum(negdr),
"observation(s) converted to",tol,
"before applying logarithmic transformation"
),
call. = FALSE
)
}

# Apply log transformation
ext$dr <- log(ext$dr)

# Set y axis intercept to 0
ext$yintercept <- 0
} else {
# Set y axis intercept to 1
ext$yintercept <- 1
}
return(ext)
}

Loading

0 comments on commit 6620962

Please sign in to comment.