如何修复 cv.zipath 中的 "variable length differ" 错误?

How to fix "variable length differ" error in cv.zipath?

尝试运行使用mpath 包中的cv.zipath对零膨胀泊松模型进行交叉验证。

安装 LASSO
fit.lasso = zipath(estimation_sample_nomiss ~ .| ., 
             data = missings, 
             nlambda = 100, 
             family = "poisson", 
             link = "logit")
交叉验证
n <- dim(docvisits)[1]
K <- 10
set.seed(197)
foldid <- split(sample(1:n), rep(1:K, length = n))
fitcv <- cv.zipath(F_time_unemployed~ . | ., 
    data = estimation_sample_nomiss, family = "poisson",
                      nlambda = 100, lambda.count = fit.lasso$lambda.count[1:30],
                      lambda.zero = fit.lasso$lambda.zero[1:30], maxit.em = 300,
                      maxit.theta = 1, theta.fixed = FALSE, penalty = "enet",
                      rescale = FALSE, foldid = foldid)

我遇到以下错误:

Error in model.frame.default(formula = F_time_unemployed ~ . + ., data = list(: variable lengths differ (found for '(weights)')

我已经清理了所有 NA 的示例,但仍然遇到错误消息。

解决方案原来是 cv.zipath() 命令不接受 tibble 数据格式 - 至少在这种情况下。 (无法保证如何概括此陈述)。使用 dplyr 命令后,需要转换回数据帧。因此,解决方案就像as.dataframe()一样简单。