For use in model formulas,
natural cubic spline as in
but with knot positions chosen using
k-means rather than quantiles.
Automatically uses less knots if there are insufficient distinct values.
The predictor variable. A numeric vector.
Number of knots to use.
If TRUE, produce a message about the knots chosen.
Wong (1982, 1984) showed the asymptotic density of k-means in 1 dimension is
proportional to the cube root of the density of x.
Compared to using quantiles (the default for
choosing knots using k-means produces a better spread of knot locations
if the distribution of values is very uneven.
k-means is computed in an optimal, deterministic way using
A matrix of predictors, similar to
This function supports "safe prediction"
Original knot locations will be used for prediction with
Wong, M. (1982). Asymptotic properties of univariate sample k-means clusters. Working paper #1341-82, Sloan School of Management, MIT. https://dspace.mit.edu/handle/1721.1/46876
Wong, M. (1984). Asymptotic properties of univariate sample k-means clusters. Journal of Classification, 1(1), 255<e2><80><93>270. https://doi.org/10.1007/BF01890126
1 2 3 4 5 6 7 8 9
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.