#======================================================= # R code that illustrates baseline category logit models # using the alligator data described in section 6.3.2 #======================================================= # Read aligator data from the web: data="http://www.stat.ufl.edu/~aa/glm/data/Alligators.dat" alligators = read.table(data, header = T) alligators # We will use teh VGAM library: library(VGAM) #====================== # Fit model #====================== # We fit a baseline category logit model with size and lake as #main effects and fish (y1) as the reference category: fit.main=vglm(cbind(y2,y3,y4,y5,y1)~size+factor(lake), family=multinomial, data=alligators) summary(fit.main) #============================ # Test if size has an effect: #============================ # Fit model with only lake: fit.lake=vglm(cbind(y2,y3,y4,y5,y1)~factor(lake),family=multinomial, data=alligators) summary(fit.lake) # Test if there is an effect of size G2=deviance(fit.lake)-deviance(fit.main) G2 df.diff=df.residual(fit.lake)-df.residual(fit.main) df.diff 1-pchisq(G2,df.diff) # Size has a significant effect #============================ # Test if lake has an effect: #============================ # Fit model with only size: fit.size=vglm(cbind(y2,y3,y4,y5,y1)~size,family=multinomial, data=alligators) summary(fit.size) # Test if there is an effect of lake G2=deviance(fit.size)-deviance(fit.main) G2 df.diff=df.residual(fit.size)-df.residual(fit.main) df.diff 1-pchisq(G2,df.diff) # Lake has a significant effect