library(XML)
library(RJSONIO)
library(reshape)
library(stringr)
library(dismo)
library(fields)
mydata <- read.csv("E:/MDCommColl.csv", header=T)
gc <- read.table("E:/geocode.txt", header=T)
total <- merge(mydata,gc,by="Address")
dfID<-(expand.grid(total$ID, total$ID))
dfRatio<-(expand.grid(total$ratio, total$ratio))
dfFA2012FT<-(expand.grid(total$FA2012FT, total$FA2012FT))
dfFA2012PT<-(expand.grid(total$FA2012PT, total$FA2012PT))
dfLONG<-(expand.grid(total$longitude, total$longitude))
dfLAT<-(expand.grid(total$latitude, total$latitude))
dfCOLL<-(expand.grid(total$College, total$College))
dfCOLL <- rename(dfCOLL, c(Var1="College", Var2="SameColl"))
dfID <- rename(dfID, c(Var1="ID", Var2="SameID"))
dfCOLL <- rename(dfCOLL, c(Var1="College", Var2="SameColl"))
dfLONG <- rename(dfLONG, c(Var1="longitude", Var2="SameLong"))
dfLAT <- rename(dfLAT, c(Var1="latitude", Var2="SameLat"))
dfFA2012FT <- rename(dfFA2012FT, c(Var1="FA2012FT", Var2="SameFT"))
dfFA2012PT <- rename(dfFA2012PT, c(Var1="FA2012PT", Var2="SamePT"))
dfRatio <- rename(dfRatio, c(Var1="ratio", Var2="SameRatio"))
df <- cbind (dfID, dfRatio, dfLONG, dfLAT, dfCOLL, dfFA2012FT, dfFA2012PT)
df$R <- 6371 # Earth mean radius in km
deg2rad = pi / 180
dlat = deg2rad * (df$SameLat - df$latitude)
dlon = deg2rad * (df$SameLon - df$longitude)
a = sin(dlat / 2) * sin(dlat / 2) + cos(deg2rad * df$latitude) * cos(deg2rad * df$SameLat) * sin(dlon / 2) * sin(dlon / 2)
c = 2 * asin(sqrt(a))
df$miles = df$R * c * 0.621371
df$enrollment.distance.ft = df$FA2012FT*(df$miles**-2)*df$ratio
df$enrollment.distance.pt = df$FA2012PT*(df$miles**-2)*df$ratio
df2 <- df[ which(df$ID!=df$SameID), ]
enrollment.distance.ft.agg <-aggregate(x=df2$enrollment.distance.ft, by=list(ID=df2$SameID), FUN=c("sum"), na.rm=TRUE)
enrollment.distance.pt.agg <-aggregate(x=df2$enrollment.distance.pt, by=list(ID=df2$SameID), FUN=c("sum"), na.rm=TRUE)
enrollment.distance.ft.agg <- rename(enrollment.distance.ft.agg, c(x="d.ft"))
enrollment.distance.pt.agg <- rename(enrollment.distance.pt.agg, c(x="d.pt"))
write.csv(df, "E:/df.csv")
total <- merge(mydata,enrollment.distance.ft.agg,by="ID")
total <- merge(total,enrollment.distance.pt.agg,by="ID")
total$competition.index.ft = (1/total$FA2012FT)*total$ratio*(total$d.ft)
total$competition.index.pt = (1/total$FA2012PT)*total$ratio*(total$d.pt)
write.csv(total, "E:/ci.csv")
(The formula for competition indices is adapted from Misra and Chi (2011) but the ratio of student credit hours to faculty hours taught was added to the equation).
Figure 1. Competition indices - full time enrollment
library(maps)
library(mapproj)
library(RColorBrewer)
library(classInt)
total <- merge(total,gc,by="Address")
map("county", "maryland")
map.axes()
plotvar <- total$competition.index.ft
nclr <- 8
plotclr <- brewer.pal(nclr,"BuPu")
max.symbol.size=10
min.symbol.size=1
class <- classIntervals(plotvar, nclr, style="quantile")
colcode <- findColours(class, plotclr)
symbol.size <- ((plotvar-min(plotvar))/
(max(plotvar)-min(plotvar))*(max.symbol.size-min.symbol.size)
+min.symbol.size)
points(total$longitude, total$latitude, pch=16, col=colcode, cex=symbol.size)
points(total$longitude, total$latitude, cex=symbol.size)
text(-120, 46.5, "Competition indices - full time enrollment")
legend(locator(1), legend=names(attr(colcode, "table")), fill=attr(colcode, "palette"), cex=0.6, bty="n")
Figure 2. Competition indices - part time enrollment
library(maps)
library(mapproj)
library(RColorBrewer)
library(classInt)
total <- merge(total,gc,by="Address")
map("county", "maryland")
map.axes()
plotvar <- total$competition.index.pt
nclr <- 8
plotclr <- brewer.pal(nclr,"BuPu")
max.symbol.size=10
min.symbol.size=1
class <- classIntervals(plotvar, nclr, style="quantile")
colcode <- findColours(class, plotclr)
symbol.size <- ((plotvar-min(plotvar))/
(max(plotvar)-min(plotvar))*(max.symbol.size-min.symbol.size)
+min.symbol.size)
points(total$longitude, total$latitude, pch=16, col=colcode, cex=symbol.size)
points(total$longitude, total$latitude, cex=symbol.size)
text(-120, 46.5, "Competition indices - part time enrollment")
legend("bottomleft", inset=.05, title="Competition indices - part time",
legend=names(attr(colcode, "table")), fill=attr(colcode, "palette"), horiz=FALSE)