Generalized linear models (IN PROGRESS)
Generalized linear models (GLM)
are a generalization of OLS where you use a link function help ensure that a constant change in the predictor leads to a constant change in the dependent variable and y assumed to come from a distribution within the exponential family of distributions which includes the normal distribution. GLMs typically have y values that are bounded or non-continuous. For example you cannnot have negative rheobase or resistance or negetive frequency of spikes. These values are considered bound by 0. While bound values can be normally distributed they are often not. OLS just uses the identity link where no transform is needed. Unlike OLS, GLMs are solved using maximum likelihood estimation. Maximum likelihood is the product of the likelihoods. Maximum likelihood is computationally solved by minimizing the sum of negative log likelihood using iterative computation methods like those used for non-linear curve fitting.
The link function¶
The link function relates the predictors to the expected value, of the dependent variable. For example for the normal distribution the link is the identity function and the equation is: . For Gamma distribution the link is the negative inverse: . When the GLM is being solved we actually use the inverse of the link function. For example the link has the inverse link function . The inverse link ensures that the predicted values from lie in a range that is valid for the choosen response distribution. For exmpale, if your y values are from a gamma distribution you cannot have nagative values. However, your coefficients can lead to negative values so to you need to transform to ensure the values are within the range of the choosen distribution. One thing that may be confusing is that the is not the same for the normal distribution and other exponential distributions. For the normal distribution the mean also changes the location of the distribution. For other distributions the mean is function of what are called the shape and scale of the distribution. These other distributions don’t have a location so if you may need to shift your data.
Common GLM regressions¶
We will cover some common GLM regressions and when to use them. Some of these distributions we covered in the distributions chapter so you can go their to see more about them.
Poisson regression¶
The Poisson regression is used when you have count data, data on the number of events that occur within some fixed interval. You could measure how many synaptic events or entrys into part of an arena are occuring and whether they differ between genotypes. However, for many neuroscience data we would either have long periods of time at which we measure these features or we would have repeated measures at which we would need to measure the features. Due to this we typically use rates rather than counts.
Log-normal regression¶
Log-normal regression is used when you have log-normally distributed data, when you data has the bounds (0,). This is less commonly used because usually it is easier to just log transform your y data and run a OLS. Log-normal distribution can be used when you have rates.
Gamma regression¶
Gamma regression is used when you have rate data or when you data has the bounds (0,). Unlike log-normal data, log transforming gamma distribution data will not lead to normally distributed data.
Binomial regression¶
Binomial regression is used when you have y values that are 0 or 1. This is like success or not, past the threshold or not. An example is you could use binomial regression to test whether the number of interneurons with depolarization block (0 for block, 1 for no block) is different between genotypes. If you notice your data is bimodal, you could find the threshold and assign values of 0 or 1 for above or below threshold. I have also found binomial regression to be useful when you have extremely leptokurtotic and skewed data. You can sythesize data use that to set a cutoff and run an binomial regression.
Beta regression¶
Beta regression is the continuous equivalent of the binomial regression where your values are bounded (0,1) with the exception that you cannot actually have 0s or 1s. You can use beta regression on a set of correlation coefficients (bounded between -1 and 1) as long as you shift and rescale them or split them into positive and negative (need to transform them by multiplying by -1).