错误消息表明您正在使用的 mgcv 版本不支持这些扩展系列,而这些扩展系列原本由 mgcv 的 gam() 函数支持。 p>
谢天谢地,Simon Wood 现在已经从版本 1.8-19 中实现了此功能(bam() 中的扩展系列),如ChangeLog 所述:
1.8-19
** bam() 现在接受大家庭(即nb、tw、ocat 等)
当前版本是 1.8-22,它修复了与您正在寻找的功能相关的一些错误,因此请确保更新到最新版本。
这是一个从?ziP修改的例子
## function to simulated zip data
rzip <- function(gamma,theta= c(-2,.3)) {
## generate zero inflated Poisson random variables, where
## lambda = exp(gamma), eta = theta[1] + exp(theta[2])*gamma
## and 1-p = exp(-exp(eta)).
y <- gamma; n <- length(y)
lambda <- exp(gamma)
eta <- theta[1] + exp(theta[2])*gamma
p <- 1- exp(-exp(eta))
ind <- p > runif(n)
y[!ind] <- 0
np <- sum(ind)
## generate from zero truncated Poisson, given presence...
y[ind] <- qpois(runif(np,dpois(0,lambda[ind]),1),lambda[ind])
y
}
library('mgcv')
## Simulate some ziP data...
set.seed(1);n<-400
dat <- gamSim(1,n=n)
dat$y <- rzip(dat$f/4-1)
b <- bam(y ~ s(x0) + s(x1) + s(x2) + s(x3),
family = ziP(), data = dat)
这给了我以下拟合模型:
> summary(b)
Family: Zero inflated Poisson(-1.855,1.244)
Link function: identity
Formula:
y ~ s(x0) + s(x1) + s(x2) + s(x3)
Parametric coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.97426 0.04988 19.53 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Approximate significance of smooth terms:
edf Ref.df F p-value
s(x0) 2.396 2.989 2.336 0.0759 .
s(x1) 2.784 3.464 77.217 <2e-16 ***
s(x2) 7.397 8.317 59.364 <2e-16 ***
s(x3) 1.235 1.428 0.269 0.5888
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Deviance explained = 69%
fREML = 593.94 Scale est. = 1 n = 400