Learn R Programming

itsadug (version 2.5)

derive_timeseries: Derive the time series used in the AR1 model.

Description

Derive the time series used in the AR1 model.

Usage

derive_timeseries(model, AR.start = NULL)

Value

A vector with time series indication based on the AR1 model.

Arguments

model

GAMM model that includes an AR1 model.

AR.start

Vector with AR.start information, necessary for the AR1 model. Optional, defaults to NULL.

Author

Jacolien van Rij

See Also

Other functions for model criticism: acf_n_plots(), acf_plot(), acf_resid(), resid_gam(), start_event(), start_value_rho()

Examples

Run this code
data(simdat)

# add missing values to simdat:
simdat[sample(nrow(simdat), 15),]$Y <- NA
simdat <- start_event(simdat, event=c('Subject', 'Trial'))

if (FALSE) {
# Run GAMM model:
m1 <- bam(Y ~ te(Time, Trial)+s(Subject, bs='re'), data=simdat, 
    rho=.5, AR.start=simdat$start.event)
simdat$Event <- NA
simdat[!is.na(simdat$Y),]$Event <- derive_timeseries(m1)
acf_resid(m1, split_pred=list(Event=simdat$Event))

# And this works too:
simdat$Event <- derive_timeseries(simdat$start.event)
acf_resid(m1, split_pred=list(Event=simdat$Event))

# Note that acf_resid automatically makes use of derive_timeseries:
acf_resid(m1, split_pred='AR.start')
}

Run the code above in your browser using DataLab