i have constructed a negative binomial model with gam
such as:
> nb.gam <- gam(terms(seizure.rate ~ . * age_cat , data = epilepsy_cat),
+ data = epilepsy_cat , scale=-1, family=nb(link="log"))
> summary(nb.gam)
Family: Negative Binomial(1.495)
Link function: log
Formula:
seizure.rate ~ (treatment + age_cat) * age_cat
attr(,"variables")
list(seizure.rate, treatment, age_cat)
attr(,"factors")
treatment age_cat treatment:age_cat
seizure.rate 0 0 0
treatment 1 0 1
age_cat 0 1 1
attr(,"term.labels")
[1] "treatment" "age_cat" "treatment:age_cat"
attr(,"order")
[1] 1 1 2
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>
Parametric coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 1.97716 0.29951 6.601 4.08e-11 ***
treatment -0.46457 0.39763 -1.168 0.2427
age_cat2 0.06306 0.38880 0.162 0.8712
age_cat3 0.29152 0.46737 0.624 0.5328
treatment:age_cat2 0.25385 0.53232 0.477 0.6334
treatment:age_cat3 -1.58097 0.80874 -1.955 0.0506 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
R-sq.(adj) = 0.0226 Deviance explained = 15.1%
-REML = 164.71 Scale est. = 1 n = 58
but when i try to plot this, i get an error. Two plots are produced, but i was expecting 4 plots to show up. Any ideas what is going on?
> plot(nb.gam,residuals=TRUE,col="red",shade=TRUE) # cex=1.3,ylim=c(-9,6),
Error in plot.gam(nb.gam, residuals = TRUE, col = "red", shade = TRUE) :
No terms to plot - nothing for plot.gam() to do.
> gam.check(nb.gam)
Method: REML Optimizer: outer newton
full convergence after 2 iterations.
Gradient range [-5.07631e-06,-5.07631e-06]
(score 164.7056 & scale 1).
Hessian positive definite, eigenvalue range [15.68978,15.68978].
Model rank = 6 / 6
You fitted a model without any smooths so plot.gam()
has nothing to plot. You can add all.terms = TRUE
to your plot()
call get it to plot the linear/parametric terms also.
library("mgcv")
set.seed(3)
n <- 400
dat <- gamSim(1,n=n)
g <- exp(dat$f/5)
## negative binomial data...
dat$y <- rnbinom(g,size=3,mu=g)
## same with theta estimation...
b <- gam(y ~ x0 + x1 + x2 + x3, family=nb(), data=dat)
plot(b, pages=1, all.terms = TRUE)
producing
When using gam.check()
I get four plots:
> gam.check(b)
Method: REML Optimizer: outer newton
full convergence after 2 iterations.
Gradient range [-6.590911e-05,-6.590911e-05]
(score 1109.152 & scale 1).
Hessian positive definite, eigenvalue range [113.3885,113.3885].
Model rank = 5 / 5
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.