1、Called the link function of the GLM.Selected GLM families and their canonical linkFamilyCanonical linkNamebinomiallogitgaussianidentitypoissonlog1.2 Binary Dependent VariablesModel:In the probit case: equals the standard normal CDFIn the logit case: equals the logistic CDFExample:(1)DataConsidering
2、female labor participation for a sample of 872 women from Switzerland.The dependent variable: participationThe explain variables:income,age,education,youngkids,oldkids,foreignyesandage2.R:library(AER)data(SwissLaborsummary(SwissLabor)participation income age education no :471 Min. : 7.187 Min. :2.00
3、0 Min. : 1.000 yes:401 1st Qu.:10.472 1st Qu.:3.200 1st Qu.: 8.000 Median :10.643 Median :3.900 Median : 9.000 Mean :10.686 Mean :3.996 Mean : 9.307 3rd Qu.:10.887 3rd Qu.:4.800 3rd Qu.:12.000 Max. :12.376 Max. :6.200 Max. :21.000 youngkids oldkids foreign Min. :0.0000 Min. :0.0000 no :656 1st Qu.:0
4、.0000 1st Qu.:0.0000 yes:216 0.0000 Median :1.0000 0.3119 Mean :0.9828 0.0000 3rd Qu.:2.0000 3.0000 Max. :6.0000 (2) Estimationswiss_prob=glm(participation.+I(age2),data=SwissLabor,family=binomial(link=probit)summary(swiss_prob)Call:glm(formula = participation . + I(age2), family = binomial(link = )
5、, data = SwissLabor)Deviance Residuals: Min 1Q Median 3Q Max -1.9191 -0.9695 -0.4792 1.0209 2.4803 Coefficients: Estimate Std. Error z value Pr(|z|) (Intercept) 3.74909 1.40695 2.665 0.00771 * income -0.66694 0.13196 -5.054 4.33e-07 *age 2.07530 0.40544 5.119 3.08e-07 *education 0.01920 0.01793 1.07
6、1 0.28428 youngkids -0.71449 0.10039 -7.117 1.10e-12 *oldkids -0.14698 0.05089 -2.888 0.00387 * foreignyes 0.71437 0.12133 5.888 3.92e-09 *I(age2) -0.29434 0.04995 -5.893 3.79e-09 *-Signif. codes: 0 * 0.001 * 0.01 * 0.05 . 0.1 1 (Dispersion parameter for binomial family taken to be 1) Null deviance:
7、 1203.2 on 871 degrees of freedomResidual deviance: 1017.2 on 864 degrees of freedomAIC: 1033.2Number of Fisher Scoring iterations: 4(3) VisualizationPlotting participation versus ageplot(participationage,data=SwissLabor,ylevels=2:1)(4) EffectsAverage marginal effects:The average of the sample margi
8、nal effects:fav=mean(dnorm(predict(swiss_prob,type=link)fav*coef(swiss_prob)(Intercept) income age education youngkids oldkids foreignyes I(age2) The average marginal effects at the average regressor:av=colMeans(SwissLabor,-c(1,7)av=data.frame(rbind(swiss=av,foreign=av),foreign=factor(c(no,yesav=pre
9、dict(swiss_prob,newdata=av,type=av=dnorm(av)avswiss*coef(swiss_prob)-7foreignswiss: (Intercept) income age education youngkids oldkids I(age2) Foreign:(5) Goodness of fit and predictionPseudo-R2:as the log-likelihood for the fitted model, as the log-likelihood for the model containing only a constan
10、t term. swiss_prob0=update(swiss_prob,formula=.1)1- as.vector(logLik(swiss_prob)/logLik(swiss_prob0)1 0.1546416Percent correctly predicted:table(true=SwissLabor$participation,pred=round(fitted(swiss_prob) predtrue 0 1no 337 134yes 146 25567.89%ROC curve:TPR(c):the number of women participating in th
11、e labor force that are classified as participating compared with the total number of women participating.FPR(c):the number of women not participating in the labor force that are classified as participating compared with the total number of women not participating.ROCRpred=prediction(fitted(swiss_pro
12、b),SwissLabor$participation)plot(performance(pred,acctprfprabline(0,1,lty=2) Extensions: Multinomial responsesFor illustrating the most basic version of the multinomial logit model, a model with only individual-specific covariates,.BankWagesIt contains, for employees of a US bank, an ordered factor job with levels custodial, admin(for administration), and manage (for management), to be modeled as afunction of education (in years) and a factor minority indicating minority status. There also exists a factor gender, but since there are no women in the category custo