Densities Hermite polynomial approximation approach has been
proposed by A. Gallant and D. W. Nychka in 1987. The main idea is to
approximate unknown distribution density with scaled Hermite polynomial.
For more information please refer to the literature listed below.
Let's use notations introduced in dhpa 'Details' 
section. Function hpaBinary maximizes the following
quasi log-likelihood function:
$$\ln L(\gamma_{0}, \gamma, \alpha, \mu, \sigma; x) = 
\sum\limits_{i:z_{i}=1} 
\ln\left(\overline{F}_{\xi}
(-(\gamma_{0}+\gamma x_{i}), \infty;\alpha, \mu, \sigma)\right) +$$
$$
+\sum\limits_{i:z_{i}=0} 
\ln\left(\overline{F}_{\xi}
(-\infty, -(\gamma_{0} + x_{i}\gamma);\alpha, \mu, \sigma)\right),$$
where (in addition to previously defined notations):
\(x_{i}\) - is row vector of regressors derived from data 
according to formula.
\(\gamma\) - is column vector of regression coefficients.
\(\gamma_{0}\) - constant.
\(z_{i}\) - binary (0 or 1) dependent variable defined in formula.
Note that \(\xi\) is one dimensional and K corresponds
to \(K=K_{1}\).
The first polynomial coefficient (zero powers) 
set to 1 for identification purposes i.e. \(\alpha_{0}=1\).
If is_z_coef_first_fixed is TRUE then the coefficient for the 
first independent variable in formula will be fixed to 1 i.e.
\(\gamma_{1}=1\).
If z_mean_fixed is not NA then \(\mu\)=z_mean_fixed
fixed.
If z_sd_fixed is not NA then \(\sigma\)=z_mean_fixed
fixed. However if is_x0_probit = TRUE then parameter \(\sigma\) will 
be scale adjusted in order to provide better initial point for optimization 
routine. Please, extract \(\sigma\) adjusted value from the function's 
output list. The same is for z_mean_fixed.
Rows in data corresponding to variables mentioned in formula
which have at least one NA value will be ignored.
All variables mentioned in formula should be numeric vectors.
The function calculates standard errors via sandwich estimator
and significance levels are reported taking into account quasi maximum
likelihood estimator (QMLE) asymptotic normality. If one wants to switch
from QMLE to semi-nonparametric estimator (SNPE) during hypothesis testing
then covariance matrix should be estimated again using bootstrap.
This function maximizes (quasi) log-likelihood function 
via optim function setting its method 
argument to "BFGS". If opt_type = "GA" then genetic
algorithm from ga function
will be additionally (after optim putting its
solution (par) into suggestions matrix) applied in order to 
perform global optimization. Note that global optimization takes
much more time (usually minutes but sometimes hours or even days). 
The number of iterations and population size of the genetic algorithm
will grow linearly along with the number of estimated parameters. 
If it seems that global maximum has not been found then it
is possible to continue the search restarting the function setting 
its input argument x0 to x1 output value. Note that
if cov_type = "bootstrap" then ga
function will not be used for bootstrap iterations since it
may be extremely time consuming.
If opt_type = "GA" then opt_control should be the
list containing the values to be passed to ga
function. It is possible to pass arguments lower, upper,
popSize, pcrossover, pmutation, elitism,
maxiter, suggestions, optim, optimArgs,
seed and monitor. 
Note that it is possible to set population,
selection, crossover and mutation arguments changing
ga default parameters via gaControl 
function. These arguments information reported in ga.
In order to provide manual values for lower and upper bounds
please follow parameters ordering mentioned above for the
x0 argument. If these bounds are not provided manually then
they (except those related to the polynomial coefficients)
will depend on the estimates obtained
by local optimization via optim function
(this estimates will be in the middle
between lower and upper).
Specifically for each sd parameter lower (upper) bound
is 5 times lower (higher) than this
parameter optim estimate.
For each mean and regression coefficient parameter its lower and 
upper bounds deviate from corresponding optim estimate
by two absolute values of this estimate.
Finally, lower and upper bounds for each polynomial
coefficient are -10 and 10 correspondingly (do not depend
on their optim estimates).
The following arguments are differ from their defaults in
ga:
pmutation = 0.2,
 
optim = TRUE,
 
optimArgs =
list("method" = "Nelder-Mead", "poptim" = 0.2, "pressel" = 0.5),
 
seed = 8,
 
elitism = 2 + round(popSize * 0.1).
 
Let's denote by n_reg the number of regressors
included into the formula.
The arguments popSize and maxiter of
ga function have been set proportional to the number of
estimated polynomial coefficients and independent variables: