install.packages("car")
library(car)

#read csv file
csvfile=file.path("D:/Users/Administrator/Desktop/DrivingForce.csv")

ESsTrads.STD=read.csv(csvfile,header=TRUE,sep=",")


attach(ESsTrads.STD)
#detach(ESsTrads.STD)

#Sheep	
model<-lm(SHEEP~aPRCP2+TEM10+farmlandLUi+GrassLUi+agriCapa+POP,data=ESsTrads.STD)
#summary(model)
vif(model) 
mstep<-step(model)   #stepwise
summary(mstep)      
vif(mstep)

#Grain
model<-lm(GRAIN~aPRCP2+TEM10+farmlandLUi+GrassLUi+agriCapa+POP,data=ESsTrads.STD)
#summary(model)
vif(model) 
mstep<-step(model)  #stepwise
summary(mstep)      

#NPP
model<-lm(NPP~aPRCP2+TEM10+farmlandLUi+GrassLUi+agriCapa+POP,data=ESsTrads.STD)
#summary(model)
vif(model) 
mstep<-step(model)  #stepwise
summary(mstep)      

#SP	
model<-lm(SP~aPRCP2+TEM10+WIN5+farmlandLUi+GrassLUi+agriCapa,data=ESsTrads.STD)
#summary(model)
vif(model) 
mstep<-step(model)  #stepwise
summary(mstep)      

#WR	
model<-lm(WR~aPRCP2+TEM10+farmlandLUi+GrassLUi+agriCapa+POP,data=ESsTrads.STD)
#summary(model)
vif(model) 
mstep<-step(model)  #stepwise
summary(mstep)      

rm(ESsTrads.STD)
rm(model)
rm(mstep)
