# STA 437/1005 Assignment 1, Question 4. # Read the data into a data frame. d <- read.table("smog.txt",head=T) # Put plots in a PDF file (one per page). pdf("ass1-plots.pdf",pointsize=9) # Scatterplots against year and against month. par(mfrow=c(4,4)) for (i in 4:10) { boxplot(d[,i]~d$year,xlab="year",ylab=colnames(d)[i]) boxplot(d[,i]~d$month,xlab="month",ylab=colnames(d)[i]) } # Produce all pairs of scatterplots, except those involving the year/month/day. plot(d[-(1:3)],pch=".") # Histograms of variables other than year/month/day. par(mfrow=c(3,3)) for (i in 4:10) { hist(d[,i],nclass=30,xlab=colnames(d)[i],main="Histogram") } # Normal QQ plots of variables other than year/month/day. par(mfrow=c(3,3)) for (i in 4:10) { qqnorm(d[,i],xlab=colnames(d)[i],pch=".") } # Histograms and normal QQ plots for some transformed variables. par(mfrow=c(3,3)) hist(sqrt(d$deaths),nclass=30,xlab="Square root of deaths",main="Histogram") qqnorm(sqrt(d$deaths),xlab="Square root of deaths",pch=".") hist(sqrt(d$so2),nclass=30,xlab="Square root of so2",main="Histogram") qqnorm(sqrt(d$so2),xlab="Square root of so2",pch=".") hist(sqrt(d$ozone),nclass=30,xlab="Square root of ozone",main="Histogram") qqnorm(sqrt(d$ozone),xlab="Square root of ozone",pch=".") hist(log(d$pm10),nclass=30,xlab="Log of pm10",main="Histogram") qqnorm(log(d$pm10),xlab="Log of pm10",pch=".") # Make new data frame with some variables transformed. nd <- d nd$deaths <- sqrt(d$deaths); colnames(nd)[4] <- "sqrt deaths" nd$so2 <- sqrt(nd$so2); colnames(nd)[8] <- "sqrt so2" nd$ozone <- sqrt(nd$ozone); colnames(nd)[9] <- "sqrt ozone" nd$pm10 <- log(nd$pm10); colnames(nd)[10] <- "log pm10" # Produce all pairs of scatterplots, with some variables transformed, except # those involving the year/month/day. plot(nd[-(1:3)],pch=".") # Done with plotting. dev.off()