Statisical Modelling and Computing
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
MATH3821 Statisical Modelling and Computing
The total marks available for this assignment is 20. It will be possible to obtain a raw score above 20, however
the final mark will be the minimum of the raw mark and 20. The assignment is due on Friday July 26 at
5pm and should be submitted through the link titled “Submission link - Assignment 2” on the subject’s
Moodle page. Please combine your work into a single pdf document that includes all relevant R code.
Question 1 [3+4+2+2+5+4=20 Marks]
Let y := (y1, . . . , yn)T . In the univariate scatterplot smoothing problem, yi, i = 1, . . . , n, are responses that
depend on a single predictor xi, through the equation
yi = f(xi) + εi,
where f(·) is a general smooth function, x1 < x2 < · · · < xn, and εi, i = 1, . . . , n, are independent mean 0,
variance σ2 error terms. Our goal is to estimate f := (f(x1), . . . , f(xn))T , and we denote this estimate by
fˆ := (fˆ(x1), . . . , fˆ(xn))T . If we apply a linear smoothing method to compute fˆ , then there always exists an
n× n matrix S such that
fˆ = Sy,
which is called the smoothing matrix. The matrix S depends on x := (x1, . . . , xn)T , the smoothing method
applied, and the smoothing parameter (labelled h below).
In this question we will apply the kernel smoothing method to compute fˆ . In this method
fˆ(xi) =
n∑
j=1
wj(xi)yj , where wj(xi) =
K
(
xj−xi
h
)
∑n
k=1K
(
xk−xi
h
) .
Here h is the smoothing parameter that can be adjusted to manage the bias/variance trade-off and K is the
kernel. The above equation implies that
Sij = wj(xi) =
K
(
xj−xi
h
)
∑n
k=1K
(
xk−xi
h
) ,
where Sij is the ij-th entry of the smoothing matrix S. Below we let x = (x1, . . . , xn)T =
(0, 1/6, 2/6, . . . , 59/60, 10)T and let the kernel K be the standard normal density. The following
code computes S with h = 1.
h=1
n=61
x<-seq(from=0, to=10, length.out=n)
S<-matrix(0,nrow=n,ncol=n)
for(i in 1:n){
S[i,]<-dnorm((x-x[i])/h)/sum(dnorm((x-x[i])/h))
}
1
(a) Suppose that f(x) = x so that f = (f(x1), . . . , f(x61)) = (0, 1/6, . . . , 10)T . Compute the bias vector
b := f − E(fˆ), for h = 1, and use it to plot the bias as a function of x. Does the smoothing method
suffer from boundary bias? Explain you answer. (Hint: we can compute the bias using one of the
formulas given in lecture 14)
(b) Now suppose that f(x) = x cos(10− x) and σ2 = 16, with f = (f(x1), . . . , f(x61))T .