`smooth.spline`

smooth.spline has no formula interface, which is sometimes inconvenient, if one simply wants to copy a formula of a linear model or a plot to spline.

`SmoothSpline(x, ...)`# S3 method for default
SmoothSpline(x, y = NULL, w = NULL, df, spar = NULL, cv = FALSE,
all.knots = FALSE, nknots = .nknots.smspl, keep.data = TRUE,
df.offset = 0, penalty = 1, control.spar = list(),
tol = 0.000001 * IQR(x), ...)

# S3 method for formula
SmoothSpline(formula, data, subset, na.action, ...)

- x
a vector giving the values of the predictor variable, or a list or a two-column matrix specifying x and y.

- y
responses. If

`y`

is missing or`NULL`

, the responses are assumed to be specified by`x`

, with`x`

the index vector.- w
optional vector of weights of the same length as

`x`

; defaults to all 1.- df
the desired equivalent number of degrees of freedom (trace of the smoother matrix).

- spar
smoothing parameter, typically (but not necessarily) in \((0,1]\). The coefficient \(\lambda\) of the integral of the squared second derivative in the fit (penalized log likelihood) criterion is a monotone function of

`spar`

, see the details below.- cv
ordinary (

`TRUE`

) or ‘generalized’ cross-validation (GCV) when`FALSE`

; setting it to`NA`

skips the evaluation of leverages and any score.- all.knots
if

`TRUE`

, all distinct points in`x`

are used as knots. If`FALSE`

(default), a subset of`x[]`

is used, specifically`x[j]`

where the`nknots`

indices are evenly spaced in`1:n`

, see also the next argument`nknots`

.- nknots
integer or

`function`

giving the number of knots to use when`all.knots = FALSE`

. If a function (as by default), the number of knots is`nknots(nx)`

. By default for \(n_x > 49\) this is less than \(n_x\), the number of unique`x`

values, see the Note.- keep.data
logical specifying if the input data should be kept in the result. If

`TRUE`

(as per default), fitted values and residuals are available from the result.- df.offset
allows the degrees of freedom to be increased by

`df.offset`

in the GCV criterion.- penalty
the coefficient of the penalty for degrees of freedom in the GCV criterion.

- control.spar
optional list with named components controlling the root finding when the smoothing parameter

`spar`

is computed, i.e., missing or`NULL`

, see below.**Note**that this is partly*experimental*and may change with general spar computation improvements!- low:
lower bound for

`spar`

; defaults to -1.5 (used to implicitly default to 0 in R versions earlier than 1.4).

- high:
upper bound for

`spar`

; defaults to +1.5.- tol:
the absolute precision (

**tol**erance) used; defaults to 1e-4 (formerly 1e-3).- eps:
the relative precision used; defaults to 2e-8 (formerly 0.00244).

- trace:
logical indicating if iterations should be traced.

- maxit:
integer giving the maximal number of iterations; defaults to 500.

Note that `spar`

is only searched for in the interval
\([low, high]\).

a tolerance for same-ness or uniqueness of the `x`

values. The values are binned into bins of size `tol`

and
values which fall into the same bin are regarded as the same. Must
be strictly positive (and finite).

a formula of the form `lhs ~ rhs`

where `lhs`

gives the data values and rhs the corresponding groups.

The data frame from which the formula should be evaluated.

an optional vector specifying a subset of observations to be used.

a function which indicates what should happen when the data contain NAs. Defaults to
`getOption("na.action")`

.

Other arguments to be passed to
`smooth.spline`

.

Andri Signorell <andri@signorell.net>

`smooth.spline`

, `lines.smooth.spline`

```
plot(temperature ~ delivery_min, data=d.pizza)
lines(SmoothSpline(temperature ~ delivery_min, data=d.pizza))
```

Run the code above in your browser using DataLab