## a)

``````

In [1]:

require('MASS')

``````
``````

``````
``````

In [2]:

par(mfrow=c(2,2))
hist(geyser\$waiting, prob=TRUE, xlab="s", ylab="", main="Waiting + Gaussian + Scott's")
lines(density(geyser\$waiting, bw="nrd", kernel="gaussian"))
hist(geyser\$waiting, prob=TRUE, xlab="s", ylab="", main="Waiting + Epanechnikov + Scott's")
lines(density(geyser\$waiting, bw="nrd", kernel="epanechnikov"))
hist(geyser\$waiting, prob=TRUE, xlab="s", ylab="", main="Waiting + Gaussian + BCV")
lines(density(geyser\$waiting, bw="ucv", kernel="gaussian"))
hist(geyser\$waiting, prob=TRUE, xlab="s", ylab="", main="Waiting + Epanechnikov + UCV")
lines(density(geyser\$waiting, bw="ucv", kernel="epanechnikov"))

``````
``````

``````
``````

In [3]:

par(mfrow=c(2,2))
hist(geyser\$duration, prob=TRUE, xlab="s", ylab="", main="Duration + Gaussian + Scott's")
lines(density(geyser\$duration, bw="nrd", kernel="gaussian"))
hist(geyser\$duration, prob=TRUE, xlab="s", ylab="", main="Duration + Epanechnikov + Scott's")
lines(density(geyser\$duration, bw="nrd", kernel="epanechnikov"))
hist(geyser\$duration, prob=TRUE, xlab="s", ylab="", main="Duration + Gaussian + UCV")
lines(density(geyser\$duration, bw="bcv", kernel="gaussian"))
hist(geyser\$duration, prob=TRUE, xlab="s", ylab="", main="Duration + Epanechnikov + BCV")
lines(density(geyser\$duration, bw="bcv", kernel="epanechnikov"))

``````
``````

``````

## b)

``````

In [4]:

COL <- gray(30:100 /100)

``````
``````

In [5]:

old.par <- par(mfrow=c(2,2))
plot(geyser\$waiting, geyser\$duration, xlab="waiting", ylab="duration", main="Scatterplot")
f1 <- kde2d(geyser\$waiting, geyser\$duration, n=50)
image(f1, xlab="waiting", ylab="duration", main="Scott's normal rule", col=COL)
f2 <- kde2d(geyser\$waiting, geyser\$duration, n=50, h=c(width.SJ(geyser\$waiting), width.SJ(geyser\$duration)))
image(f2, xlab="waiting", ylab="duration", main="Sheather-Jones's method", col=COL)

``````
``````

``````