简体   繁体   中英

check_resid() function in itsadug package visualizing results of bam function in mgcv package returns error

I am going through the tutorial "Overview GAMM analysis of time series data" ( http://www.sfs.uni-tuebingen.de/~jvanrij/Tutorial/GAMM.html )

I fit a model with the following code:

m1 <- bam(Y ~ Group 
        + s(Time, by=Group) 
        + s(Condition, by=Group, k=5) 
        + ti(Time, Condition, by=Group)
        + s(Time, Subject, bs='fs', m=1)
        + s(Trial, Subject, bs='fs', m=1),
        data=simdat)

The I run the following command from the itsadug package:

check_resid(m1, split_pred=c("Subject", "Trial") )

This returns an exception:

Warning message in is.na(res.rho):
"is.na() applied to non-(list or vector) of type 'NULL'"
Error in ts(x): 'ts' object must have one or more observations
Traceback:

1. check_resid(m1, split_pred = c("Subject", "Trial"))
2. acf(res, main = sprintf("ACF resid(%s)", deparse(substitute(model))), 
 .     col = "darkgray", ylim = range(c(0, acf(res, plot = FALSE)$acf[, 
 .         , 1], acf(res.rho[!is.na(res.rho)], plot = FALSE)$acf[, 
 .         , 1]), na.rm = TRUE), bty = "L")
3. plot.acf(acf.out, ...)
4. acf(res.rho[!is.na(res.rho)], plot = FALSE)
5. na.action(as.ts(x))
6. as.ts(x)
7. as.ts.default(x)
8. ts(x)
9. stop("'ts' object must have one or more observations")

The first two plots only are produced (instead of 4).

I checked the documentation of the command and perhaps this is relevant:

AR_start

Defaults to NULL. Only use this when the model was run in an old versions of package mgcv and the function cannot retrieve the used AR.start values from the model. When an error is shown with newer versions of mgcv, please check the column provided as values of AR.start. when using old versions of package mgcv. Function will give error when it cannot find AR.start.

How can I correct the problem?

The correct syntax (see the help ?check_resid ) is:

check_resid(m1, split_by=c("Subject", "Trial") )

and the output is:

在此处输入图像描述

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM