library(SOP)
# Simulate the data
set.seed(123)
n <- 1000
sigma <- 0.5
x <- runif(n)
f0 <- function(x) 2*sin(pi*x)
f <- f0(x)
y <- f + rnorm(n, 0, sigma)
dat <- data.frame(x = x, y = y)
# Fit the model
m0 <- sop(formula = y ~ f(x, nseg = 10), data = dat)
m0
Run the code above in your browser using DataLab