# What are weights in a binary glm and how to calculate them?

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.

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.

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.

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$$, but that would take you into the realm of quasi-likelihood theory and the pseudo-binomial GLM family. For true likelihood based binomial GLMs, 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.

• 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.) – Raskolnikov Oct 28 at 15:55