Answers:
泊松回归模型假定的泊松分布,并使用链接函数。因此,对于单个解释变量,假设(因此),并且。根据该模型生成数据很容易。这是一个示例,您可以根据自己的情况进行调整。日志X ý 〜P (μ )ë (Ý )= V (Ý )= μ 日志(μ )= β 0 + β 1 X
> #sample size
> n <- 10
> #regression coefficients
> beta0 <- 1
> beta1 <- 0.2
> #generate covariate values
> x <- runif(n=n, min=0, max=1.5)
> #compute mu's
> mu <- exp(beta0 + beta1 * x)
> #generate Y-values
> y <- rpois(n=n, lambda=mu)
> #data set
> data <- data.frame(y=y, x=x)
> data
y x
1 4 1.2575652
2 3 0.9213477
3 3 0.8093336
4 4 0.6234518
5 4 0.8801471
6 8 1.2961688
7 2 0.1676094
8 2 1.1278965
9 1 1.1642033
10 4 0.2830910
如果您想生成一个完全适合模型的数据集,则可以执行以下操作R
:
# y <- exp(B0 + B1 * x1 + B2 * x2)
set.seed(1234)
B0 <- 1.2 # intercept
B1 <- 1.5 # slope for x1
B2 <- -0.5 # slope for x2
y <- rpois(100, 6.5)
x2 <- seq(-0.5, 0.5,,length(y))
x1 <- (log(y) - B0 - B2 * x2) / B1
my.model <- glm(y ~ x1 + x2, family = poisson(link = log))
summary(my.model)
哪个返回:
Call:
glm(formula = y ~ x1 + x2, family = poisson(link = log))
Deviance Residuals:
Min 1Q Median 3Q Max
-2.581e-08 -1.490e-08 0.000e+00 0.000e+00 4.215e-08
Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept) 1.20000 0.08386 14.309 < 2e-16 ***
x1 1.50000 0.16839 8.908 < 2e-16 ***
x2 -0.50000 0.14957 -3.343 0.000829 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
(Dispersion parameter for poisson family taken to be 1)
Null deviance: 8.8619e+01 on 99 degrees of freedom
Residual deviance: 1.1102e-14 on 97 degrees of freedom
AIC: 362.47
Number of Fisher Scoring iterations: 3