powered by
Calculates AIC and BIC for the selection of knots in a spline over values (potentially including polynomials) up to a user-defined 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)
A formula detailing the model for which smoothing is to be evaluated.
A character string identifying the variable for which smoothing is to be evaluated.
Data frame providing values of all variables in form.
form
Degree of polynomial in B-spline basis functions.
Minimum number of internal B-spline knots to be evaluated.
Maximum number of internal B-spline knots to be evaluated.
Include linear and polynomial models up to, and including degree-th order polynomials.
degree
Logical indicating whether a plot should be returned.
Statistical criterion to minimize in order to find the best number of knots - AIC, BIC or Cross-validation.
Number of groups for cross-validation
Number of iterations of cross-validation to average over. 10 is the default but in real-world 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.
plot=TRUE
# NOT RUN { library(car) NKnots(prestige ~ education + type, var="income", data=na.omit(Prestige), plot=FALSE) # }
Run the code above in your browser using DataLab