I want to implement the GLM model in C++ for a commercial package (ie. this is not for fun), including but not limited to normal, binomial distribution etc. I'm not so sure how the implementation should work. Say, I want to implement the linear and logistic models in a GLM framework.
I can simply implement the linear model by solving the following matrix equation for the OLS coefficients:
But I will need to iteratively estimate the MLE coefficients for a logistic model.
To me, the implementation will be something like:
if (normal in the exponential family)
{
solve the matrix equation listed above
}
else if (logistic in the exponential family)
{
iteratively solve the logistic MLE coefficients
}
else if (poisson in the ....)
{
iteratively solve the poisson MLE coefficients
}
else (.....)
{
other error distributions...
}
The GLM gives us a mathematical way of generalising the distribution models but it does not help computationally. This is like gluing distant families of different models into one model.
How does a statistical software implement a GLM model? Is there any open-source statistical library (not necessarily in C++) that shows how this can be done? Any resources (articles, papers, books) that shows how the GLM model is written?
What does the GLM model gives us how the families can be generalised computationally? Are we supposed to write an implementation for each family indepedently?