##create two binary vectors of lenght 100 x=sample(c(0,1),100, replace=T) y=sample(c(0,1),100, replace=T) ##set up a basic dataset with two 100 rows and two columns xydata=cbind(x,y) xydata ##create a 2x2 table with counts xytab=table(x,y) xytab count=cbind(xytab[,2],xytab[,1]) count xfactor=factor(c("0","1")) xfactor ##create a dataframe with 4 rows and counts in the Freq column xydf=as.data.frame(xytab) xydf ##logistic regression models ## tmp1, tmp2 and tmp3 all fit the same simple logistic regression model tmp1=glm(y~x, family=binomial("logit")) tmp2=glm(as.factor(y)~as.factor(x), family=binomial("logit")) tmp3=glm(count~xfactor, family=binomial("logit")) tmp4=glm(count~1, family=binomial("logit")) ## intercept only model ##loglinear modelss tmp5=glm(xydf$Freq~xydf$x+xydf$y, family=poisson("log")) ## loglinear model tmp6=loglin(xytab, list(c(1,2)), fit=TRUE, param=TRUE) tmp7=loglin(xytab, list(1,2), fit=TRUE, param=TRUE) ##chi-square test of independence tmp8=chisq.test(xytab, correct=FALSE)