I am studying logistic regressions and I wonder why are estimators biased when the independent variables have low variance (maybe low variance compared to its mean, but anyway).
I simulate the underlying model as a linear function of a single variable x
and I do not include an error term. x
is generated from a normal distribution, with mean mx
and sd sx
.
f
is a helper to map the probabilities using a logistic function
I use mx = 1.0
, and sample sx
from a uniform distribution from 0 to 1, so I can estimate the model for different values of sx
.
SAMPLE_SIZE = 1000
set.seed(100)
f <- function(v) exp(v) / (1 + exp(v));
sim = function(b0, b1, mx, sx) {
xs <- rnorm(SAMPLE_SIZE, mean = mx, sd = sx)
ps <- f(b0 + b1 * xs)
ys <- rbinom(SAMPLE_SIZE, 1, ps)
glm(ys ~ xs, family = binomial)
}
sx <- runif(n = 1000, min = 0.05, max = 1.0)
b0 = 1.5
b0s <- sapply(sx, function(v) {
sim(b0 = b0, b1 = 1.0, mx = 1.0, sx = v)$coefficients[[1]]
})
And then I plot the error between the estimated b0
coefficient and the real one, for different values of sx
:
plot(sx, b0s - b0)
What I get is that the error gets smaller the greater sx
is.
From common linear regressions, we know that the estimators get more precise the larger the variance in the independent variables. But that does not say anything about the biases.
How to interpret this result? Are the estimators really biased in logistic regressions? What's missing here? Is there any problem related to numerical estimates here?