Skip to content

Instantly share code, notes, and snippets.

@marutter
Created November 10, 2010 14:33
Show Gist options
  • Select an option

  • Save marutter/670918 to your computer and use it in GitHub Desktop.

Select an option

Save marutter/670918 to your computer and use it in GitHub Desktop.
data <- read.csv("salary.csv")
attach(data)
# Analysis
#
# Different intercept, same slope
res1 <- lm(Salary~YSdeg+Sex)
summary(res1)
# Different slope, same intercept
res2 <- lm(Salary~YSdeg+Sex:YSdeg)
summary(res2)
# Different intercept and slop
res3 <- lm(Salary~YSdeg+Sex+Sex:YSdeg)
summary(res3)
res0 <- lm(Salary~YSdeg)
res4 <- lm(Salary~YSdeg+Sex:YSdeg+Rank)
res5 <- lm(Salary~YSdeg+Sex:YSdeg+Rank+Rank:YSdeg)
res6 <- lm(Salary~YSdeg+Sex+Rank+YSdeg:Sex+YSdeg:Rank)
AIC(res0)
AIC(res1)
AIC(res2)
AIC(res3)
AIC(res4)
AIC(res5)
AIC(res6)
#BIC
AIC(res0,k=log(length(Salary)))
summary(res5)
library(car)
colnames(model.matrix(res5))
# Assitant vs. Assoc Prof
hm <- c(0,0,1,-1,0,0,0)
linearHypothesis(res5,hm,0)
# Male Asst Prof with 6 years vs. Female Assoc with 10 years
hm <- c(0,-4,1,0,6,6,0)
linearHypothesis(res5,hm,0)
# Confidence intervals for the two professors
xn <- data.frame(YSdeg=c(6,10),Rank=c("Asst Prof","Assoc Prof"),Sex=c("Male","Female"))
predict(res5,xn,interval="confidence")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment