## ---------------------------------------------------------------------------- ## R scripts for Haerdle/Mueller/Sperlich/Werwatz: "Nonparametric and ## Semiparametric Modelling", Springer Series in Statistics, 2004 ## ---------------------------------------------------------------------------- ## Script SPMlocpolyderivative ## ---------------------------------------------------------------------------- ## Description computes the derivative of food on net-income ## for the UK 1976 expenditure data. ## ---------------------------------------------------------------------------- ## Author Marlene Mueller, 2008/12/19 ## ---------------------------------------------------------------------------- x <- read.csv2("D:\\fes76.txt", dec=".") x <- x[,c("NIC","FOO")] x <- x[order(x$NIC),] library(KernSmooth) mh1 <- locpoly(x$NIC,x$FOO,degree=1,kernel="normal",bandwidth=20) mh2.1 <- locpoly(x$NIC,x$FOO,drv=1,degree=2,kernel="normal",bandwidth=20) fac <- 20 ylim <- range(c(mh1$y,fac*mh2.1$y)) plot(mh1,col="blue",type="l",ylim=ylim,main="Derivative Estimation") lines(mh2.1$x,fac*mh2.1$y,col="blue",lwd=2,lty=1) abline(a=0,b=0,col="red") legend("topleft",c("LocLin",paste("1st Deriv *",fac)),col="blue",lwd=c(1,2))