# --Example script for running Dow-Eff functions on SCCS--- #--set working directory and load needed libraries-- setwd("e:/Dropbox/functions/") library(Hmisc) library(mice) library(foreign) library(stringr) library(AER) library(spdep) library(psych) library(geosphere) library(relaimpo) library(linprog) library(dismo) library(forward) library(pastecs) library(classInt) library(maps) library(dismo) library(plyr) library(aod) library(reshape) library(RColorBrewer) library(XML) library(tm) library(mlogit) library(mapproj) load(url("http://capone.mtsu.edu/eaeff/downloads/mycloud/DEf01f.Rdata")) setDS("SCCS") # create new variables dx$inhreal=(SCCS$v278>1)*1 addesc("inhreal","Dummy: real property is inherited") dx$inhmove=(SCCS$v279>1)*1 addesc("inhmove","Dummy: movable property is inherited") dx$marrgood=(SCCS$v208<4)*1 addesc("marrgood","Dummy: marriage includes transfer of goods") mkdummy("v245",2) # make imputed data sets evm<-c("v238","v921","v928","v1685","v232","v206","v245.d2", "v270","v272","v237","v155","v72","v1726","inhreal", "inhmove","marrgood","v63","v64","v1665","v1666", "v1667","v666","v767","v768","v770","v773","v891", "v1649","v1650") smi<-doMI(evm,nimp=5,maxit=7) dim(smi) # dimensions of new dataframe smi smi[1,] # first row of new dataframe smi # make scales # ==agricultural potential== agp<-c("v921","v928") fec<-mkscale(compvarbs="agp", udnavn="PCAP", impdata=smi, set.direction="v921", type="pc1", add.descrip="1st PC: Agricultural potential high") #--check reasonableness of scale-- fec$stats fec$corrs smi[,names(fec$scales)]<-fec$scales # ==commmunity size== csz<-c("v63","v237") fec<-mkscale(compvarbs="csz", udnavn="PCsize", impdata=smi, set.direction="v63", type="pc1", add.descrip="1st PC: Community size large") #--check reasonableness of scale-- fec$stats fec$corrs smi[,names(fec$scales)]<-fec$scales # ==violence== vio<-c("v1665","v1666","v1667") fec<-mkscale(compvarbs="vio", udnavn="PCviol", impdata=smi, set.direction="v1665", type="pc1", add.descrip="1st PC: High levels of violence") #--check reasonableness of scale-- fec$stats fec$corrs smi[,names(fec$scales)]<-fec$scales # --dependent variable-- dpV<-"v238" #--independent variables in UNrestricted model-- UiV<-c("PCAP","PCsize","PCsizeSq","PCviol", "v1685","v232","v206","v245.d2", "v270","v272","v155","v72","v1726","inhreal", "inhmove","marrgood","v64", "v666","v767","v768","v770","v773","v891", "v1649","v1650") #--independent variables in restricted model (all must be in UiV above)-- RiV<-c("PCAP","PCsize","PCsizeSq", "v1685","v206","v272","v1650") h<-doOLS(smi,depvar=dpV,indpv=UiV,rindpv=RiV,othexog=NULL, dw=TRUE,lw=TRUE,ew=FALSE,stepW=FALSE,boxcox=FALSE,getismat=FALSE, relimp=TRUE,slmtests=FALSE,haustest=NULL,mean.data=TRUE,doboot=300,full.set=FALSE) names(h) h$Rmodel h$Diagnostics h$OtherStats mkmappng(h$data,"v238","v238MoralGods",show="ydata",numnb.lg=3,numnb.lm=20,numch=5,pvlm=.05,dfbeta.show=TRUE) plotSq(h) CSVwrite(h,"olsresults",FALSE)