logspline  R Documentation 
Fits a logspline
density using splines to approximate the logdensity
using
the 1997 knot addition and deletion algorithm (logspline
).
The 1992 algorithm is available using the oldlogspline
function.
logspline(x, lbound, ubound, maxknots = 0, knots, nknots = 0, penalty,
silent = TRUE, mind = 1, error.action = 2)
x 
data vector. The data needs to be uncensored. 
lbound,ubound 
lower/upper bound for the support of the density. For example, if there
is a priori knowledge that the density equals zero to the left of 0,
and has a discontinuity at 0,
the user could specify 
maxknots 
the maximum number of knots. The routine stops adding knots when this number of knots is reached. The method has an automatic rule for selecting maxknots if this parameter is not specified. 
knots 
ordered vector of values (that should cover the complete range of the
observations), which forces the method to start with these knots.
Overrules knots.
If 
nknots 
forces the method to start with 
penalty 
the parameter to be used in the AIC criterion. The method chooses
the number of knots that minimizes

silent 
should diagnostic output be printed? 
mind 
minimum distance, in order statistics, between knots. 
error.action 
how should 
Object of the class logspline
, that is intended as input for
plot.logspline
(summary plots),
summary.logspline
(fitting summary),
dlogspline
(densities),
plogspline
(probabilities),
qlogspline
(quantiles),
rlogspline
(random numbers from the fitted distribution).
The object has the following members:
call 
the command that was executed. 
nknots 
the number of knots in the model that was selected. 
coef.pol 
coefficients of the polynomial part of the spline. The first coefficient is the constant term and the second is the linear term. 
coef.kts 
coefficients of the knots part of the spline.
The 
knots 
vector of the locations of the knots in the 
maxknots 
the largest number of knots minus one considered during fitting
(i.e. with 
penalty 
the penalty that was used. 
bound 
first element: 0  
samples 
the sample size. 
logl 
matrix with 3 columns. Column one: number of knots; column two: model fitted during addition (1) or deletion (2); column 3: loglikelihood. 
range 
range of the input data. 
mind 
minimum distance in order statistics between knots required during fitting (the actual minimum distance may be much larger). 
Charles Kooperberg clk@fredhutch.org.
Charles Kooperberg and Charles J. Stone. Logspline density estimation for censored data (1992). Journal of Computational and Graphical Statistics, 1, 301–328.
Charles J. Stone, Mark Hansen, Charles Kooperberg, and Young K. Truong. The use of polynomial splines and their tensor products in extended linear modeling (with discussion) (1997). Annals of Statistics, 25, 1371–1470.
plot.logspline
,
summary.logspline
,
dlogspline
,
plogspline
,
qlogspline
,
rlogspline
,
oldlogspline,
oldlogspline.to.logspline
.
y < rnorm(100)
fit < logspline(y)
plot(fit)
#
# as (4 == length(2, 1, 0, 1, 2) 1), this forces these initial knots,
# and does no knot selection
fit < logspline(y, knots = c(2, 1, 0, 1, 2), maxknots = 4, penalty = 0)
#
# the following example give one of the rare examples where logspline
# crashes, and this shows the use of error.action = 2.
#
set.seed(118)
zz < rnorm(300)
zz[151:300] < zz[151:300]+5
zz < round(zz)
fit < logspline(zz)
#
# you could rerun this with
# fit < logspline(zz, error.action=0)
# or
# fit < logspline(zz, error.action=1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.