我在R(包fda
)中进行功能回归,我应该消除拦截术语。但是R中的fda包似乎没有这样的公式。
这是我想做的事情:
fit.fd <- fRegress(Acc.fd~Velo.fd - 1)
其中Acc.fd
和Velo.fd
是包fda中的两个功能对象。但它与以下内容没有什么不同:
fit.fd <- fRegress(Acc.fd~Velo.fd)
由于结果是深度嵌套的,我正在添加一个示例,因此代码可以小规模运行,并且可以生成结果的详细信息。
list3d <- rep(0, 10*5*2)
list3d <- array(list3d, c(10,5, 2))
# The data is 5 functions each evaluated at 10 points
# Indep variable
list3d[, , 2] <- matrix(rnorm(50, 0, 1), 10, 5)
# Response variable
list3d[, , 1] <- matrix(rnorm(50, 0, 0.1) , 10, 5)+list3d[, , 2] ^ 2
dimnames(list3d)[[1]] <- seq(0,9)
time.range <- c(0, 9)
time.basis <- create.fourier.basis(time.range, nbasis = 3)
lfd <- vec2Lfd(c(0, (2*pi/20)^2, 0), rangeval = time.range)
time.lfd<- smooth.basisPar(seq(0,9), list3d , time.basis, Lfdobj = lfd, lambda = 0.01)$fd
Acc.fd <- time.lfd[, 1]
Velo.fd <- time.lfd[, 2]
# Expecting to see without intercept here
fit.fd <- fRegress(Acc.fd ~ Velo.fd - 1)
# plot of coef func
plot(plotpoints, eval.fd(plotpoints, fit.fd$betaestlis$Velo.fd$fd))
# Plot of intercept func, I wish to limit it to zero
plot(plotpoints, eval.fd(plotpoints, fit.fd$betaestlis$const$fd))
# Compare with regular functional regression with no restriction
fit.fd <- fRegress(Acc.fd ~ Velo.fd)
plot(plotpoints, eval.fd(plotpoints, fit.fd$betaestlis$Velo.fd$fd))
list3d <- rep(0, 10*5*2)
list3d <- array(list3d, c(10,5, 2))
# The data is 5 functions each evaluated at 10 points
# Indep variable
list3d[, , 2] <- matrix(rnorm(50, 0, 1), 10, 5)
# Response variable
list3d[, , 1] <- matrix(rnorm(50, 0, 0.1) , 10, 5)+list3d[, , 2] ^ 2
dimnames(list3d)[[1]] <- seq(0,9)
time.range <- c(0, 9)
time.basis <- create.fourier.basis(time.range, nbasis = 3)
lfd <- vec2Lfd(c(0, (2*pi/20)^2, 0), rangeval = time.range)
time.lfd<- smooth.basisPar(seq(0,9), list3d , time.basis, Lfdobj = lfd, lambda = 0.01)$fd
Acc.fd <- time.lfd[, 1]
Velo.fd <- time.lfd[, 2]
# Expecting to see without intercept here
fit.fd <- fRegress(Acc.fd ~ Velo.fd - 1)
# plot of coef func
plot(plotpoints, eval.fd(plotpoints, fit.fd$betaestlis$Velo.fd$fd))
# Plot of intercept func, I wish to limit it to zero
plot(plotpoints, eval.fd(plotpoints, fit.fd$betaestlis$const$fd))
# Compare with regular functional regression with no restriction
fit.fd <- fRegress(Acc.fd ~ Velo.fd)
plot(plotpoints, eval.fd(plotpoints, fit.fd$betaestlis$Velo.fd$fd))
所以no intercept选项与中的工作方式不同?有人能帮帮我吗?非常感谢!