In the book Functional Data Analysis with R (Ramsay&Silverman) there is described the possibility to do the "positive smoothing" if it’s needed instead of the "normal smoothing".
In the books Chapter 5.4.1 ist says:
...function w(t) is now the logarithm of the data-fitting function x(t) = exp[w(t)], and consequently is unconstrained as to its sign, while at the same time the fitting function is guaranteed to be positive. It can go as close to zero as we like by permitting the values of w(t) to be arbitrarily large negative numbers. For example, we can smooth Vancouver’s mean daily precipitation data, which can have zero but not negative values, using these commands using the function smooth.pos in R.
So as I understand, if I do smoothing with the function smooth.pos the smoothed function would not be negative or have negative values? I computed the example in the book with the Vancouvers Precipitation and the positive smoothed function is sometimes negative. (Picture smooth.pos)
"normal smooth" here I plotted the fd object.
"positive smooth" here I plotted the Wfd object.
Here the code to try it yourself.
### Constrained Smoothing from fda ##positive smoothing # library(fda) VancPrec = CanadianWeather$dailyAv[,'Vancouver','Precipitation.mm'] time = 1:365 sum(VancPrec==0) # saturated Fourier basis fbasis = create.fourier.basis(c(0,365),365) # harmonic acceleration penalty harmaccelLfd = vec2Lfd(c(0,2*pi/365,0),c(0,365)) vanprecpar = fdPar(fbasis,harmaccelLfd,lambda=1e3) # direct smoothing normalsmooth = smooth.basis(time,VancPrec,vanprecpar) plot(normalsmooth$fd, ylim=c(-1,7)) #(graphic: Unrestricted smooth) abline(h=0,lty = 2, col=4) # positive smoothing ??smooth.pos positivesmooth = smooth.pos(time,VancPrec,vanprecpar) plot(positivesmooth$Wfdobj) #(graphic: Positive smooth) ##################plot after evaluating #compare the smooths plot(time,VancPrec,col=2,xlab='day',ylab='precipitation', cex.lab=1.5,cex.axis=1.5) lines(normalsmooth$fd,col=4,lwd=2) # There is no direct plot command for positive fd objects, but the # eval.posfd function will do the exponentiation for you. ??eval.fd presvals = eval.fd(time,normalsmooth$fd) plot(presvals, ylim=c(-1,7)) abline(h=0,lty = 2, col=4) ??eval.posfd posvals = eval.posfd(time,positivesmooth$Wfdobj) plot(posvals, ylim=c(-1,7)) abline(h=0,lty = 2, col=4) #lines(time,posvals,col=5,lwd=2)
So why is it then negetaive? Also I tried the smooth.pos on my data and it produced some functions completely in the negative region. Thx.