Interactive demo · Probability and Statistical Inference · Chapter 21

Cosine series density estimation: how many terms?

Any density f on [0, 1] is a cosine series f = 1 + Σj≥1 βjφj with φj(x) = √2 cos(jπx), and each coefficient βj = E φj(X) is estimated by a sample mean. Keeping J terms trades variance (Σj≤J σj2/n) against bias (Σj>J βj2). Neither is known, but both can be estimated from the data: J is chosen to minimise the risk estimate (21.16) over 1 ≤ J ≤ √n. For simulated data the page also draws the true risk, so you can see how well the estimate finds its minimum, and the band of Theorem 21.6 around the estimate.

Data

Sample size n

Number of terms J

Band

Try these

Simulated samples come from a seeded generator, so the same settings always give the same sample; "New sample" moves to the next seed. The Old Faithful eruption times (minutes) are mapped to [0, 1] by (x − 1.5)/4 and the estimate is drawn back on the minutes scale. The true risk uses the coefficients of the true density, computed by a fine midpoint rule.

In the lecture notes