# How to know what function to use to transform $X$ to get the best model fit in logistic regression?

I have simple model $Y~X$ where $Y \sim Bin(1, p)$, so it's a case of simple logistic regression. $X$ is continuous. How to know what function to use to transform $X$ to get the best model fit?

There are many ways to go about this. If you had only a single $X$ you could just use the loess nonparametric smoother with outlier detection turned off to estimate the probability that $Y=1$ given $X=x$ (e.g., see the R Hmisc package plsmo function). In general, regression splines are great solutions because they are flexible and because they are honest about how many parameters (degrees of freedom) there are in the fit, which results in accurate confidence bands and $P$-values. Much more detail is in my handouts available through http://biostat.mc.vanderbilt.edu/rms.