Description Usage Arguments Details Value Author(s) References Examples
View source: R/splineDensity.R
Given raw (discretized) distributional observations, smoothSplines
computes the density
function that 'best' fits data, in a tradeoff between smooth and least squares approximation, using Bspline basis functions.
1 2 3 4 5 6 7 8 9 10 11 12 13 
k 
smoothing splines degree 
l 
order of derivative in the penalization term 
alpha 
weight for penalization 
data 
an object of class "matrix" containing data to be smoothed, row by row 
xcp 
vector of control points 
knots 
either vector of knots for the splines or a integer for the number of equispaced knots 
weights 
matrix of weights. If not given, all data points will be weighted the same. 
num_points 
number of points of the grid where to evaluate the density estimated 
prior 
prior used for zeroreplacements. This must be one of "perks", "jeffreys", "bayes_laplace", "sq" or "default" 
cores 
number of cores for parallel execution, if the option was enabled before installing the package 
fast 
1 if maximal performance is required (print statements suppressed), 0 otherwise 
The original discretized densities are not directly smoothed, but instead the centred logratio transformation is
first applied, to deal with the unit integral constraint related to density functions.
Then the constrained variational problem is set. This minimization problem for the optimal
density is a compromise between staying close to the given data, at the corresponding xcp
,
and obtaining a smooth function.
The nonsmoothness measure takes into account the l
th derivative, while the fidelity term is weigthed by alpha
.
The solution is a natural spline. The vector of its coefficients is obtained by the minimum norm solution of a linear system.
The resulting splines can be either backtransformed to the original Bayes space of density
functions (in order to provide their smoothed counterparts for vizualization and interpretation
purposes), or retained for further statistical analysis in the clr space.
An object of class smoothSpl
, containing among the other the following variables:

each row is the vector of Bspline coefficients 

the values of the smoothed curve, for the grid given 

the values of the smoothed curve, in the clr setting, for the grid given 
Alessia Di Blasi, Federico Pavone, Gianluca Zeni, Matthias Templ
J. Machalova, K. Hron & G.S. Monti (2016): Preprocessing of centred logratio transformed density functions using smoothing splines. Journal of Applied Statistics, 43:8, 14191435.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20  SepalLengthCm < iris$Sepal.Length
Species < iris$Species
iris1 < SepalLengthCm[iris$Species==levels(iris$Species)[1]]
h1 < hist(iris1, nclass = 12, plot = FALSE)
midx1 < h1$mids
midy1 < matrix(h1$density, nrow=1, ncol = length(h1$density), byrow=TRUE)
knots < 7
## Not run:
sol1 < smoothSplines(k=3,l=2,alpha=1000,midy1,midx1,knots)
plot(sol1)
h1 < hist(iris1, freq = FALSE, nclass = 12, xlab = "Sepal Length [cm]", main = "Iris setosa")
# black line: kernel method; red line: smoothSplines result
lines(density(iris1), col = "black", lwd = 1.5)
xx1 < seq(sol1$Xcp[1],tail(sol1$Xcp,n=1),length.out = sol1$NumPoints)
lines(xx1,sol1$Y[1,], col = 'red', lwd = 2)
## End(Not run)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.