set.seed(2000)
N<-50;M<-24
N<-30;M<-12
X<-rnorm(N,mean=0)
time<-seq(0,1,length.out=M)
Y<-simulate_simple_dfrr(beta0=function(t){cos(pi*t+pi)},
beta1=function(t){2*t},
X=X,time=time)
#The argument T_E indicates the number of EM algorithm.
#T_E is set to 1 for the demonstration purpose only.
#Remove this argument for the purpose of converging the EM algorithm.
dfrr_fit<-dfrr(Y~X,yind=time,T_E=1)
coefs<-coef(dfrr_fit,return.fourier.coefs=TRUE)
basis<-basis(dfrr_fit)
evaluated_coefs<-coefs%*%t(fda::eval.basis(time,basis))
#Plotting the regression coefficients
oldpar<-par(mfrow=c(1,2))
plot(time,evaluated_coefs[1,],'l',main="Intercept")
plot(time,evaluated_coefs[2,],'l',main="X")
par(oldpar)
Run the code above in your browser using DataLab