## typing in the data, the target y is the fraction of UK pupils admitted into Oxf/Cam ## the explanatory variable x is school_month birth_month <- c(9:12,1:8) school_month <- 0:11 number_admissions <- c(470,515,470,457,473,381,466,457,437,396,384,394) number_pupils <- c(66776,64167,59603,62877,62543,57597,65319,62651,65454,64429,64612,62738) y <- 100* number_admissions / number_pupils ## use pdf command to generate a pdf of the data plot; leave it and dev.off() away if you just want to generate a plot on the screen pdf(file="admission.pdf",width=6,height=6) plot(school_month, y, xlab="MONTHS AFTER SCHOOL YEAR STARTS",ylab="ADMISSION RATE INTO OXFORD/CAMBRIDGE (%)",pch=20,cex=2) dev.off() ## fit a linear model with y as response variable and school_month as explanatory variable linmod <- lm( y ~ school_month ) ## generate a plot as before but add the regression line in red pdf(file="admission_fit.pdf",width=6,height=6) plot(school_month, y,xlab="MONTHS AFTER SCHOOL YEAR STARTS",ylab="ADMISSION RATE INTO OXFORD/CAMBRIDGE (%)",pch=20,cex=2) lines(school_month, fitted(linmod),col="red",lwd=2) dev.off()