Skip to contents

run functions to create acf matrix and plot the results

Usage

runACF(
  block,
  model,
  store = FALSE,
  save = F,
  suppress.printout = TRUE,
  maxlag = NULL,
  printplot = TRUE
)

Arguments

block

Vector of blocks that identify data points that are correlated

model

Fitted model object (glm or gam)

store

(default=FALSE). Logical stating whether a list of the matrix of correlations is stored (output from acffunc.)

save

(default=FALSE). Logical stating whether plot should be saved into working directory.

suppress.printout

(default=TRUE. Logical stating whether to show a printout of block numbers to assess progress. FALSE will show printout.

maxlag

(default=NULL). Numeric entry to allow the restriction of the maximum lag on the plots. If NULL then the length of the longest panel is used as the maximum plotted lag.

Value

Plot of lag vs correlation. Each grey line is the correlation for each individual block in block. The red line is the mean values for each lag.

If store=TRUE then the matrix of correlations (nblocks x length_max_block) is returned and plotacf may be used to plot the acf.

Author

LAS Scott-Hayward, University of St Andrews

Examples

# load data
data(ns.data.re)

model<-gamMRSea(birds ~ observationhour + as.factor(floodebb) + as.factor(impact), 
           family='quasipoisson', data=ns.data.re)

ns.data.re$blockid<-paste(ns.data.re$GridCode, ns.data.re$Year, ns.data.re$MonthOfYear, 
                    ns.data.re$DayOfMonth, sep='')
ns.data.re$blockid<-as.factor(ns.data.re$blockid)

runACF(ns.data.re$blockid, model, suppress.printout=TRUE)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:igraph':
#> 
#>     as_data_frame, groups, union
#> The following objects are masked from 'package:raster':
#> 
#>     intersect, select, union
#> The following object is masked from 'package:MRSea':
#> 
#>     contains
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
#> Error in ggplot(): could not find function "ggplot"

# storing the output and then plotting
acfoutput <- runACF(ns.data.re$blockid, model, suppress.printout=TRUE, store=TRUE)
plotacf(acfoutput$acfmat)
#> Error in ggplot(): could not find function "ggplot"