##Example 2.1.1 ex.data<-matrix(c(309,191,319,281), ncol=2, byrow=2) dimnames(ex.data)<-list(Gender=c("Female", "Male"), Attitude=c("Support","Do not support")) ex.data prop.test(ex.data,correct=F) #only applies to I*2 tables chisq.test(ex.data, correct=F) #apply to general I*J tables testresult<-prop.test(ex.data,correct=F) testresult$estimate[1]/testresult$estimate[2] odds<-testresult$estimate/(1- testresult$estimate) odds odds[1]/odds[2] %Odds Ratio% #expected values rowsum<-apply(ex.data,1,sum) colsum<-apply(ex.data,2,sum) n<-sum(ex.data) mij<-outer(rowsum,colsum/n,make.dimnames=T) mij #residuals rowp<-rowsum/n #Row marginal prob. colp<-colsum/n #Column marginal prob. resid<-(ex.data-mij)/sqrt(mij) resid fisher.test(ex.data,alternative="greater") ##logistic regression #illustration mu<--2 sigma<-2 #Examples for f(-2) and F(-2) dlogis(x = -2, location = mu, scale = sigma) plogis(q = -2, location = mu, scale = sigma) win.graph(width = 10, height = 6, pointsize = 12) par(mfrow = c(1,2)) par(pty="s") curve(expr = dlogis(x = x, location = mu, scale = sigma), ylab = "f(x)", xlab = "x", xlim = c(-15, 15), main = "PDF", col = "red", panel.first = grid(col = "gray", lty = "dotted"), n = 1000) abline(h = 0) curve(expr = plogis(q = x, location = mu, scale = sigma), ylab = "F(x)", xlab = "x", xlim = c(-15, 15), main = "CDF", col = "red", panel.first = grid(col = "gray", lty = "dotted"), n = 1000) abline(h = c(0,1))