cv.glmnet 中有偏移量的泊松误差

Error in cv.glmnet for poisson with an offset

我在尝试 运行 使用 offset.

在 glmnet 上对 family = poisson 进行交叉验证时遇到错误

我设法用下面这个非常简单的例子重现了这个错误:

library(glmnet)

#poisson
N=500; p=20
nzc=5
x=matrix(rnorm(N*p),N,p)
beta=rnorm(nzc)
f = x[,seq(nzc)]%*%beta
mu=exp(f)
y=rpois(N,mu)
exposure=rep(0.5,length(y))

#cross validation
cv=cv.glmnet(x,y,family="poisson",offset=log(exposure),nlambda=50,nfolds=3)

其中returns出现以下错误:

Error: No newoffset provided for prediction, yet offset used in fit of glmnet

我不知道我做错了什么。并且无法在互联网上找到任何帮助。有人有想法吗?

非常感谢!

EDIT : this issue is obsolete, and was linked to the version 2.0-12 of the glmnet package - fixed when updating to version 2.0-13

这个有效: predict(cv,x,newoffset=log(exposure))

来自 glmnetoffset 参数的文档:

If supplied, then values must also be supplied to the predict function.