atf.mgcv.spline: Autocorrelation Guided Spline Regression

Description Usage Arguments Value Examples

View source: R/AcfGuidedSpline.R

Description

Spline optimization by residual autocorrelation analysis

Usage

1
2
3
4
5
6
7
8
atf.mgcv.spline(
  formula,
  data,
  df.range,
  spl.type = "cr",
  boxlag = 20,
  DEBUG = FALSE
)

Arguments

formula

A regression formula with an unpenalized "bs" spline term to be optimized

data

Data frame

df.range

The range of df parameter to be optimized

spl.type

The spline basis type: "cr" cubic, "tp" thin plate (default="cr")

boxlag

The lag value for the Ljung Box test (default=20)

debug

Debug mode: prints debug information when set to TRUE (default=FALSE).

Value

A list:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# Create a "iid + drift" signal
N <- 1000
drift <- sin(29.6*((1:N/N) + 0.2))/((1:N)/N + 0.2)
iid <- runif(n=N, min=-1.0, max=1.0)
y <- iid + drift
mydf <- data.frame(y=y,x=1:N)

# Add "random" covariates
mydf$cov1 <- sample(N)
mydf$cov2 <- sample(N)

# Run atf.mgcv.spline
fit <-   atf.mgcv.spline(y ~ bs(x) + cov1 + cov2, data=mydf, 3:100, DEBUG=TRUE)

# plot the "true" drift
lines(drift, col="blue")

# Plot LB p-values
plot(fit$box.pvals, type="l")

bw-dpm/AcfGuidedSpline documentation built on Dec. 19, 2021, 12:47 p.m.