{ # Logistic Regression #Problem 15-1 of Helsel book.. test=matrix(scan("prob-15-1.txt"), ncol=5, byrow=T) y = test[,5] x = test[,1:4] N = length(y) #Fit a logistic model to all the variables.. logcalib=glm(y ~ x,family="binomial") #estimate the value at the data points logpred=predict.glm(logcalib,data.frame(x=x),se.fit=T,type="response") plot(y,logpred$fit,xlab="Actual",ylab="Estimated",cex=1.5) # provide the ANOVA table # summary(logcalib) #commands for x-validated estimates.. # PART - II X-validated estimates.. yxval=1:N positions = 1:N for( ypos in 1:N){ positions1=positions[positions!=ypos] positions2=positions[positions==ypos] yy=y[positions1] xx=x[positions1,] xxpred=x[positions2,] logcalib=glm(yy~xx,family="binomial") xx[1,]=xxpred logpred=predict.glm(logcalib,data.frame(xx=xx),se.fit=T,type="response") yxval[ypos]=logpred$fit[1] } #Loop ends for each cross validated year plot(y,yxval,xlab="Actual",ylab="Estimated",cex=1.5) } #End of the Program