bitten<-sample(c(0,1),100,replace=TRUE,prob=c(0.4,0.6))
sex<-sample(c("Male","Female"),100,replace=TRUE,prob=c(0.5,0.5))
hab<-sample(c("Forest","Savannah"),100,replace=TRUE,prob=c(0.3,0.7))
sp<-sample(c("Cobra","Viper","Mamba","Boomslang"),100,replace=TRUE,
prob=c(0.4,0.25,0.2,0.15))
testdat<-data.frame(bitten,sex,hab,sp)
# Single binary variable in model
testmod1<-glm(bitten~sex,data=testdat,family=binomial)
LRbarplot(testmod1,parIndex=2,yName="receiving bite",
xLevels=levels(as.factor(testdat$sex)),cex.lab=1.5,cex.axis=1.5,
cex.names=1.5,col=c("coral1","cornflowerblue"))
mtext("Sex",line=3,adj=0.5,font=2,cex=1.5, side=1)
# Single 4-level variable in model
testmod2<-glm(bitten~sp,data=testdat,family=binomial)
LRbarplot(testmod2,parIndex=2:4,yName="receiving bite",
xLevels=levels(as.factor(testdat$sp)),cex.lab=1.5,cex.axis=1.5,
cex.names=1.5,col=c("green","tan2","ivory4","sienna"))
mtext("Species",line=3,adj=0.5,font=2,cex=1.5, side=1)
# Plotting the second of two binary variables in the model
testmod3<-glm(bitten~sex+hab,data=testdat,family=binomial)
LRbarplot(testmod3,parIndex=3,yName="receiving bite",
xLevels=levels(as.factor(testdat$hab)),cex.lab=1.5,cex.axis=1.5,
cex.names=1.5,col=c("dark green","light yellow"))
mtext("Habitat",line=3,adj=0.5,font=2,cex=1.5, side=1)
Run the code above in your browser using DataLab