# How to correct inference for searching over multiple specifications?

Correcting for multiple testing is easy, and there's a lot of literature around it. But now consider a different problem.

Say you have $X$ and $Y$ and you want to estimate $E[Y|X=x]= f(x)$ where $f$ could be any function.

Say you fit several functions $f_1, \dots, f_k \in F$ and you pick one of them according to some criteria (for example, via cross-validation or whatever other criteria you prefer). Let $f^*$ be the chosen function.

Now you want to do inference with $f^*$. For instance, suppose $f^*$ has some parameteric form (for example, a GLM) and you want to obtain confidence intervals for some of the parameters.

If you had started with $f^*$ to begin with, then inference is easy, just traditional statistical techniques. But you didn't start with $f^*$. So how can you do inference properly, taking into account the fact you have searched $f^*$ over a set of functions $F$?

That said, if you have a clear algorithm for selecting $f^\ast$, you could use simulation or permutation to obtain $p$-values that incorporate this selection. Simulate data under the null hypothesis for whatever effect you are interested in, then run the entire process of both selecting $f^\ast$ and performing inference on it, saving the resulting statistic. Do this many times with randomly generated data. Finally insert your actually observed statistic into this null distribution of statistics, and you have a $p$-value that takes the selection into account.