Skip to content

Instantly share code, notes, and snippets.

@marutter
Created October 1, 2010 00:39
Show Gist options
  • Save marutter/605547 to your computer and use it in GitHub Desktop.
Save marutter/605547 to your computer and use it in GitHub Desktop.
data <- read.csv("cdi.csv")
attach(data)
names(data)
plot(p.bach,per.cap.inc,pch=as.character(region),col=as.numeric(region))
resNC <- lm(per.cap.inc~p.bach,data[region=="NC",])
resNE <- lm(per.cap.inc~p.bach,data[region=="NE",])
resS <- lm(per.cap.inc~p.bach,data[region=="S",])
resW <- lm(per.cap.inc~p.bach,data[region=="W",])
confint(resNC,level=.90)
confint(resNE,level=.90)
confint(resS,level=.90)
confint(resW,level=.90)
abline(resNC)
abline(resNE,col="red")
abline(resS,col="green")
abline(resW,col="blue")
newdata <- data.frame(p.bach=seq(min(p.bach),max(p.bach),(max(p.bach)-min(p.bach))/45))
confNC <- predict(resNC,newdata,interval="confidence",level=.90)
confNE <- predict(resNE,newdata,interval="confidence",level=.90)
confS <- predict(resS,newdata,interval="confidence",level=.90)
confW <- predict(resW,newdata,interval="confidence",level=.90)
matlines(newdata$p.bach,confNC[,-1],col="black",lty=2)
matlines(newdata$p.bach,confNE[,-1],col="red",lty=2)
matlines(newdata$p.bach,confS[,-1],col="green",lty=2)
matlines(newdata$p.bach,confW[,-1],col="blue",lty=2)
par(mfrow=c(2,2))
plot(per.cap.inc~p.bach,data[region=="NC",],pch=20,main="North Central",
ylim=c(8800,40000),xlim=c(8,53))
abline(resNC)
matlines(newdata$p.bach,confNC[,-1],col="black",lty=2)
plot(per.cap.inc~p.bach,data[region=="NE",],pch=20,main="North East",
ylim=c(8800,40000),xlim=c(8,53))
abline(resNE)
matlines(newdata$p.bach,confNE[,-1],col="black",lty=2)
plot(per.cap.inc~p.bach,data[region=="S",],pch=20,main="South",
ylim=c(8800,40000),xlim=c(8,53))
abline(resS)
matlines(newdata$p.bach,confS[,-1],col="black",lty=2)
plot(per.cap.inc~p.bach,data[region=="W",],pch=20,main="West",
ylim=c(8800,40000),xlim=c(8,53))
abline(resW)
matlines(newdata$p.bach,confW[,-1],col="black",lty=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment