Professional Documents
Culture Documents
R Fourier
R Fourier
R Fourier
library(fda.usc)
data(aemet,package = "fda.usc")
names(aemet)
write.matrix(aemet, "aemet.csv")
temp = as.data.frame(aemet$temp$data,row.names=F)
phimat = eval.basis(tt,basisobj=temp_k7)
#phimat1 = eval.basis(tt,basisobj=temp_k8)
phi.frame = data.frame(cbind(phimat,tt))
plot(phi.frame)
#install.packages(melt)
#library(melt)
#melt.phi = melt(data=phi.frame,id.vars="tt")
ovi5 = eval.fd(tt,ovifourier5.fd)
ovi51 = eval.fd(tt,ovifourier51.fd)
ovi121 = eval.fd(tt,ovifourier121.fd)
oviedo =
setNames(data.frame(inv.temp[,10],ovi5,ovi51,ovi121),c("Oviedo","Fourier5","Fourier51","Fourier1
21"))
library(ggplot2)
lines(smooth.spline(tt,inv.temp[,10]),col="blue",lwd=2)
lines(tt,ovi5,col="red",lwd=2)
lines(tt,ovi51,col="green",lwd=2)
lines(tt,ovi121,col="cornflowerblue",lwd=2)
lty = 1,
lwd = 2,
lines(lowess(Minutes, Temperature, f = 0.1), col = "green") # Add lowess values with different
normalization
lty = 1,
lwd = 2,
maks<-365
for(i in c(1:365)){
ovi(i) = eval.fd(tt,ovifourier(i).fd)
** Examples
library(fda.usc)
axes=list("axesIntervals") )
plot(yearbasis3)
# Identify the months with letters
axes=list("axesIntervals", labels=monthLetters) )
plot(yearbasis3.)
plot(monthbasis)
plot(falseFourierBasis)
## Not run:
a1<-seq(0,1,by=.01)
a2=rnorm(length(a1),sd=0.2)
f1<-(sin(2*pi*a1))+rnorm(length(a1),sd=0.2)
nc<-50
np<-length(f1)
tt=1:101
S<-S.NW(tt,2)
mdata<-matrix(NA,ncol=np,nrow=50)
nb<-floor(seq(5,29,len=5))
l<-2^(-5:15)
out<-optim.basis(mdata,lambda=l,numbasis=nb,type.basis="fourier")
# out1<-optim.basis(mdata,type.CV = CV.S,lambda=l,numbasis=nb)
# out2<-optim.basis(mdata,lambda=l,numbasis=nb)
# variance calculations
y<-mdata
i<-3
z=qnorm(0.025/np)
fdata.est<-out$fdata.est
var.e<-Var.e(mdata,out$S.opt)
var.y<-Var.y(mdata,out$S.opt)
var.y2<-Var.y(mdata,out$S.opt,var.e)
upper.var.e<-out$fdata.est[["data"]][i,]-z*sqrt(diag(var.e))
lower.var.e<-out$fdata.est[["data"]][i,]+z*sqrt(diag(var.e))
dev.new()
plot(y[i,],lwd=1,ylim=c(min(lower.var.e),max(upper.var.e)))
lines(out$fdata.est[["data"]][i,],col=gray(.1),lwd=1)
lines(out$fdata.est[["data"]][i,]+z*sqrt(diag(var.y)),col=gray(0.7),lwd=2)
lines(out$fdata.est[["data"]][i,]-z*sqrt(diag(var.y)),col=gray(0.7),lwd=2)
lines(upper.var.e,col=gray(.3),lwd=2,lty=2)
lines(lower.var.e,col=gray(.3),lwd=2,lty=2)
gray(0.3)),lty=c(1,2))
## End(Not run)
###################################################
###################################################
library("fda.usc")
data("tecator")
names(tecator)
###################################################
###################################################
###################################################
###################################################
data(phoneme)
learn <- phoneme$learn
###################################################
###################################################
par(mfrow = c(1,2))
###################################################
###################################################
ind <- 11
###################################################
###################################################
###################################################
### dendogram
###################################################
dev.new()
a <- mdist[ind,ind]
b <- as.dist(a)
c2 <- hclust(b)
###################################################
###################################################
data(poblenou)
as.integer(poblenou$df$day.week) > 5]
par( mfrow=c(2, 2) )
"median.mode","median.RP"))
"median.mode","median.RP"))
plot(func.var(working),
plot(func.var(nonworking),
legend(x = 11, y = 5300, cex = 1, box.col = "white", lty = 1:3, col = 1:3,
###################################################
###################################################
###################################################
###################################################
as.integer(poblenou$df$day.week) < 6]
as.integer(poblenou$df$day.week) > 5]
out1 <- outliers.depth.trim(working, dfunc=depth.FM,
###################################################
###################################################
par(mfrow=c(1, 2))
###################################################
###################################################
tt <- absorp[["argvals"]]
# training data
y <- tecator$y$Fat[ind]
X <- absorp[ind, ]
###################################################
### fregre.basis
###################################################
nbasis=5)
###################################################
### summary.fregre.fd
###################################################
summary(res.basis1)
###################################################
### fregre.pc
###################################################
###################################################
### fregre.pc.cv
###################################################
res.pc2$pc.opt
res.pc2$MSC
###################################################
### fregre.pls
###################################################
fregre.pls(X.d1, y, l = 1:5)
###################################################
### influence measures
###################################################
pairs(mat)
###################################################
###################################################
par(mfrow=c(1, 3))
plot(res.boot1$betas.boot,
col="grey", main = "5 Fourier basis elements", ylim = yl, lty=1, lwd=2)
plot(res.boot2$betas.boot,
plot(res.boot3$betas.boot,
###################################################
### fregre.lm
###################################################
###################################################
### fregre.np
###################################################
fregre.np(X.d1, y)
###################################################
### fregre.plm
###################################################
###################################################
### prediction I
###################################################
pred.lm1<-predict.fregre.lm(res.lm1, newldata)
###################################################
###################################################
###################################################
###################################################
if (any(class(model)=="fregre.fd")) {
df <- model$df
r2 <- model$r2
else {
if (any(class(model) == "lm")) {
df <- smr$df[1]
r2 <- smr$r.squared
out <- cbind(round(df, 1), round(r2, 3), round(sr2, 3), round(MEP, 4))
out
}
tabl
## Not run:
a1<-seq(0,1,by=.01)
a2=rnorm(length(a1),sd=0.2)
f1<-(sin(2*pi*a1))+rnorm(length(a1),sd=0.2)
nc<-50
np<-length(f1)
tt=1:101
S<-S.NW(tt,2)
mdata<-matrix(NA,ncol=np,nrow=50)
mdata<-fdata(mdata)
nb<-floor(seq(5,29,len=5))
l<-2^(-5:15)
out<-optim.basis(mdata,lambda=l,numbasis=nb,type.basis="fourier")
out1<-optim.basis(mdata,type.CV = CV.S,lambda=l,numbasis=nb)
out2<-optim.basis(mdata,lambda=l,numbasis=nb)
# variance calculations
y<-mdata
i<-3
z=qnorm(0.025/np)
fdata.est<-out$fdata.est
var.e<-Var.e(mdata,out$S.opt)
var.y<-Var.y(mdata,out$S.opt)
var.y2<-Var.y(mdata,out$S.opt,var.e)
upper.var.e<-out$fdata.est[["data"]][i,]-z*sqrt(diag(var.e))
lower.var.e<-out$fdata.est[["data"]][i,]+z*sqrt(diag(var.e))
dev.new()
plot(y[i,],lwd=1,ylim=c(min(lower.var.e),max(upper.var.e)))
lines(out$fdata.est[["data"]][i,],col=gray(.1),lwd=1)
lines(out$fdata.est[["data"]][i,]+z*sqrt(diag(var.y)),col=gray(0.7),lwd=2)
lines(out$fdata.est[["data"]][i,]-z*sqrt(diag(var.y)),col=gray(0.7),lwd=2)
lines(upper.var.e,col=gray(.3),lwd=2,lty=2)
lines(lower.var.e,col=gray(.3),lwd=2,lty=2)
gray(0.3)),lty=c(1,2))
## End(Not run)