0
$\begingroup$

I need help answering a problem I have:

I am modeling data set using GLM that has two independent variables $x_1, x_2$, and a single response variable $y$. I am using $\verb|statsmodels.api|$ python library to set these models up. The problem I am trying to get an answer to is, how I get the shape parameters for the distributions that result from the model?

In other words, suppose that $\verb|glm_model|$ is the model I trained. Then given a test data point $x^*$, $$\verb|glm_model|(x^*)=y^*=\mu.$$ This is the first shape parameter for my distribution (mean). I want to get the variance, $\sigma$, so that I can get the distribution $N(\mu, \sigma)$. However, there does not seem to be any method in the glm python package that I can easily use to get this parameter.

Visually what I am trying to get is the distributions that you see on these graphs.

enter image description here enter image description here enter image description here

There is a distribution associated with each predicted value point. If there is no way to get the variance this way, is there a way to estimate the variance around $y^*$ locally? Is there a formal method of doing this?

$\endgroup$
5
  • 1
    $\begingroup$ The attached figure visualizes a linear regression. Your question refers to generalized linear regression (GLM). These are not the same models; very briefly, in a GLM the response Y is not $N(\mu,\sigma^2)$. Please clarify what kind of variable the response $y$ is and what kind of GLM you are fitting. $\endgroup$
    – dipetkov
    Aug 7, 2022 at 12:11
  • $\begingroup$ @dipetkov Sorry for the confusion. I edited my question with more example figures. I got these from the following sites: link1, link2. What I was trying to ask is, regardless of what the response variables distribution was, how can you can the distributions found in the figures above? They fit a Poisson regression on one of them and plotted the distributions resulting from the model. $\endgroup$ Aug 7, 2022 at 14:16
  • 1
    $\begingroup$ The variance of the Poisson distribution is equal to the mean. So with Poisson regression, you obtain $E(Y|X=x)$ from the model and then $\operatorname{Var}(Y|X=x) = E(Y|X=x)$. In the notation of the Medium article you link to: $\lambda_i = E(Y_i|X=x_i)$. $\endgroup$
    – dipetkov
    Aug 7, 2022 at 14:30
  • $\begingroup$ @dipetkov Ah yes Poisson it is easy to get these parameters. How about other distributions? For example, simple linear regression. $\endgroup$ Aug 7, 2022 at 14:44
  • 1
    $\begingroup$ It's easy for all of the regressions mentioned in your questions as long as you understand the regression model. I suggest you do a bit of revision. For linear regression $\sigma^2$ is the error variance. $\endgroup$
    – dipetkov
    Aug 7, 2022 at 14:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.