be-green / quantspace

R package for estimating quantile regression coefficients via the quantile spacing method
https://brice.green/quantspace
Other
4 stars 3 forks source link

Smoother splines for interpolation #6

Open be-green opened 3 years ago

be-green commented 3 years ago

Right now the spline code has sharp breaks where it meets the tails. This isn't always wrong, but I think it happens more often than it should. Perhaps there is a way to resolve this issue via penalized splines (so that they don't get too wiggly). Or perhaps we could do some kind of weighting deal where the splines take into account the tail density more directly when they are being fitted, rather than just the knot at the quantile.

be-green commented 3 years ago

Here's an example that helps clarify. The asymptotics look fine, but right now if you have (for example) equally spaced knots for the quantiles, the splines start to look like a Runge phenomenon demonstration.

beta = c(1, -3)
X = MASS::mvrnorm(n, mu = c(0.2, 0.3), Sigma = matrix(c(1, 0.2, 0.2, 2), ncol = 2))
y = X %*% beta + rnorm(n)

arg1 <- X[,1]
arg2 <- X[,2]
dat = data.frame(out = y, one = arg1, two = arg2)
dat2 <- data.frame(out = NA, one = mean(first), two = mean(second))
fit <- qs(out ~ one + two, data = dat, quantiles = seq_quant(0,1,by = 0.1))

de <- distributional_effects(fit, newdata = data.frame(one = 0.05251955, 
                                                       two = 0.2959033))

plot(de, newdata = mean(X), what = "pdf")

Compare N = 100 to N = 1,000 to N = 10,0000 at the same forecasting coordinates:

N = 100 image

N = 1,000 image

N = 10,000 image

N = 100,000 image

We might want to a) provide guidance on selecting quantiles to fit with the model for distributional effect estimate (e.g. Chebyshev Polynomials) b) incorporate some kind of penalization to the spline, because right now they are really overfitting in the small samples.