faculty <- read.csv("/Users/kennetheggering/dropbox/GEOG 5023 - Spring 2013/Data/faculty.csv",
header = T)
################################ Begin Question 1 ###############################
### display the names of columns
colnames(faculty)
## [1] "AYSALARY" "R1" "R2" "R7" "PRIOREXP" "YRBG"
## [7] "YRRANK" "TERMDEG" "YRDG" "EMINENT" "FEMALE"
### display the number of rows (i.e. observations)
nrow(faculty)
## [1] 725
### display the number of columns(i.e. variables)
ncol(faculty)
## [1] 11
################################ End Question 1 ###############################
#
#
#
#
#
################################ Begin Question 2 ############################### dev.off()
### Assuming I (R) calculated the mean correctly, there is a tail on the
### right of the histogram. With the exception of that tail, the rest of
### the histogram is 'nicely' distributed. So, no. Salaries are not
### evenly distributed.
### make a swanky looking histogram of Profs salaries###
hist(faculty$AYSALARY, col = "deepskyblue3", breaks = seq(22000, 120000, by = 2000),
xlab = "Academic year salary", main = "Salaries", ylab = "What's the Frequency, Kenneth?")
### insert mean numerical info
mtext(paste("mean $", round(mean(faculty$AYSALARY), 1)))
### insert tick marks on x-axis, 1/4 height of standard R tick marks###
### 'nx=10' tick marks = $2000 intervals
minor.tick(nx = 10, ny = 10, tick.ratio = 1/4)
## Error: could not find function "minor.tick"
### insert tick marks on x-axis, 3/4 height of standard R tick marks###
### 'nx=2' tick marks = $10000 intervals
minor.tick(nx = 2, ny = 2, tick.ratio = 3/4)
## Error: could not find function "minor.tick"
### insert mean line
abline(v = mean(faculty$AYSALARY), col = "green")
### change visuals (such as graphs) from scientific notation to real
### numbers- (¿pienso que 0='yes' SN, 1='no' SN ?not sure? Seth?)###
getOption("scipen")
## [1] 0
options(scipen = 1)
### re-execute the hist command
################################ End Question 2 ###############################
#
#
#
#
#
################################ Begin Question 3 ###############################
### create box plot of male/female salaries I wanted to play with colors,
### but had no luck, kept the strange code I found online, though. it does
### appear there is a difference between male and female faculty members
boxplot(faculty$AYSALARY ~ faculty$FEMALE, main = "Gender salaries", ylab = "Academic Year Salary",
xlab = "Male Female", col = rep(seq(ncol(faculty)) +
2, each = 1, ))
### insert tick marks on y-axis, 1/4 height of standard R tick marks###
### 'nx=10' tick marks = $2000 intervals
minor.tick(nx = 0, ny = 10, tick.ratio = 1/4)
## Error: could not find function "minor.tick"
### insert tick marks on y-axis, 5/8 height of standard R tick marks###
### 'nx=2' tick marks = $10000 intervals
minor.tick(nx = 0, ny = 2, tick.ratio = 5/8)
## Error: could not find function "minor.tick"
################################ End Question 3 ###############################
#
#
#
#
#
################################ Begin Question 4 ###############################
plot(faculty$AYSALARY ~ faculty$YRBG,
main = "Relationship Between Salary\n and Years On the Job",
ylab = "Salary",
xlab = "Years Teaching",
font.axis = 2, ###Display axis tick labels in bold
pch = 18, ylim = c(20000, 120000))
###insert tick marks on y-axis, 1/4 height of standard R tick marks### "nx=10" tick marks = $2000 intervals
minor.tick(nx=10, ny=10, tick.ratio=1/4)
## Error: could not find function "minor.tick"
###insert tick marks on y-axis, 5/8 height of standard R tick marks### "nx=2" tick marks = $10000 intervals
minor.tick(nx=2, ny=2, tick.ratio=5/8)
## Error: could not find function "minor.tick"
Salary.model <- lm(faculty$AYSALARY ~ faculty$YRBG)
summary(Salary.model)
##
## Call:
## lm(formula = faculty$AYSALARY ~ faculty$YRBG)
##
## Residuals:
## Min 1Q Median 3Q Max
## -25227 -6879 -2594 5533 61804
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 36878.8 660.7 55.8 <2e-16 ***
## faculty$YRBG 871.7 41.4 21.1 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 11000 on 723 degrees of freedom
## Multiple R-squared: 0.38, Adjusted R-squared: 0.379
## F-statistic: 444 on 1 and 723 DF, p-value: <2e-16
abline(coef(Salary.model), col="blue", lwd =2)
###insert mean numerical info
mtext(paste("R^2 = .3794, P-value= .000000000000000016"))
################################ End Question 4 ###############################
#
#
#
#
#
################################ Begin Question 5 ###############################
### I struggled with this problem. Didn't know what to google. I initially
### answered the question by creating 3 individual plots. Then I cheated
### and went to Alex Crawford's submission. So, credit goes to him for
### the 4th plot in my panel.
### Here are the 3 scatter plots I initially made, and the 'par' command.
### set up paneling for graphs
par(mfrow = c(2, 2))
### plot Full Prof salary
boxplot(faculty$AYSALARY[faculty$R1 == "1"], main = "Full Prof Salary", ylab = "Annual Salary",
xlab = "Full Professor", ol = "red")
### insert tick marks on y-axis, 1/4 height of standard R tick marks###
### 'nx=10' tick marks = $2000 intervals
minor.tick(nx = 10, ny = 10, tick.ratio = 1/4)
## Error: could not find function "minor.tick"
### insert tick marks on y-axis, 5/8 height of standard R tick marks###
### 'nx=2' tick marks = $10000 intervals
minor.tick(nx = 2, ny = 2, tick.ratio = 5/8)
## Error: could not find function "minor.tick"
### plot Associate Prof Salary
boxplot(faculty$AYSALARY[faculty$R2 == "1"], main = "Associate Prof Salary",
ylab = "Annual Salary", xlab = "Associate Professor", col = "green")
### insert tick marks on y-axis, 1/4 height of standard R tick marks###
### 'nx=10' tick marks = $2000 intervals
minor.tick(nx = 10, ny = 10, tick.ratio = 1/4)
## Error: could not find function "minor.tick"
### insert tick marks on y-axis, 5/8 height of standard R tick marks###
### 'nx=2' tick marks = $10000 intervals
minor.tick(nx = 2, ny = 2, tick.ratio = 5/8)
## Error: could not find function "minor.tick"
### plot Instructor Salary
boxplot(faculty$AYSALARY[faculty$R7 == "1"], main = "Instructor Salary", ylab = "Annual Salary",
xlab = "Instructor", col = "blue")
### insert tick marks on y-axis, 1/4 height of standard R tick marks###
### 'nx=10' tick marks = $2000 intervals
minor.tick(nx = 10, ny = 10, tick.ratio = 1/4)
## Error: could not find function "minor.tick"
### insert tick marks on y-axis, 5/8 height of standard R tick marks###
### 'nx=2' tick marks = $10000 intervals
minor.tick(nx = 2, ny = 2, tick.ratio = 5/8)
## Error: could not find function "minor.tick"
### begin copy/paste of Alex Crawford's code I added tick marks to his
### work
faculty$Rank[faculty$R1 == 1] <- 1
faculty$Rank[faculty$R2 == 1] <- 2
faculty$Rank[faculty$R7 == 1] <- 3
boxplot(faculty$AYSALARY ~ faculty$Rank, main = "Annual Salary \nby Rank",
ylab = "Annual Salary ($)", xlab = "1 = FP, 2 = AP, 3 = I/L", col = rainbow(3))
### insert tick marks on y-axis, 1/4 height of standard R tick marks###
### 'nx=10' tick marks = $2000 intervals
minor.tick(nx = 10, ny = 10, tick.ratio = 1/4)
## Error: could not find function "minor.tick"
### insert tick marks on y-axis, 5/8 height of standard R tick marks###
### 'nx=2' tick marks = $10000 intervals
minor.tick(nx = 2, ny = 2, tick.ratio = 5/8)
## Error: could not find function "minor.tick"
### end copy/paste of Alex Crawford's code
dev.off()
################################ End Question 5 ###############################
###experimental stuff faculty$Females[faculty$FEMALE == 1] <- T faculty$Males[faculty$FEMALE == 0] <- T colnames(faculty)
####experimental notes: I tried to convert the numeric values in the FEMALE column to “true /"false” ###gave up. Ask about later str(faculty, nchar.max=all, give.length=T)