1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
### Lab 04 ###
# For this lab you will create a categorical factor
# by binning the continuous income variable. First
# get the cut points for quantiles on income.
qtls <- quantile(x = Prestige$income, probs = c(.25, .5, .75))
qtls

# Now create a factor variable with four factors based
# on the cutpoints.
incomeF <- numeric(dim(Prestige)[1])
incomeF[which(Prestige$income < 4250.5)] <- "lowest"
incomeF[which(Prestige$income >= 4250.5 & Prestige$income < 6035.5)] <- "low"
incomeF[which(Prestige$income >= 6035.5 & Prestige$income < 8226.25)] <- "high"
incomeF[which(Prestige$income >= 8226.25)] <- "highest"
Prestige$incomeF <- factor(incomeF)
head(Prestige)
str(Prestige)

Prestige$incomeF <- relevel(Prestige$incomeF, ref = "lowest")
levels(Prestige$incomeF) # "wc" will be reference
lm2 <- lm(prestige ~ type, data = Prestige)
summary(lm2)
# Your task for lab is to run one-way ANOVA to assess the
# effect of income on prestige. If you find an overall effect,
# follow up with pairwise comparisons and describe the results.
# Finally, check for a significant difference in the average of
# prestige of lowest and low vs the averge prestige of high and
# highest. Be sure to check assumptions.