Interactive

Interactive Illustrations

The following examples illustrate a range of features of kernel density estimation and regression using the `manipulate' package (note that the manipulate package only functions under RStudio, and that you may have to maximize the height of your plot pane in RStudio in order to see the full menu... to reveal the manipulate menu simply click on the tool icon on the top left of the figure produced when you source (execute) the code). 

These examples are interactive in nature, and I hope that you enjoy them! From my perspective they offer valuable pedagogical tools that can enhance one's understanding of kernel estimators. So what are you waiting for? Fire up RStudio, download an R script then run it, and kindly let me know if you have any suggestions for improvements.

  1. Create a dynamic univariate density plot with `sliders' and `pickers' that can be used to dynamically change the bandwidth, kernel function, kernel order, bandwidth type, degrees of freedom of the underlying chi-square distribution, number of observations, and overlay histograms and rugs then immediately see the impact on the resulting estimate (manipulate_density.R).

  2. Create a dynamic univariate density plot for the `Old Faithful Eruptions' data with `sliders' and `pickers' that can be used to dynamically change the bandwidth, kernel function, kernel order, bandwidth type, and overlay histograms and rugs then immediately see the impact on the resulting estimate (manipulate_eruptions.R).

  3. Create a dynamic univariate cumulative distribution plot with `sliders' and `pickers' that can be used to dynamically change the bandwidth, kernel function, kernel order, bandwidth type, degrees of freedom of the underlying chi-square distribution, number of observations, and overlay empirical distribution functions and rugs then immediately see the impact on the resulting estimate (manipulate_distribution.R).

  4. Create a dynamic bivariate density plot with `sliders' and `pickers' that can be used to dynamically change the bandwidth, kernel function, kernel order, scale factors, azimuthal viewing direction, number of training, and number of evaluation observations then immediately see the impact on the resulting estimate (manipulate_bivariate_density.R).

  5. Create a dynamic bivariate density plot for the `Old Faithful' data with `sliders' and `pickers' that can be used to dynamically change the bandwidth, kernel function, kernel order, scale factors, azimuthal viewing direction, and number of evaluation observations then immediately see the impact on the resulting estimate (manipulate_faithful_density.R).

  6. Create a dynamic bivariate cumulative distribution plot with `sliders' and `pickers' that can be used to dynamically change the bandwidth, kernel function, kernel order, scale factors, azimuthal viewing direction, number of training, and number of evaluation observations then immediately see the impact on the resulting estimate (manipulate_bivariate_distribution.R).

  7. Create dynamic multivariate regression partial plots with `sliders' that can be used to dynamically change the non-axis variable's quantile (i.e. the value at which the non-axis predictors are held fixed for constructing the plots) (manipulate_wage1.R).

  8. Create a dynamic bivariate regression plot that can be used to change the polynomial order or sine function frequency, bandwidth, degree of the underlying DGP, and number of observations to illustrate Hall & Racine (2013), "Infinite-order cross-validated local polynomial regression" (manipulate_npglpreg.Rmanipulate_npglpreg_sin.R).

  9. Create a dynamic bivariate regression plot that can be constrained using the method of Du, Parmeter and Racine (2013), "Nonparametric Kernel Regression with Multiple Predictors and Multiple Shape Constraints", (Statistica Sinica) (manipulate_constrained_local_polynomial.R). Note that this requires the np and quadprog packages to be installed (np version 0.50-2 or higher).

  10. Create a dynamic bivariate production function plot that can be constrained using the method of Du, Parmeter and Racine (2013), "Nonparametric Kernel Regression with Multiple Predictors and Multiple Shape Constraints", (Statistica Sinica) (manipulate_constrained_local_polynomial_production.R). Note that this requires the np and quadprog packages to be installed (np version 0.50-2 or higher).

  11. Create a dynamic bivariate regression plot that can be constrained using the method of Du, Parmeter and Racine (2013), "Nonparametric Kernel Regression with Multiple Predictors and Multiple Shape Constraints", (Statistica Sinica) (manipulate_constrained_spline.Rmanipulate_constrained_spline_derivative.R). Note that this requires the crs and quadprog packages to be installed.

  12. Create dynamic bivariate copula plots with `sliders' and `pickers' to determine whether to plot the copula, copula density, contours, or overlay the true DGP, among others (manipulate_copula.R). Note that that this requires that the mnormt package be installed.

  13. Use the manupulate package from within RStudio to examine complex nonlinear systems with an ensemble of methods including conditional density, conditional mean, conditional distribution, and conditional quantile estimators (manipulate_socco.Rdata.RDatafigures.R). We would like to gratefully acknowledge the generous assistance of SOCCO (Southern Ocean Carbon & Climate Observatory socco.org.za). This requires that the R package np be installed and that you place the R code and data in the same directory (make sure to change to this working directory prior to sourcing the code in RStudio).