5
$\begingroup$

I have a dataset that includes four variables. Three of them are factors and one is constant. My response variable contains (0,1) so my glm is about logistic regression. My question is, how do I know whether I should include weights as a parameter in my glm() function call in R and if so, then how do I calculate them? I'm a bit confused.

$\endgroup$
0

3 Answers 3

10
$\begingroup$

I'm going to give a more detailed answer. Tim and Ivan have correctly advised you not to worry about the weights argument and their answers would be excellent for continuous GLMs. Binary regression with (0,1) responses is however a very special case and some stronger guidelines about weights are in order.

For binary regression, the GLM weights should never be set to any value other than 1 (which is the default value). To see this, recall what the definition of a weight is for a binary GLM. The variance of the $i$th binary variable $y_i$ is assumed to be $${\rm var}(y_i)=\frac1{w_i}\mu_i(1-\mu_i)$$ where $\mu_i=E(y_i)=P(y_i=1)$ is the expected value. For a Bernoulli random variable, it is impossible for the variance to be anything other than $\mu_i(1-\mu_i)$, where $\mu_i$ is the probability of a success. So it is impossible for $w_i$ to take on any value other than 1.

If you were to set the weights to any value other than 1 in a binary glm, the results would be meaningless.

If your data was binomial rather than binary, so that $y_i$ was the number of successes out of $n_i$ trials, then you could compute the proportion of successes as $p_i=y_i/n_i$. In that case, you would fit a binomial GLM with weights equal to the $n_i$, for example:

p <- y / n
fit <- glm(p ~ x, family=binomial, weights=n)

With $n_i>1$ you can theoretically set the weight to be a value other than $n_i$, although doing so takes you into the realm of quasi-likelihood theory and the quasi-binomial GLM family. For a quasi-binomial GLM, weights larger than $n_i$ would make sense if the individual bernoulli trials that make up $y_i$ are positively correlated (positive feedback) and a weight less than $n_i$ would make sense if they are negatively correlated (negative feedback). For true likelihood-based binomial GLMs, however, the weight argument is determined by the number of trials and cannot be varied.

Similar considerations apply to other count-based GLM families such as Poisson and negative binomial. You can only set the GLM prior weights for those families to a value other than 1 if you are willing to embrace a quasi-likelihood model.

$\endgroup$
4
  • $\begingroup$ Suppose I have the following situation, I want to make a logistic regression or binary glm, but I want to give more weight to observations according to some variable (actuarial example I'm thinking on: a person can decide to pay a premium or not. This depends on several predictor variables, but I also want to give more weight to the observation when the premium in the past was larger). How would I go about such a thing? (The response variable does not depend on premium in the past in my example, but that's not important.) $\endgroup$ Commented Oct 28, 2019 at 15:55
  • $\begingroup$ @Raskolnikov Weights in glms correspond to variances. Using weights to instead represent some utility weighting (like size of premium) would be a misuse of glm weights. $\endgroup$ Commented Nov 20, 2022 at 22:55
  • $\begingroup$ "For binary regression, the GLM weights should never be set to any value other than 1". I think this is too strong a statement. Weights can be used successfully with binary regression for a variety of valid reasons, e.g., frequency weights, sampling weights, or weights for causal inference. These weights do not have to be greater than 1. All these do is change each unit's contribution to the likelihood. It's true you have to use a variance to correct for use of the weights, but that doesn't make the model or estimates invalid. $\endgroup$
    – Noah
    Commented Apr 30 at 12:55
  • $\begingroup$ @Noah I believe my comments to be correct as they stand. I gave a clear-cut mathematical derivation why this must be so. My comments relate specifically to R's glm function and I define "binary regression" to be the case where n=1 and y is binary. If you have frequency weights or sampling weights, then it's not binary regression. $\endgroup$ Commented May 2 at 1:38
5
$\begingroup$

The simple answer is that if you don't know what the weights are, then most likely you don't need them.

Weights are used to tell your model that some observations are more important than other ones. For example, if you know that Buddhists are unrepresented in your sample, and you can calculate the exact disparency as compared to the population (and you find it important, since always some group will be underrepresented, no matter how hard you try), then you can use this information to re-weight your data in such way to correct for the discrepancy.

$\endgroup$
2
$\begingroup$

weights are not calculated endogenously. It depends from the nature of your data, and the specific problem you are working at. If your data don't provide any particularly good reason to specify a set of weights, simply skip that parameter, and glm() will automatically treat all observations as of equal weight.

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.