NKnots {DAMisc}  R Documentation 
Calculates AIC and BIC for the selection of knots in a spline over values (potentially including polynomials) up to a userdefined maximum.
NKnots(
form,
var,
data,
degree = 3,
min.knots = 1,
max.knots = 10,
includePoly = FALSE,
plot = FALSE,
criterion = c("AIC", "BIC", "CV"),
cvk = 10,
cviter = 10
)
form 
A formula detailing the model for which smoothing is to be evaluated. 
var 
A character string identifying the variable for which smoothing is to be evaluated. 
data 
Data frame providing values of all variables in 
degree 
Degree of polynomial in Bspline basis functions. 
min.knots 
Minimum number of internal Bspline knots to be evaluated. 
max.knots 
Maximum number of internal Bspline knots to be evaluated. 
includePoly 
Include linear and polynomial models up to, and including

plot 
Logical indicating whether a plot should be returned. 
criterion 
Statistical criterion to minimize in order to find the best number of knots  AIC, BIC or Crossvalidation. 
cvk 
Number of groups for crossvalidation 
cviter 
Number of iterations of crossvalidation to average over. 10 is the default but in realworld applications, this should be somewhere around 200. 
A plot, if plot=TRUE
, otherwise a data frame with the degrees
of freedom and corresponding fit measure.
Dave Armstrong
data(Prestige, package="carData")
NKnots(prestige ~ education + type, var="income", data=na.omit(Prestige), plot=FALSE)