| ad | R Documentation | 
Auxiliary function used to define adaptive smooth terms in a sop model formula. The function does not do any fitting but is used as part of a sop() model formula.
ad(..., nseg = 10, pord = 2, degree = 3, nseg.sp = 5, degree.sp = 3)
| ... | the x-variable (continuous) to be used for adaptive smoothing. Currently, only one dimensional adaptive smoothers are allowed. | 
| nseg | the number of segments for the B-spline basis used to represent the smooth term. The default value is 10. | 
| pord | penalty order. The defauly value is 2 (second order penalty). | 
| degree | the order of the polynomial for the B-spline basis for this term. The default value is 3 (cubic B-splines). | 
| nseg.sp | the number of segments for the B-spline basis used to ‘smooth’ the smoothing parameters. The default value is 5. | 
| degree.sp | the order of the polynomial for the B-spline basis used for smoothing of the smoothing parameters. The default value is 3 (cubic B-splines). | 
The function ad() can be use to fit an adaptive smooth function of x.
An ‘adaptive’  smooth function is one in which the smoothing parameter is allowed to vary over the range of the explanatory variable x. Details can be found in Rodriguez-Alvarez at. al (2019).  
The function is interpreted in the formula of a sop model and creates the right framework for fitting the adaptive smoother. List containing the following objects:
| vars | name of the covariates involved in the adaptive smooth term. | 
| nseg | the number of segments for the B-spline basis. | 
| pord | the penalty order. | 
| degree | the order of the polynomial for the B-Spline basis for this term. | 
| nseg.sp | the number of segments for the B-spline basis used to ‘smooth’ the smoothing parameters. | 
| degree.sp | the order of the polynomial for the B-spline basis used for smoothing of the smoothing parameters. | 
| dim | The dimension of the smoother - i.e. the number of covariates that it is a function of. | 
| label | labels terms. | 
Rodriguez-Alvarez, M.X., Durban, M., Lee, D. J. and Eilers, P. (2019). On the estimation of variance parameters in non-standard generalised linear mixed models: application to penalised smoothing. Statistics and Computing, 29 (3), 483–500.
f, rae, sop
library(SOP)
# Simulate the data
set.seed(123)
n <- 1000
x <- runif(n, 0.0001, 1)
doppler.function <- function(x) sin(4 / (x + 0.1)) + 1.5
mu <- doppler.function(x)
sigma <- 0.2
y <- mu + sigma*rnorm(n)
dat <- data.frame(x = x, y = y)
# Fit the models
# With addaptive smoothing
m0 <- sop(formula = y ~ ad(x, nseg = 197, nseg.sp = 17), data = dat, 
         control =  list(trace = FALSE, epsilon = 1e-03))
# Without addaptive smoothing
m1 <- sop(formula = y ~ f(x, nseg = 197), data = dat, 
         control =  list(trace = FALSE, epsilon = 1e-03))         
# Plot results
plot(y ~ x, data = dat)
ox <- order(dat$x)
lines(fitted(m0)[ox] ~ dat$x[ox], col = 2, lwd = 2)
lines(fitted(m1)[ox] ~ dat$x[ox], col = 4, lwd = 2)
legend("topright", c("Theoretical", "Adaptive", "Non Adaptive"), 
    col = c(1,2,4), lty = 1, lwd = 2, bty = "n")	
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.