setwd("D:/data") # 设置工作目录,根据实际情况修改路径
d3.4<-read.csv("C:\\Users\\86167\\Desktop\\ex3.4.csv",header=T) # 读取数据到数据框d3.4
glm.ln<-glm(y~x1+x2,family=poisson(link=log),data=d3.4)
summary(glm.ln)
##
## Call:
## glm(formula = y ~ x1 + x2, family = poisson(link = log), data = d3.4)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) 0.54798 0.19085 2.871 0.004088 **
## x1 0.02772 0.01374 2.017 0.043655 *
## x2 0.65596 0.17736 3.698 0.000217 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
## Null deviance: 63.153 on 59 degrees of freedom
## Residual deviance: 19.554 on 57 degrees of freedom
## AIC: 211.77
##
## Number of Fisher Scoring iterations: 4
##lny^=0.5480+0.0277x1+0.6560x2 ##x1,x2显著 ##x1和x2的系数都显著,说明家庭年收入(x1),是否有私家车(x2)对一年外出旅游条件(y)重要影响.x2的回归系数为0.0227,表明保持其他预测变量不变,有私家车,旅游次数的对数的均值将相应的增加0.0227.
exp(coef(glm.ln))
## (Intercept) x1 x2
## 1.729759 1.028110 1.926987
##x1 对应的 1.028118 :该值表示在其他变量不变的情况下,家庭年收入每增加1万元,家庭一年外出旅游次数的期望值会乘以1.028110。这说明家庭年收入对家庭一年外出旅游次数有正向影响,虽然影响程度相对较小(因为系数接近1)。x2 对应的 1.926987:这个值表示在其他条件相同的情况下,有私家车(x2=1)的家庭相比没有私家车(x2=0)的家庭,家庭一年外出旅游次数的期望值会乘以1.926987。这表明是否有私家车对家庭一年外出旅游次数有较大的正向影响,有私家车的家庭外出旅游次数的期望值明显更高。