sm_density: Computation and Plotting the Log-concave Score Matching...

sm_densityR Documentation

Computation and Plotting the Log-concave Score Matching Density Estimate

Description

Based on a "LogConcaveDESM" object, evaluates and plots the (penalized) log-concave score matching density estimate.

Usage

evaluate_density(scorematching_logconcave, newx, minus_const = 0)

plot_density(
  scorematching_logconcave,
  minus_const = 0,
  plot_domain,
  plot_points_cnt = 100,
  plot_hist = FALSE,
  hist_binwidth = NULL,
  hist_alpha = 0.2
)

Arguments

scorematching_logconcave

An object of class "LogConcaveDESM", usually the output of lcd_scorematching or cv_optimal_density_estimate.

newx

A numeric vector of real numbers at which the (penalized) log-concave score matching density estimate should be evaluated.

minus_const

A numeric to be subtracted in the exponent to ensure the finite-ness of the integration result. Default is 0.

plot_domain

A numeric vector to indicate the domain of the plot.

plot_points_cnt

A numeric to indicate the number of points for evaluating and plotting. Default is 100.

plot_hist

A logical value to indicate whether to the histogram. Default is FALSE.

hist_binwidth

A numeric to indicate the bin width parameter in plotting the histogram; only works when plot_hist == TRUE. Default is NULL, under which condition the Freedman-Diaconis rule is used.

hist_alpha

A numeric to indicate the opacity in plotting the histogram; must range from 0 to 1, inclusively; only works when plot_hist == TRUE. Default is 0.2.

Value

A data frame with the first column being the sorted newx and the second column being the corresponding values of the (penalized) log-concave score matching density estimate.

A ggplot2 plot of the (penalized) log-concave score matching density estimate over the specified plot domain.

Examples

set.seed(1119)
N <- 100
data <- rnorm(N)
domain <- c(-5, 5)
result <- lcd_scorematching(data, domain, penalty_param = 1e-1)

# evaluation
evaluate_density(
scorematching_logconcave = result,
newx = seq(result$domain[1], result$domain[2], by = 0.01))

# plot
plot_density(result, minus_const = 0, plot_domain = result$domain, plot_points_cnt = 500,
plot_hist = TRUE)



zhoucx1119/LogConcaveDESM documentation built on Aug. 28, 2024, 3:25 p.m.