#Ex embryogenic anther (Sec 7.4.1) yea = c(55,52,57,55,50,50) nea = c(102,99,108,76,81,90) storage = c(1,1,1,2,2,2) centrifuge=c(40,150,350,40,150,350) lcentrifuge=log(centrifuge) plot(lcentrifuge,yea/nea) points(lcentrifuge[1:3],yea[1:3]/nea[1:3],col='red') #R wants indata as [y, n-y] yeain=matrix(c(yea,nea-yea),6,2) #logit Model 1 res1=glm(yeain~storage*lcentrifuge, family=binomial(link="logit")) summary(res1) res2=glm(yeain~storage+lcentrifuge, family=binomial(link="logit")) summary(res2) res3=glm(yeain~lcentrifuge, family=binomial(link="logit")) summary(res3) res4=glm(yeain~1, family=binomial(link="logit")) summary(res4) #House sparrows dispersal ~ wing length #Make design #Make one specific dataset set.seed(555) N=1000; #Set true parameters beta0 = -4; beta1 = 0.5; #Sample some covariates/measurments x1=rnorm(N,5,0.3) #Calculate mu eta = beta0 + beta1*x1; #Use probit link p=pnorm(eta,0,1); #Simulate data y=rbinom(rep(1,N),rep(1,N),p) sum(y) plot(x1,y,xlab='Wing length', ylab='Dispersed') plot(x1,p,xlab='Wing length', ylab='Probability of dispersal') #R wants indata as [y, n-y] respin=matrix(c(y,rep(1,N)-y),N,2) resultprobit = glm(respin~x1, family=binomial(link="probit")) summary(resultprobit) fittedprobit=resultprobit$fitted; plot(x1,fittedprobit) #Use logit link instead resultlogit = glm(respin~x1, family=binomial(link="logit")) summary(resultlogit) fittedlogit=resultlogit$fitted; points(x1,fittedlogit,col='blue') #Use cloglog link instead resultcloglog = glm(respin~x1, family=binomial(link="cloglog")) summary(resultcloglog) fittedcloglog=resultcloglog$fitted; points(x1,fittedcloglog,col='green') plot(x1,resultlogit$res)