# --------------------------------------------------------------------- # Program: Bivariate1.S # Author: Steven M. Boker # Date: Tue Oct 3 08:10:36 EDT 2006 # # Bivariate data # # --------------------------------------------------------------------- # ---------------------------------------------- # Load required libraries library(lattice) # ------------------------------------------------ # Read the iris data. iris <- data.frame(read.table("iris.dat", header=T)) summary(iris) source("edaStudent.sdd") summary(edaStudent) # --------------------------------------------------------------------- # Scatterplots pdf("Biv1ZtestPlot1.pdf", height=5, width=5) plot(edaStudent$ztest, edaStudent$hscgpa, xlab="Entrance Exam (Z-Score)", ylab="High School Core GPA", type='p', pch=2) dev.off() pdf("Biv1HSCGPAXYPlot1.pdf", height=5, width=5) print(xyplot(hscgpa ~ ztest, data = edaStudent, aspect=1, xlab = list(label="Entrance Exam (Z-Score)",cex=1.25), ylab=list(label="High School Core GPA",cex=1.25), scales=list(cex=1.25) ) ) dev.off() pdf("Biv1ZtestXYPlot0.pdf", height=5, width=5) print(xyplot(ztest ~ sex, data = edaStudent, aspect=1, xlab = list(label="Sex",cex=1.25), ylab=list(label="Entrance Exam (Z-Score)",cex=1.25), scales=list(cex=1.25) ) ) dev.off() pdf("Biv1ZtestXYPlot1.pdf", height=5, width=5) print(xyplot(ztest ~ jitter(as.numeric(sex), .5), data = edaStudent, aspect=1, xlab = list(label="Sex",cex=1.25), ylab=list(label="Entrance Exam (Z-Score)",cex=1.25), scales=list(cex=1.25) ) ) dev.off() # --------------------------------------------------------------------- # Scatterplots conditioned on a factor pdf("Biv1HSCGPAXYPlot2.pdf", height=5, width=6) print(xyplot(hscgpa ~ ztest | sex, data = edaStudent, aspect=1, xlab = list(label="Entrance Exam (Z-Score)",cex=1.25), ylab=list(label="High School Core GPA",cex=1.25), scales=list(cex=1.25) ) ) dev.off() # --------------------------------------------------------------------- # Scatterplots conditioned on a factor pdf("Biv1IrisPlot1.pdf", height=5, width=5) print(xyplot(petal.length ~ petal.width | variety, data = iris, aspect=1, xlab = list(label="Petal Length",cex=1.25), ylab=list(label="Petal Width",cex=1.25), scales=list(cex=1.25) ) ) dev.off() pdf("Biv1IrisPlot2.pdf", height=5, width=5) print(xyplot(sepal.length ~ sepal.width | variety, data = iris, aspect=1, xlab = list(label="Sepal Length",cex=1.25), ylab=list(label="Sepal Width",cex=1.25), scales=list(cex=1.25) ) ) dev.off() # --------------------------------------------------------------------- # Scatterplots conditioned on a continuous variable pdf("Biv1HSCGPAXYPlot3.pdf", height=5, width=6) print(xyplot(hscgpa ~ ztest | cut(pposths,6), data = edaStudent, aspect=1, main=list("HSCGPA vs. ZTEST \n Cut by Probability of Post HS in Neighborhood",cex=1.25), xlab = list(label="Entrance Exam (Z-Score)",cex=1.25), ylab=list(label="High School Core GPA",cex=1.25), scales=list(cex=1.25) ) ) dev.off() # --------------------------------------------------------------------- # Estimating a linear model tLM <- lm(hscgpa ~ ztest, data=edaStudent) summary(tLM) # --------------------------------------------------------------------- # Plotting a regression line pdf("Biv1HSCGPAXYPlot4.pdf", height=5, width=5) print(xyplot(hscgpa ~ ztest, data = edaStudent, panel = function(x, y) { panel.xyplot(x, y) panel.abline(lm(hscgpa ~ ztest, data = edaStudent)) }, aspect=1, xlab = list(label="Entrance Exam (Z-Score)",cex=1.25), ylab=list(label="High School Core GPA",cex=1.25), scales=list(cex=1.25) ) ) dev.off()