Video Demos

Short, reproducible video demonstrations for np and npRmpi, with captions, transcripts, and exact R scripts.
Keywords

video demos, RStudio, np, npRmpi, reproducible examples

These short demonstrations show the finished result quickly, then reveal the few essential R statements needed to reproduce it. Every entry includes captions, a transcript, the exact installed-build script, and direct download links. Longer installation and platform instructions remain on Install and Get Started.

Onboarding and first results

Function: npreg()
Takeaway: one call selects the smoothing parameter and fits the relationship.

R is the computational environment; RStudio is the interface used here to write and run the analysis. This walkthrough moves from loading np to a fitted curve using the package’s bundled wage data.

Open or download the MP4 · Download the captions · Read the transcript

Install the public package once:

install.packages("np")

Then run the exact demonstrated analysis:

## Your first np result.
## Last verified with the public CRAN np 0.70-5 build.

library(np)
data(cps71, package = "np")

fit_first <- npreg(logwage ~ age, data = cps71)
summary(fit_first$bws)
plot(fit_first, main = "A first np regression")

Download the R script.

The example uses public CRAN np 0.70-5 and the 205 observations in the bundled cps71 data. No seed is needed because the example neither simulates nor resamples data. Least-squares cross-validation selects an age bandwidth of 1.892158 in the verified installed build.

Transcript

R is the computing environment, and RStudio is where we work.

Install np once, load it, and use the bundled wage data.

One npreg() call selects the smoothing parameter and fits the relationship.

The summary records the selected bandwidth. The plot shows the result.

Your first reproducible np analysis is complete, and the full script is on the Gallery Video Demos page.

Once this works, continue to Data Preparation to learn how continuous, unordered, and ordered variables should be represented before using your own data.

Analytical demonstrations

The Italy sequence uses the same public dataset to connect conditional density, conditional distribution, and direct conditional quantiles without turning any one short into a full theoretical treatment. See How the four targets connect for the population definitions and the important target-specific smoothing distinction.

Function: npcdens()
Takeaway: the entire conditional density can change shape, not merely its average.

The bundled Italy data follow per-capita GDP in 21 regions over 48 observed years from 1951 through 1998. year is already an ordered factor, so the estimator respects its ordered discrete support. The estimated density is mainly unimodal after the war and develops two clear peaks in later years, corresponding descriptively to the wealthier North and less wealthy South.

Open or download the MP4 · Download the captions · Read the transcript

## Italy conditional-density short.
## Last verified with the public CRAN np 0.70-5 build.

library(np)
data(Italy, package = "np")

class(Italy$year)
fit_cdens <- npcdens(gdp ~ year, data = Italy)
summary(fit_cdens$bws)
plot(fit_cdens, view = "fixed", theta = 90, phi = 45)

Download the R script.

The verified public CRAN np 0.70-5 build selected an ordered-year smoothing parameter of 0.613508 and a GDP bandwidth of 0.570879. No seed is needed. These values are selected for the conditional-density target.

Transcript

Per-capita GDP across 21 Italian regions begins mainly unimodal after the war.

Here, year is an ordered factor, so npcdens() smooths across observed year levels.

Across later years, two clear peaks emerge, corresponding to the wealthier North and less wealthy South.

One call reveals the whole conditional density, not merely an average.

The full script is on Gallery Video Demos.

Function: npcdist()
Takeaway: for each ordered year and GDP value, the surface estimates the share of regions at or below that value.

Integrating a conditional density gives the conditional distribution at the population level. This episode estimates the conditional distribution directly. It does not obtain the fitted surface by numerically integrating the preceding video’s density estimate.

Open or download the MP4 · Download the captions · Read the transcript

## Italy conditional-distribution short.
## Last verified with the public CRAN np 0.70-5 build.

library(np)
data(Italy, package = "np")

class(Italy$year)
fit_cdist <- npcdist(gdp ~ year, data = Italy)
summary(fit_cdist$bws)
plot(fit_cdist, view = "fixed", theta = 90, phi = 45)

Download the R script.

The verified public build selected an ordered-year smoothing parameter of 0.687927 and a GDP bandwidth of 0.307366 for the conditional-distribution target. Five fresh installed runs were exactly identical for the selected bandwidth object and fitted result. No seed is needed.

Transcript

Integrating the conditional density produces the conditional distribution.

Here, for each ordered year, the surface gives the estimated share of Italian regions with per-capita GDP at or below each value.

One npcdist() call estimates the whole conditional distribution.

Invert the conditional distribution at a chosen probability and you obtain a conditional quantile.

The full script is on Gallery Video Demos.

Function: npqreg()
Takeaway: choose probabilities and invert the fitted conditional distribution to obtain the corresponding conditional quantiles.

This example requests the 25th, 50th, and 75th conditional quantiles of regional GDP for each ordered year. The default plot overlays those curves on the observed per-year distributions.

Open or download the MP4 · Download the captions · Read the transcript

## Italy conditional-quantile short.
## Last verified with the public CRAN np 0.70-5 build.

library(np)
data(Italy, package = "np")

class(Italy$year)
fit_qreg <- npqreg(gdp ~ year,
                   data = Italy,
                   tau = c(0.25, 0.50, 0.75))
summary(fit_qreg$bws)
plot(fit_qreg)

Download the R script.

npqreg() first computes bandwidths optimized for the conditional-distribution target, estimates that distribution, and then inverts it at the requested \(\tau\in(0,1)\) values. With the same data and selection settings, the verified bandwidth values match the preceding npcdist() example. This is a distribution-based quantile route. nplsqreg() is a separate, regression-based location-scale method. No seed is needed.

Transcript

Choose a probability, tau, and invert the fitted conditional distribution. The result is the GDP value where that distribution reaches tau. Here, one npqreg() call directly traces the 25th, 50th, and 75th conditional quantiles across Italy’s ordered years. The curves show the lower, middle, and upper parts of the distribution. The full script is on Gallery Video Demos.

The next pair uses the built-in faithful data to compare two unconditional bivariate targets and to demonstrate the interactive rgl renderer in RStudio’s Viewer.

Function: npudens()
Takeaway: target-specific smoothing reveals two distinct eruption cycles in a manipulable joint-density surface.

The datasets::faithful data contain 272 observations of Old Faithful eruption duration in minutes and the waiting time to the next eruption. The two peaks correspond to short eruptions followed by shorter waits and long eruptions followed by longer waits.

Open or download the MP4 · Download the captions · Read the transcript

## Old Faithful joint-density short.
## Last verified with the public CRAN np 0.70-5 build.

library(np)
data(faithful, package = "datasets")

fit_udens <- npudens(~ eruptions + waiting, data = faithful)
summary(fit_udens$bws)
plot(fit_udens, renderer = "rgl")

Download the R script.

The verified public CRAN np 0.70-5 build selected bandwidths of 0.146981 for eruptions and 2.925689 for waiting, optimized for the joint-density target. No seed is needed. With renderer = "rgl", the fitted surface opens in RStudio’s Viewer, where it can be rotated, zoomed, and resized.

Transcript

Old Faithful’s 272 observations contain measurements of eruption duration and waiting time. One npudens call selects bandwidths optimized for the joint-density target and reveals two distinct peaks: short eruptions with shorter waits, and long eruptions with longer waits. The surface opens in RStudio’s Viewer, where you can drag to rotate, scroll to zoom, and resize the pane. Find the full script in Gallery Video Demos.

Function: npudist()
Takeaway: the same data can be viewed cumulatively with smoothing selected for the joint-distribution target.

At each eruption-duration and waiting-time pair, the fitted surface estimates the probability of observing values at or below both coordinates. npudist() estimates this joint distribution directly; it does not integrate the fitted joint-density object from the preceding video.

Open or download the MP4 · Download the captions · Read the transcript

## Old Faithful joint-distribution short.
## Last verified with the public CRAN np 0.70-5 build.

library(np)
data(faithful, package = "datasets")

fit_udist <- npudist(~ eruptions + waiting, data = faithful)
summary(fit_udist$bws)
plot(fit_udist, renderer = "rgl")

Download the R script.

The verified public build selected bandwidths of 0.0576794 for eruptions and 0.186285 for waiting, optimized for the joint-distribution target. Five fresh installed runs were exactly identical for each estimator’s selected bandwidth object and fitted result. No seed is needed.

Transcript

The same 272 Old Faithful observations can be viewed cumulatively. One npudist call selects bandwidths optimized for the joint-distribution target and estimates the probability at or below each eruption-duration and waiting-time pair. This object is estimated directly, not by integrating the density. It opens in RStudio’s Viewer, where you can rotate, zoom, and resize the surface. Find the full script in Gallery Video Demos.

The next reviewed episode returns to regression with NOMAD joint selection of polynomial degree and bandwidth, followed by bootstrap uncertainty for the fitted curve and its derivatives. Testing and npRmpi session workflows will follow one reviewed example at a time.

Back to top