0
library(zoo)
library(glmnet)
我可以得到一個線性迴歸滾動係數:[R rollapply上glmnet
seat <- as.zoo(log(UKDriverDeaths))
time(seat) <- as.yearmon(time(seat))
seat <- merge(y = seat, y1 = lag(seat, k = -1),
y12 = lag(seat, k = -12), all = FALSE)
tail(seat)
fm <- rollapply(seat, width = 50,
FUN = function(z) coef(lm(y ~ y1 + y12, data = as.data.frame(z))),
by.column = FALSE, align = "right")
,但我有麻煩的滾動係數glmnet:
fm <- rollapply(seat, width = 50,
FUN = function(z) coef(cv.glmnet(z[,c(2,3)],z[,1],alpha=1, data =
as.data.frame(z))), by.column = FALSE, align = "right")
謝謝你任何幫助
請讓您的示例具有可重現性,並明確說明是什麼給了您這個問題。它是否給出錯誤?如果包含錯誤... – Dason