Restricted (Natural) cubic spline - wrong equation?

  • Context: Graduate 
  • Thread starter Thread starter shockedMonkey
  • Start date Start date
  • Tags Tags
    Cubic Natural
Click For Summary
SUMMARY

The user is attempting to fit a restricted cubic spline to a dataset resembling an 'S' shape, following the methodology outlined in Hastie, Tibshirani, and Friedman’s "The Elements of Statistical Learning". The R code provided generates synthetic data with specified knots at {.2, .4, .6, .8} using the NLS() function. Despite these efforts, the user is unable to achieve the desired S-shape in the fitted model, indicating a potential issue with their equation or approach. The discussion seeks insights on correcting the spline fitting process.

PREREQUISITES
  • Understanding of restricted cubic splines and their applications in statistical modeling.
  • Proficiency in R programming, specifically with the NLS() function for non-linear least squares fitting.
  • Familiarity with the concepts presented in "The Elements of Statistical Learning" by Hastie, Tibshirani, and Friedman.
  • Basic knowledge of generating synthetic datasets and visualizing data in R.
NEXT STEPS
  • Review the implementation of restricted cubic splines in R using the 'splines' package.
  • Explore the use of the 'gam' package in R for fitting generalized additive models with splines.
  • Investigate alternative knot placements and their impact on spline fitting outcomes.
  • Learn about diagnostic techniques for evaluating spline model fits in R.
USEFUL FOR

Statisticians, data scientists, and R programmers who are involved in modeling complex relationships using splines, particularly those seeking to refine their understanding of restricted cubic splines and their implementation in R.

shockedMonkey
Messages
2
Reaction score
0
My Restricted (Natural) Cubic Spline Equation is Wrong ?

I am trying to fit a restricted cubic spline (natural cubic spline) to toy data, attempting to follow
Hastie, Tibshirani, Friedman 2nd ed. 5.2.1 p.144-146, Eqs 5.4 and 5.5.
Data: Is basically a transposed ‘S’ shape. R-code is:
n <© 100
x <- (1:n)/n
true <- ((exp(1.2*x)+1.5*sin(7*x))-1)/3
noise <- rnorm(n, 0, 0.15)
y <- true + noise
plot(x,y)

I set knots at: {.2, .4, .6, .8} and am fitting using the non-linear NLS() function in R, but I can’t get the S-shape of the data no matter what I try.

My equations is wrong ? Or I am completely off-base in my approach? Any suggestions?
(Book-excerpt, my equation, and data-plot posted below)
 

Attachments

  • book1.JPG
    book1.JPG
    16 KB · Views: 507
  • book2.JPG
    book2.JPG
    8.2 KB · Views: 529
  • splineEq.JPG
    splineEq.JPG
    8.7 KB · Views: 539
  • data.JPG
    data.JPG
    17.3 KB · Views: 485
Physics news on Phys.org
Q: Is my problem unclear? Or - is anyone aware of a better forum for my question? Thank you.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K