# Generate a data sample for the response variable
# Y and the single covariate X
set.seed(123)
N <- 1000
f_1 <- function(x) x^3
X <- sort(runif(N, min = -5, max = -3))
# Specify a model for the mean of Y to include only a component
# non-linear in X, defined by the function f_1
means <- f_1(X)
# Add (Normal) noise to the mean of Y
Y <- rnorm(N, means, sd = 0.2)
Gmod <- NGeDS(Y ~ f(X), phi = 0.9)
plot(Gmod)
# Convert GeDS fit to a cubic piecewise polynomial representation
ppoly <- PPolyRep(Gmod, n = 4)
# Invert the spline using predicted values to recover predictor values
pred_new <- Gmod$Cubic.Fit$Predicted
X_new <- PPolyInv(ppoly, pred_new)
# Compare recovered predictors to original values (differences should be near 0)
as.numeric(round(X_new - X, 4))
Run the code above in your browser using DataLab