












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
ISYE7406_HW2_2 QUESTIONS AND ANSWERS
Typology: Exams
1 / 20
This page cannot be seen from the preview
Don't miss anything!
2
3. Methodology
5. Conclusions
**_## Part #1 deterministic equidistant design
m <- 1000 n <- 101 x <- 2 piseq(- 1 , 1 , length=n) ## Initialize the matrix of fitted values for three methods fvlp <- fvnw <- fvss <- matrix( 0 , nrow= n, ncol= m) ##Generate data, fit the data and store the fitted values for (j in 1 :m){ **_## simulate y-values
n in eq. (2)** xlocal = c() for (i in 1 :n) { xlocal[i] = ( 2 * pi) * (- 1 + 2 ((i- 1 )/(n- 1 ))) } f = function () { yi = c() for (i in 1 :n) { yi[i] = ( 1 - (xlocal[i]* 2 )) * exp(-0.5(xlocal[i]* 2 )) } return(yi) } y <- f() + rnorm(length(xlocal), sd=0.2); **## Get the estimates and store them_** fvlp[,j] <- predict(loess(y ~ x, span = 0.75), newdata = x); fvnw[,j] <- ksmooth(x, y, kernel="normal", bandwidth= 0.2, x.points=x)$y; fvss[,j] <- predict(smooth.spline(y ~ x), x=x)$y } ## Below is the sample R code to plot the mean of three estimators in a singl e plot meanlp = apply(fvlp, 1 ,mean); meannw = apply(fvnw, 1 ,mean); meanss = apply(fvss, 1 ,mean); dmin = min( meanlp, meannw, meanss); dmax = max( meanlp, meannw, meanss); matplot(x, meanlp, "l", ylim=c(dmin, dmax), ylab="Response") matlines(x, meannw, col="red") matlines(x, meanss, col="blue") points(x, y)
matplot(x, y, "l", ylim=c(min(y), max(y))) points(x,y)
dmax = max(varlp, varnw, varss); matplot(x, varlp, "l", ylim=c(dmin, dmax), ylab="Variance") matlines(x, varnw, col="red") matlines(x, varss, col="blue") _#Double Check
#MSE_ mselp = replicate( 101 , 0 ) msenw = replicate( 101 , 0 ) msess = replicate( 101 , 0 ) for (i in 1 :n) { for (j in 1 :m) { mselp[i] = mselp[i] + (fvlp[i, j] - y[i])** 2 msenw[i] = msenw[i] + (fvnw[i, j] - y[i])** 2 msess[i] = msess[i] + (fvss[i, j] - y[i])** 2 }
mselp = mselp / m msenw = msenw / m msess = msess / m dmin = min(mselp, msenw, msess); dmax = max(mselp, msenw, msess); matplot(x, mselp, "l", ylim=c(dmin, dmax), ylab="MSE") matlines(x, msenw, col="red") matlines(x, msess, col="blue") #Plot min and max of NW and SS! minsv1nw = apply(fvnw, 1 , min) maxsv1nw = apply(fvnw, 1 , max) minsv1ss = apply(fvss, 1 , min) maxsv1ss = apply(fvss, 1 , max) dmin = min(minsv1nw, minsv1ss); dmax = max(maxsv1nw, maxsv1ss); matplot(x, minsv1nw, "l", ylim=c(dmin, dmax), ylab="Min/Max", col="red", lty = 'dashed') matlines(x, maxsv1nw, col="red", lty = 'dashed') #matlines(x, meannw, col="red") matlines(x, minsv1ss, col="blue", lty = 'dashed') matlines(x, maxsv1ss, col="blue", lty = 'dashed')
meanss = apply(fvss, 1 ,mean); dmin = min( meanlp, meannw, meanss); dmax = max( meanlp, meannw, meanss); matplot(x, meanlp, "l", ylim=c(dmin, dmax), ylab="Response") matlines(x, meannw, col="red") matlines(x, meanss, col="blue") points(x,y) matplot(x, y, "l", ylim=c(min(y), max(y))) points(x,y)
biaslp = meanlp - y biasnw = meannw - y biasss = meanss - y dmin = min(biaslp, biasnw, biasss); dmax = max(biaslp, biasnw, biasss); matplot(x, biaslp, "l", ylim=c(dmin, dmax), ylab="Response") matlines(x, biasnw, col="red") matlines(x, biasss, col="blue")
_#Double Check
#MSE_ mselp = replicate( 101 , 0 ) msenw = replicate( 101 , 0 ) msess = replicate( 101 , 0 ) for (i in 1 :n) { for (j in 1 :m) { mselp[i] = mselp[i] + (fvlp[i, j] - y[i])** 2 msenw[i] = msenw[i] + (fvnw[i, j] - y[i])** 2 msess[i] = msess[i] + (fvss[i, j] - y[i])** 2 } } mselp = mselp / m msenw = msenw / m msess = msess / m
dmin = min(mselp, msenw, msess); dmax = max(mselp, msenw, msess); matplot(x, mselp, "l", ylim=c(dmin, dmax), ylab="Response") matlines(x, msenw, col="red") matlines(x, msess, col="blue")