0
> t<-seq(0,1,len=5)
> x<-matrix(c(1.3,2.3,21,2.4,3.8,9,4.5,11.3,4.2,7.8),2)
> s1 <- splinefun(t, colMeans(x), method = "monoH.FC")
> plot(s1)

I have used a simple example to use the build in Hermite spline function(which is splinefun). So I used it and plot the s1, it gives the plot that I was expecting. But my question: is there any way to get points from the function that they use to plot s1. I think it's probably infinite, but if I want 20 points of s1 function corresponding to 20 t points. how could I get that. FYI s1 returns the built in function, not any points or numeric value and you need fda package to run splinefun.

Antora
  • 21
  • 3
  • I doubt that there is a function in the stats package named `splinefunion`. Furthermore you seems to be asking how to build or understand some sort of spline function and that's more a mathematical or statistics methods question and those are not on-topic for SO. I voted to migrate to the Statistics forum but you could raise a flag to have it go to the Math forum. Once you have a well-defined algorithm then do some searching to see if its already been done and if not then come back here with a better question for SO. – DWin Apr 26 '19 at 22:18
  • If you are talking about a function whose documentation is at https://stat.ethz.ch/R-manual/R-patched/library/stats/html/splinefun.html then what problems are you having in getting the code and exactly where are you having trouble with its interpretation? – DWin Apr 26 '19 at 22:27
  • 1
    Groan. Please read [MCVE]. And probably the rest of the the help pages including [ask]. We cannot possibly reproduce results with that code. Consider using a simple example and do not load every package ... only load the ones needed. `splinefunH` is in the `stats`package and is loaded by default. – DWin Apr 26 '19 at 23:40
  • Isn't this question answered at https://stats.stackexchange.com/questions/97845/interpreting-spline-results/101484#101484? – whuber May 01 '19 at 21:02

1 Answers1

1

The default type of spline with splinefun is "fmm" and the help page says:

If method = "fmm", the spline used is that of Forsythe, Malcolm and Moler (an exact cubic is fitted through the four points at each end of the data, and this is used to determine the end conditions).

Your original question seemed to be how splinefunH was calculated, which is arguably why your question was migrated. At the moment it appears more appropriate for SO but migrating back again might not be feasible. As I read your current question it is how to use s1 as a function:

> t2 <- seq(0,1,len=20)
> s1(t2)
 [1]  1.800000  4.150139  6.748476  9.169529 10.987812
 [6] 11.771133 11.217641  9.785187  8.089605  6.746727
[11]  6.288234  6.487039  7.011022  7.574661  7.892433
[16]  7.790348  7.449832  6.974486  6.459484  6.000000

If in the other hand your question is really about where the parameters of that cubic spline are to be found. To see the function code of s1 just type its name:

 s1

It is sometimes the case that functional objects store their parameters in their environments:

> ls(environment(s1))
[1] "dx" "m"  "x0" "y0"

[1] 0.25 0.25 0.25 0.25
> environment(s1)$m
[1] 39.6  9.2 -7.6 -0.8 -7.6
> environment(s1)$x0
[1] 0.00 0.25 0.50 0.75 1.00
> environment(s1)$y0
[1]  1.8 11.7  6.4  7.9  6.0
DWin
  • 7,005
  • 17
  • 32
  • Thanks, is it possible to get other way around. Like for fixed function values(s1), I want to get corresponding t values? – Antora May 02 '19 at 04:27
  • When functions are non- monotonic as yours is currently there won’t be a general inverse. You would need to pick out a domain in which there was monotonic behavior. – DWin May 02 '19 at 14:12