# データ解析基礎論A week09

```dat<-read.csv("http://www.matsuka.info/data_folder/datWA01.txt")
plot(dat\$shoesize, dat\$gender, pch=20, cex=3, xlab="Shoe size",
ylab="gender", col='blue', ylim = c(0.5, 2.5), yaxt="n")
axis(2, at = c(1,2),labels=c("female","male"))
dat.lm<-lm(as.numeric(dat\$gender)~dat\$shoesize,data=dat)
abline(dat.lm,lwd=4,col='red')

chisq.test(c(72,23,16,49),p=rep(40,4),rescale.p=T)
M=matrix(c(52,48,8,42),nrow=2)
chisq.test(M,correct=F)

plot(dat\$shoesize, dat\$gender, pch=20, cex=3, xlab="Shoe size",
ylab="gender", col='blue', ylim = c(0.5, 2.5), yaxt="n")
axis(2, at = c(1,2),labels=c("female","male"))
plot(dat\$shoesize, dat\$gender, pch=20, cex=3, xlab="Shoe size",
ylab="gender", col='blue', ylim = c(0.5, 2.5), yaxt="n")
axis(2, at = c(1,2),labels=c("female","male"))
abline(dat.lm,lwd=4,col='red')

p = seq(0.1,0.9,length.out = 20)
plot(p/(1-p),col="red",pch=20,cex=3)
plot(log(p/(1-p)),col="red",pch=20,cex=3)

dat.lr<-glm(gender~shoesize, family=binomial, data=dat)
x=seq((min(dat\$shoesize)-2), (max(dat\$shoesize)+2), 0.1)
keisu  = coef(dat.lr)
y.prob=1/(1+exp(-1*(keisu[1]+keisu[2]*x)))
plot(dat\$shoesize, dat\$gender, pch=20, cex=3, xlab="Shoe size",
ylab="gender", col='blue', ylim = c(0.5, 2.5), yaxt="n")
axis(2, at = c(1,2),labels=c("female","male"))
lines(x,y.prob+1,lty=2,lwd=4,col='green')
abline(dat.lm,lwd=4,col='red')

anova(dat.lr, test ="Chisq")

dat.lr0<-glm(gender~1,family="binomial",data=dat)
dat.lrS<-glm(gender~shoesize,family=binomial,data=dat)
dat.lrH<-glm(gender~h,family="binomial",data=dat)