R code for Least-squares density estimation
# LEAST-SQUARES DENSITY ESTIMATION WITH SHAPE RESTRICTIONS

**Smooth Decreasing Density Estimation**
Given a sample x_{1},...,x_{n} from a decreasing density f,
this code provides a smooth decreasing estimate using regression splines.

The knot choices can be provide by the user or the "default" or automatic
choices may be used.

If chosen by the user: The estimate will be over the interval [a,b]
where the user-defined knots are at a=t_{0}< t_{1} < ...< t_{k}< t_{k+1}=b.

The inputs to the code are the sample values and the knots. If knots=0, the default
knot values will be used with the mode at the origin.

The outputs are the knots, the value of the criterion function, the values of the
density estimate at the observed x-values, and values of the density estimate at a
tightly-spaced grid of points for plotting.

### R code for smooth decreasing density

Here is some example code where the default knots are chosen.

### Example implementation of R code for estimating a smooth decreasing density

**Smooth Decreasing Convex Density Estimation**
Given a sample x_{1},...,x_{n} from a decreasing convex density f on [a,b]
and knots a=t_{0}< t_{1} < ...< t_{k}< t_{k+1},
f is estimated using cubic regression splines

The knot choices can be provide by the user or the "default" or automatic
choices may be used.

If chosen by the user: The estimate will be over the interval [a,b]
where the user-defined knots are at a=t_{0}< t_{1} < ...< t_{k}< t_{k+1}=b.

The inputs to the code are the sample values and the knots. If knots=0, the default
knot values will be used with the mode at the origin.

The outputs are the knots, the value of the criterion function, the values of the
density estimate at the observed x-values, and values of the density estimate at a
tightly-spaced grid of points for plotting.

### R code for smooth decreasing convex density

Here is some example code where the default knots are chosen.

### Example implementation of R code for estimating a smooth decreasing convex density

**Smooth Unimodal Density Estimation**
Given a sample x_{1},...,x_{n} from a unimodal density f on [a,b]
and mode m,
f is estimated using quadratic regression splines. Knots are placed evenly over
[a,b], then extra knots are added where the data are "thickest."

### R code for estimating a smooth unimodal density

Here is some example code.

### Example implementation of R code for estimating a smooth unimodal density

meyer@stat.colostate.edu