Description Usage Arguments Value Examples
View source: R/AcfGuidedSpline.R
Spline optimization by residual autocorrelation analysis
1 2 3 4 5 6 7 8 | atf.mgcv.spline(
formula,
data,
df.range,
spl.type = "cr",
boxlag = 20,
DEBUG = FALSE
)
|
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). |
A list:
"best.par" : Optimized df value
"best.pval" : Ljung-Box pvalue corresponding to best.par
"best.fit" : GAM regression object corresponding to the best.par
"box.pvals" : Vector of p-values relative to the range of parameters
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")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.