if (FALSE) {
# EXAMPLE 1 (INTERFACE=FORMULA): For this example, we load Giovanni
# Baiocchi's Italian GDP panel (see Italy for details), and compute the
# cross-validated bandwidths (default) using a second-order Gaussian
# kernel (default). Note - this may take a minute or two depending on
# the speed of your computer.
data("Italy")
attach(Italy)
# First, compute the bandwidths.
bw <- npcdistbw(formula=gdp~ordered(year))
# Next, compute the condistribution object...
Fhat <- npcdist(bws=bw)
# The object Fhat now contains results such as the estimated cumulative
# conditional distribution function (Fhat$condist) and so on...
summary(Fhat)
# Call the plot() function to visualize the results (-C will
# interrupt on *NIX systems, will interrupt on MS Windows
# systems).
plot(bw)
detach(Italy)
# EXAMPLE 1 (INTERFACE=DATA FRAME): For this example, we load Giovanni
# Baiocchi's Italian GDP panel (see Italy for details), and compute the
# cross-validated bandwidths (default) using a second-order Gaussian
# kernel (default). Note - this may take a minute or two depending on
# the speed of your computer.
data("Italy")
attach(Italy)
# First, compute the bandwidths.
# Note - we cast `X' and `y' as data frames so that plot() can
# automatically grab names (this looks like overkill, but in
# multivariate settings you would do this anyway, so may as well get in
# the habit).
X <- data.frame(year=ordered(year))
y <- data.frame(gdp)
bw <- npcdistbw(xdat=X, ydat=y)
# Next, compute the condistribution object...
Fhat <- npcdist(bws=bw)
# The object Fhat now contains results such as the estimated cumulative
# conditional distribution function (Fhat$condist) and so on...
summary(Fhat)
# Call the plot() function to visualize the results (-C will
# interrupt on *NIX systems, will interrupt on MS Windows systems).
plot(bw)
detach(Italy)
# EXAMPLE 2 (INTERFACE=FORMULA): For this example, we load the old
# faithful geyser data from the R `datasets' library and compute the
# conditional distribution function.
library("datasets")
data("faithful")
attach(faithful)
# Note - this may take a few minutes depending on the speed of your
# computer...
bw <- npcdistbw(formula=eruptions~waiting)
summary(bw)
# Plot the conditional cumulative distribution function (-C will
# interrupt on *NIX systems, will interrupt on MS Windows
# systems).
plot(bw)
detach(faithful)
# EXAMPLE 2 (INTERFACE=DATA FRAME): For this example, we load the old
# faithful geyser data from the R `datasets' library and compute the
# cumulative conditional distribution function.
library("datasets")
data("faithful")
attach(faithful)
# Note - this may take a few minutes depending on the speed of your
# computer...
# Note - we cast `X' and `y' as data frames so that plot() can
# automatically grab names (this looks like overkill, but in
# multivariate settings you would do this anyway, so may as well get in
# the habit).
X <- data.frame(waiting)
y <- data.frame(eruptions)
bw <- npcdistbw(xdat=X, ydat=y)
summary(bw)
# Plot the conditional cumulative distribution function (-C will
# interrupt on *NIX systems, will interrupt on MS Windows systems)
plot(bw)
detach(faithful)
}
Run the code above in your browser using DataLab