table=read.delim("US_Temp.txt")
attach(table)
#Scatterplot
plot(Lat,JanTemp,col="green")
cor(Lat,JanTemp)

#Simple linear regression
temp.lm=lm(JanTemp~Lat)
temp.lm
summary(temp.lm)
#Add the regression line
abline(temp.lm,col="purple")

res=resid(temp.lm)
res
#Plot the residuals
plot(Lat,resid(temp.lm),col="red")
abline(0,0,col="blue")

#Delete observation 52.
table_New=table[c(-52),]
JanTemp_New=table_New$JanTemp
Lat_New=table_New$Lat
cor(JanTemp_New,Lat_New)

#Delete observation 52.
temp.lm2=lm(JanTemp~Lat,subset=c(-52))
temp.lm2
#Plot the two regression line in the same scatterplot
plot(Lat,JanTemp,col="green")
abline(temp.lm,col="purple")
abline(temp.lm2,col="red",lty=3)
legend("bottomleft",c("with all data","without obs 52"),cex=0.9,lty=c(1,3),col=c("purple","red"))


#Predicted values
newdata=data.frame(Lat=49)
predict(temp.lm,newdata)
predict(temp.lm2,newdata)


#Plot with characters
plot(Lat,JanTemp,col="darkgreen",pch=as.character(City))





