set.seed(2026)
x <- rnorm(100)
# 生成服从指数分布的随机数
y <- rexp(n = 100, rate = exp(1 + x))
# 指数分布的方差是期望的平方
fit1 <- glm(y ~ x, family = quasi(variance = "mu^2", link = "log"))
summary(fit1)
##
## Call:
## glm(formula = y ~ x, family = quasi(variance = "mu^2", link = "log"))
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -1.1104 0.0945 -11.8 <2e-16 ***
## x -1.0139 0.0942 -10.8 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for quasi family taken to be 0.8842)
##
## Null deviance: 220.58 on 99 degrees of freedom
## Residual deviance: 108.25 on 98 degrees of freedom
## AIC: NA
##
## Number of Fisher Scoring iterations: 6
回归系数和截矩项都是负的,这明显与预设的不同。不知道问题出在哪了?