rm(list = ls()) oring.sllr <- read.table( url("http://stat.unm.edu/~fletcher/LLM/DATA/TAB2-1.DAT"), #"C:\\E-drive\\Books\\ANREG2\\newdata\\tab20-3.dat", #"C:\\E-drive\\Books\\LOGLIN3\\DATA\\tab2-1.dat", sep="",col.names=c("Case","Flt","f","s","x","no")) attach(oring.sllr) oring.sllr #summary(oring.sllr) # Construct data for log-linear model # Sting out the failures followed by successes cnt=c(f,s) # The temp for each element of cnt xx=c(x,x) # The row of the table for each element of cnt row=c(Case,Case) # The col. of the table for each element of cnt # For binary data, f+s=1 # first 23 obs. are first col, 2nd 23 are 2nd col. col=c(f+s,2*(f+s)) # check that the table is correct matrix(c(cnt,row,col),ncol=3) # Fit log-linear model R=factor(row) C=factor(col) fit=glm(cnt ~ R + C + C:xx, family=poisson) summary(fit) anova(fit)