This function plots a dataset in a Tk window then draws the spline fit through the points. It places a line to show the predicted y from the given x value. The line can be clicked on and dragged to new x-values with the predicted y-values automatically updating. A table at the bottem of the graph shows the values and the 3 derivatives.
TkSpline(x, y, method='natural', snap.to.x=FALSE, digits=4,
col=c('blue','#009900','red','black'),
xlab=deparse(substitute(x)), ylab=deparse(substitute(y)),
hscale=1.5, vscale=1.5, wait=TRUE,
...)
The x-values of the data, should be sorted
The corresponding y-values of the data
Spline Method, passed to splinefun
Logical, if TRUE then the line will only take on the
values of x
Number of digits to print, passed to format
Colors of the prediction and other lines
Label for the x-axis, passed to plot
Label for the y-axis, passed to plot
Horizontal scaling, passed to tkrplot
Vertical scaling, passed to tkrplot
Should R wait for the window to close
Additional parameters passed to plot
If wait
is FALSE then an invisible NULL is returned, if
wait
is TRUE then an invisible list with the x and y values and
derivatives is returned.
This provides an interactive way to explore predictions from a set of
x and y values. Internally the function splinefun
is used to
make the predictions.
The x-value of the reference line can be changed by clicking and dragging the line to a new position. The x and y values are shown in the margins of the graph. Below the graph is a table with the y-value and derivatives.
# NOT RUN {
if(interactive()) {
x <- 1:10
y <- sin(x)
TkSpline(x,y, xlim=c(0,11))
}
# }
Run the code above in your browser using DataCamp Workspace