MiEff877.1

From InterSciWiki
Jump to: navigation, search
.Dow-Eff_Functions_-_DEf#SCCS_Dow_Eff_Functions
rm(list=ls(all=TRUE));gc();ls()
setwd("/home/yagmur/Dropbox/functions")
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)
load(url("http://dl.dropbox.com/u/9256203/DEf01c.Rdata"),.GlobalEnv)
ls() #-can see the objects contained in DEf01c.Rdata
# =========================SCCS=========================
setDS("SCCS")
dx$rectang<-(dx$v65>=8 & dx$v65<=9)*1
addesc("rectang","Dwelling is rectangular")
mkdummy("v279",1)
polyg<-fv4scale(lookword="polyg",doscale=FALSE,verbose=FALSE)
femecon<-fv4scale(lookword=c("market","exchange","wage","trade","subsistence","goods","product","labor"),
                 keepword=c("female","women","woman"),
                 coreword=c("subsistence"),nmin=60,chklevels=FALSE,verbose=FALSE)
path<-fv4scale(lookword=c("pathogen"),nmin=60,chklevels=FALSE,verbose=FALSE)
avoid<-c("v1196", "v1197", "v1198", "v1201", "v1202", "v1204", "v1205", "v1207",
        "v1208", "v1209", "v1210", "v1211", "v1212", "v1213", "v1214", "v1215",
        "v1217", "v1218", "v1219", "v1220", "v1223", "v1224")
#evm<-unique(c(polyg,"v279.d1","rectang",femecon,path,avoid))
evm<-unique(c(polyg,"v279.d1","bio.13","bio.16","bio.18","bio.2","v1256","v1259","v1708", "v79","v826","v860", "v861","v862","v872","v887","rectang",femecon,path,avoid))
smi<-doMI(evm,nimp=2,maxit=3)
dim(smi) # dimensions of new dataframe smi
smi[1,] # first row of new dataframe smi
jx<-"mean"
for (ii in c("path","femecon")){
 prp<-mkscale(compvarbs=ii,udnavn=paste(ii,jx,sep="."),impdata=smi,type=jx)
 print(head(prp$scales))
 print(prp$stats)
 print(prp$corrs)
 smi[,names(prp$scales)]<-prp$scales
}
quickdesc(polyg)
# --dependent variable--
dpV<-"v877" #Polygyny Guttman Scale I: Co-wife Autonomy Constructed from 854-852
#--independent variables in UNrestricted model--
UiV<-c("bio.13","bio.16","bio.18","bio.2","v1256","v1259","v1708", "v79","v826","v860", "v861","v862","v872","v887", "femecon.mean","path.mean","v1196", "v1197", "v1198", "v1201")
#--independent variables in restricted model (all must be in UiV above)--
RiV<-c("bio.13","bio.16","bio.18","bio.2","v1256","v1259","v1708", "v79","v826","v860", "v861","v862","v872","v887", "femecon.mean","path.mean","v1196", "v1197", "v1198")
#ToTry "bio.13","bio.16","bio.18","bio.2","rectang","v1256","v1259","v1708","v79","v826","v860","v861","v862", "v872","v887"
  1. Did Well bio.16 bio.18 v1198 v1256 v1708 v79 v826 v860 v862 v872 v887 v1259 v861
RiV<-c("bio.16","bio.18",          "v1256","v1708", "v79","v826","v860","v862","v872","v887","v1259","v861")  # femecon.mean","path.mean","v1196", "v1197", "v1198") #kept or didwell bio.18 v1708 v79 v860 v862 v872 v1259
RiV<-c("bio.18", "v1708", "v79","v860","v862","v872","v1259") #nonsignif "bio.18", "v1708", 
RiV<-c("v79","v860","v862","v872","v1259") #nonsig v1259
RiV<-c("v79","v860","v862","v872")
#Try "Careful" slimmed down stepW=FALSE, relimp=FALSE, doboot=0, 
h <- doOLS(smi, depvar = dpV, indpv = UiV, rindpv = RiV, othexog = NULL, dw = TRUE, lw = TRUE, ew = TRUE, stepW = FALSE, boxcox = FALSE, getismat = FALSE, relimp=FALSE, slmtests = FALSE, haustest = NULL, mean.data = TRUE, doboot = 0) #Works with DEf01c 

CSVwrite(h, "MiEff877new6.ew", FALSE) # DEf01b SCCS DEf01c SCCS ------------------------- ew = TRUE

#This is Eff's Oct 18 2013
h<-doOLS(smi,depvar=dpV,indpv=UiV,rindpv=RiV,othexog=NULL,
        dw=TRUE,lw=TRUE,ew=FALSE,stepW=FALSE,boxcox=FALSE,getismat=FALSE,
relimp=FALSE,slmtests=FALSE,haustest=NULL,mean.data=TRUE,doboot=0,full.set=TRUE)
#Careful: This has stepW=TRUE, relimp=TRUE and doboot=1000 Takes 5 minutes per loop
h <- doOLS(smi, depvar = dpV, indpv = UiV, rindpv = RiV, othexog = NULL, dw = TRUE, lw = TRUE, ew = TRUE, stepW = TRUE, boxcox = FALSE, getismat = FALSE, relimp = TRUE, slmtests = FALSE, haustest = NULL, mean.data = TRUE, doboot = 1000) #Works with DEf01c 

CSVwrite(h, "MiEff877new1.ew", FALSE) # DEf01b SCCS DEf01c SCCS ------------------------- ew = TRUE

h <- doOLS(smi, depvar = dpV, indpv = UiV, rindpv = RiV, othexog = NULL, dw = TRUE, lw = TRUE, ew = FALSE, stepW = TRUE, boxcox = FALSE, getismat = FALSE, relimp = TRUE, slmtests = FALSE, haustest = NULL, mean.data = TRUE, doboot = 1000) #Works with DEf01c 
CSVwrite(h, "MiEff877new1No.ew", FALSE) # DEf01b SCCS DEf01c SCCS ----------------------- ew = FALSE