Skip to contents

This is a simple wrapper for smooth.spline() from the stats package.

Usage

fm_smooth_spline(formula, data, weights = NULL, na.action = na.omit, ...)

# S3 method for fm_smooth_spline
predict(object, newdata, ...)

Arguments

formula

A formula with only one variable on right hand side.

data

A data.frame.

weights

Case weights.

na.action

A function which indicates what should happen when the data contain NAs. na.omit is the default, na.exclude or na.fail could be useful alternative settings.

...

Passed to smooth.spline().

object

Object of class “fm_smooth_spline”.

newdata

data.frame with the data to be predicted. If missing, predictions for the model data will be returned.

Value

fm_smooth_spline() returns a list of class “fm_smooth_spline” with components

  • smooth.spline: the fitted spline, of class “smooth.spline”;

  • formula: the formula;

  • weights: the fitting weights;

  • na.action: the na.action used during data preparation;

  • call: the matched call generating the model.

Methods (by generic)

  • predict(fm_smooth_spline): predict method for class “fm_smooth_spline”.

See also

smooth.spline (package stats)

Examples

(smooth <- fm_smooth_spline(dist ~ speed, data = cars))
#> Fitted model of class ‘fm_smooth_spline’ 
#>   formula:  dist ~ speed - 1
#>   data:     cars
#>   call:     fm_smooth_spline(formula = dist ~ speed, data = cars)
#>   
#>   Smoothing Parameter  spar= 0.7801305  lambda= 0.1112206 (11 iterations)
#>   Equivalent Degrees of Freedom (Df): 2.635278
#>   Penalized Criterion (RSS): 4187.776
#>   GCV: 244.1044
newd <- data.frame(speed = seq(min(cars$speed), max(cars$speed), length.out = 100))
plot(dist ~speed, cars, col = 4)
lines(newd$speed, predict(smooth, newd), col = 2)