#load&see (use lecture note p.3)
library(datasets)
fL <- "http://www.amstat.org/publications/jse/datasets/sat.dat.txt"
dta <- read.table(fL, row.names=1)
names(dta) <- c("Spending", "PTR", "Salary", "PE", "Verbal", "Math", "SAT")
str(dta)
## 'data.frame': 50 obs. of 7 variables:
## $ Spending: num 4.41 8.96 4.78 4.46 4.99 ...
## $ PTR : num 17.2 17.6 19.3 17.1 24 18.4 14.4 16.6 19.1 16.3 ...
## $ Salary : num 31.1 48 32.2 28.9 41.1 ...
## $ PE : int 8 47 27 6 45 29 81 68 48 65 ...
## $ Verbal : int 491 445 448 482 417 462 431 429 420 406 ...
## $ Math : int 538 489 496 523 485 518 477 468 469 448 ...
## $ SAT : int 1029 934 944 1005 902 980 908 897 889 854 ...
#devide the region
dta$Region <- state.division
with(dta, table(Region))
## Region
## New England Middle Atlantic South Atlantic East South Central
## 6 3 8 4
## West South Central East North Central West North Central Mountain
## 4 5 7 8
## Pacific
## 5
#SAT by Salary
library(lattice)
xyplot(SAT ~ Salary, groups=Region, data=dta, type=c("g","r"), auto.key=list(columns=3))

#students’ SAT score was negatively associated with teachers’ salary in New England, East South Central, West South Central, West North Central and Mountain