library(car)
## Loading required package: carData
pacman::p_load(car)
class(Prestige)
## [1] "data.frame"
head(Prestige)
## education income women prestige census type
## gov.administrators 13.11 12351 11.16 68.8 1113 prof
## general.managers 12.26 25879 4.02 69.1 1130 prof
## accountants 12.77 9271 15.70 63.4 1171 prof
## purchasing.officers 11.42 8865 9.11 56.8 1175 prof
## chemists 14.62 8403 11.68 73.5 2111 prof
## physicists 15.64 11030 5.13 77.6 2113 prof
names(Prestige)
## [1] "education" "income" "women" "prestige" "census" "type"
dta<- Prestige
##aggregate數據分組再重整
dta <- aggregate((prestige~ type) , data=dta, FUN=mean)
head(dta)
## type prestige
## 1 bc 35.52727
## 2 prof 67.84839
## 3 wc 42.24348
dta1<- quantile(dta$prestige, probs=seq(from=0, to=1, by=.1))
dta1
## 0% 10% 20% 30% 40% 50% 60% 70%
## 35.52727 36.87051 38.21375 39.55700 40.90024 42.24348 47.36446 52.48544
## 80% 90% 100%
## 57.60642 62.72741 67.84839
dta1 <- with(dta, cut(prestige, ordered=T, breaks=c(0, 50, 100), labels=c("Low", "High")))
with(dta, table(dta1))
## dta1
## Low High
## 2 1
dta1
## [1] Low High Low
## Levels: Low < High
dtap <- aggregate(cbind(prestige, type) ~ dta1, data=dta, FUN=mean)
dtap
## dta1 prestige type
## 1 Low 38.88538 2
## 2 High 67.84839 2
library(tidyr)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following object is masked from 'package:car':
##
## recode
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
plot(x=Prestige$education, y=Prestige$income, main="income to education",xlab="educations",ylab="incomes")
require(lattice)
## Loading required package: lattice

Prestige$prestige <- as.factor(Prestige$prestige)
xyplot(income ~ education | dta1, data=Prestige, type=c("g","p","r"), auto.key=list(columns=2))
