User:Tara Chamberlain

From InterSciWiki
Jump to: navigation, search

CreateModelTLCv214.R

Contents

Dep_var

214. TRANSFER OF RESIDENCE AT MARRIAGE: FIRST YEARS (Atlas 10 combined)

     1     . = Missing Data
     3     1 = Wife to Husband's Group (7 in 213)
     1     2 = Couple to either Group or Neolocal (4 in 213)
    30     3 = Husband to Wife's Group (2 in 213)
     4     4 = No Common Residence (0 in 213)
   147     5 = Same as Prevalent Residence (#216)
           *   Note: get rid of this variable (redundant)
      THE CODE ABOVE WAS REVISED TO FORM A CONTINUUM FROM BILOCAL TO VIRILOCAL
      EXCLUDING 5
      THE FOLLOWING CODE IS OBSOLETE and the code above was substitute May 30, 2009
     1     . = Missing Data
   147    -1 = Same as Prevalent Residence (#216)
     3     1 = Wife to Husband's Group (7 above)
     1     2 = Couple to either Group or Neolocal (4 above)
    30     3 = Husband to Wife's Group (2 above)
     4     9 = No Common Residence (0 above)
           *   Note: get rid of this variable (redundant)
Mac: setwd
setwd("/Users/Tara/Desktop/drwhite5files/sccs") #tara
setwd("/Users/drwhite/Documents/sccs") #this would work for the mac ignoring the next setwd, for your subdirectory on your mac
1A and 1B prototypes UPDATED Doug 12:16, 4 October 2010 (PDT)

1B Output CreateModelDRWpolygyny.R

                coef   Fstat       ddf pvalue    VIF
(Intercept)   3.2928  6.2110  193.5827 0.0135     NA
language     -0.7168  2.2763 9414.7259 0.1314 2.3153
distance      0.6272 13.3216 2037.9760 0.0003 2.1638
fratgrpstr    0.2503 12.9665   71.0921 0.0006 1.2979
plow         -0.5205  4.3369  229.4862 0.0384 1.4585
fem_agri      0.0085  4.7692  359.4181 0.0296 1.3843
marrcaptives  0.3179  9.3854   61.0798 0.0033 1.4399
plunder      -0.4536  6.2962  681.4361 0.0123 1.2654
femproduceND -0.4837  4.8211  126.4589 0.0299 1.0647
ecorich       0.3259  7.6741 1460.9834 0.0057 1.1819
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.4637422       0.9964540       0.9979027 
>  ols_stats$restrict_diagnostics
               Fstat         df pvalue
RESET          0.111   3173.323  0.739
Wald.on.restrs 7.818      3.486  0.057
NCV            2.351   1926.180  0.125
SW.normal      0.119    871.410  0.730
lag..language  0.071 420589.855  0.790
lag..distance  0.080   2081.777  0.777


2A v214 Program CreateModelDRWpolygyny2.R Used half your variables to illustrate an UNRESTRICTED MODEL

setwd("C:/My Documents/sccs")
library(sccs)
data(sccs)                                 
depvar=sccs$v214
my_sccs<-data.frame(
dep_var=sccs$v214,
socname=sccs$socname,socID=sccs$"sccs#",
famsize=sccs$v68,    # similar to v80
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c(
"famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
restrict_vars=c(
"famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND")
library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

2B Used half your variables to illustrate an UNRESTRICTED MODEL

               coef  Fstat       ddf pvalue   VIF
(Intercept)  23.853 14.870    51.585  0.000    NA
language     -2.886  5.814   916.894  0.016 2.700 <--
distance     -1.625  3.451    40.675  0.070 2.712 <--
famsize      -0.001  0.001  1400.026  0.972 2.443
exogamy       0.118  3.333   357.893  0.069 1.575 <--
money        -0.071  1.184   628.195  0.277 2.511
popdens       0.200  6.610   793.519  0.010 3.974 <--
malesexag     0.033  0.417    27.156  0.524 1.723
ndrymonth    -0.015  0.278   132.586  0.599 2.566
gath         -0.041  0.240   139.938  0.625 3.719
hunt          0.071  0.740   999.022  0.390 5.519
fish          0.012  0.035   272.455  0.851 3.487
anim          0.003  0.002   256.473  0.965 6.589
brideprice    0.103  0.316  1491.873  0.574 2.202
nuclearfam   -0.198  0.820   112.305  0.367 2.593
ncmallow      0.007  0.046    60.537  0.830 1.488
cultints     -0.122  1.932   865.418  0.165 6.295
tree          0.795  2.462    84.364  0.120 4.057 <--
roots         0.791  4.071    84.185  0.047 6.080 <--
cereals       0.767  4.142    95.897  0.045 8.722 <--
settype      -0.025  0.202   172.610  0.653 4.457
localjh       0.088  0.354   187.988  0.553 2.022
superjh       0.025  0.091   193.864  0.764 2.823
moralgods    -0.006  0.007  1016.334  0.932 2.194
segadlboys    0.104  2.669    38.072  0.111 1.600 <--
plow         -0.163  0.311   248.149  0.578 3.284
pigs         -0.096  0.114   122.496  0.736 2.839
bovines      -0.017  0.004 21306.873  0.948 4.486
milk          0.043  0.022   180.869  0.883 4.658
agrlateboy    0.049  0.983    19.105  0.334 1.729
valchild     -0.010  0.436    16.390  0.518 1.369
fratgrpstr    0.050  0.257    26.268  0.616 3.661
Whyte577     -0.029  0.180   444.053  0.672 1.740
Whyte580     -0.011  0.014  3331.778  0.906 1.782
Whyte584      0.045  0.173    81.508  0.679 1.725
Whyte585     -0.036  0.026    25.850  0.872 1.667
Whyte595      0.130  1.592    32.490  0.216 1.736
Whyte602      0.081  0.159   165.438  0.691 1.831
Whyte615     -0.005  0.004    10.868  0.950 1.891
Whyte620     -0.134  1.115   127.384  0.293 2.198
Whyte626     -0.057  0.069    34.601  0.794 2.209
Whyte629      0.097  0.493    19.709  0.491 1.703
Whyte630     -0.075  0.377   253.550  0.540 1.935
Whyte631      0.089  1.008    57.363  0.320 1.591
Whyte632     -0.094  1.057    51.055  0.309 1.888
Whyte633     -0.139  1.392    52.645  0.243 2.016
Whyte635     -0.087  0.424    52.661  0.518 1.634
Paige657      0.086  0.176   173.115  0.676 1.849
femproduceND -0.007  0.001   135.738  0.973 1.573
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.4239015       0.9663717       0.9399904 
>  ols_stats$restrict_diagnostics
                Fstat        df pvalue
RESET          10.307    17.909  0.005
Wald.on.restrs  0.276    70.579  0.601
NCV            52.463   441.840  0.000
SW.normal      13.035    27.940  0.001
lag..language   0.742 26640.069  0.389
lag..distance   1.213 15510.941  0.271
>

3A Work on your indep_vars and restrict_vars Program CreateModelDRWpolygyny2.R Used half your variables to illustrate an UNRESTRICTED MODEL

setwd("C:/My Documents/sccs")
library(sccs)
data(sccs)                                 
depvar=sccs$v214
my_sccs<-data.frame(
dep_var=sccs$v214,
socname=sccs$socname,socID=sccs$"sccs#",
famsize=sccs$v68,    # similar to v80
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c(
"famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
restrict_vars=c(
"popdens","tree","roots","cereals","exogamy")
library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

3B

214. TRANSFER OF RESIDENCE AT MARRIAGE: FIRST YEARS (Atlas 10 combined)

    1     . = Missing Data
    3     1 = Wife to Husband's Group (7 in 213)
    1     2 = Couple to either Group or Neolocal (4 in 213)
   30     3 = Husband to Wife's Group (2 in 213)
    4     4 = No Common Residence (0 in 213)
  147     5 = Same as Prevalent Residence (#216)
               coef  Fstat         ddf pvalue   VIF
(Intercept) 17.129 18.255   10036.221  0.000    NA
language    -2.272  5.744    3744.224  0.017 1.525 <--
distance    -0.696  1.244   10782.712  0.265 1.562
popdens      0.112  4.333  460239.191  0.037 1.762 <--
tree         0.299  0.893 8806586.511  0.345 1.659
roots        0.374  2.727  241764.640  0.099 2.115 <--
cereals      0.261  1.650 1898942.080  0.199 2.619
exogamy      0.131  5.365 5220445.812  0.021 1.155 <--
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.1499681       0.9645702       0.9349839 
>  ols_stats$restrict_diagnostics
                Fstat         df pvalue
RESET           0.512  22306.348  0.474
Wald.on.restrs -0.076     11.554  1.000
NCV            15.724   7950.959  0.000
SW.normal      61.339 773939.289  0.000
lag..language   0.396 140260.665  0.529
lag..distance   0.705 330598.748  0.401

4A v216 Program CreateModelDRWpolygyny2.R Used half your variables to illustrate an UNRESTRICTED MODEL

setwd("C:/My Documents/sccs")
library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
famsize=sccs$v68,    # similar to v80
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c(
"famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
restrict_vars=c(
"famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND")
library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: After First Years"
alias<-"TLCtransferresidenceafterfirstyrs"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

4B v216 Principal residence

                coef  Fstat        ddf pvalue    VIF
(Intercept)   1.1637 0.5897    44.0932 0.4466     NA
language     -0.6158 0.8373    62.2182 0.3637 5.4444
distance      0.3385 0.5439   171.3157 0.4618 4.0201
famsize       0.0537 4.4441    57.4495 0.0394 2.5160 <--
exogamy      -0.0953 2.7102    77.1526 0.1038 1.5049 <--
money         0.0455 0.6503   223.5890 0.4209 2.3257
popdens       0.0339 0.2423   444.5447 0.6228 3.9257
malesexag     0.0186 0.1721    12.1679 0.6855 1.6528
ndrymonth    -0.0054 0.0473   131.5795 0.8282 2.4907
gath          0.0031 0.0018   142.9882 0.9663 3.8231
hunt         -0.0025 0.0011   287.6201 0.9738 5.6059
fish          0.0047 0.0075   377.3823 0.9310 3.3690
anim         -0.0766 1.2860   159.9977 0.2585 6.7861
brideprice   -0.1178 0.4450    47.4083 0.5079 2.2258
nuclearfam    0.0206 0.0118   173.5642 0.9136 2.5907
ncmallow     -0.0399 2.4031   592.6602 0.1216 1.5304 <--
cultints      0.0854 1.2168   591.3088 0.2704 6.1631
tree          0.3728 0.8903   803.2397 0.3457 3.5583
roots         0.1868 0.3563   231.2715 0.5512 5.3803
cereals       0.3030 0.8746   167.8089 0.3510 8.7043
settype      -0.1277 7.6511 21390.7298 0.0057 4.3939 <--
localjh      -0.0020 0.0003   527.8957 0.9870 1.9277
superjh       0.0065 0.0082  1176.6232 0.9277 2.8049
moralgods     0.0009 0.0002   795.3534 0.9889 1.9927
segadlboys    0.0596 1.5567  2134.3317 0.2123 1.5960
plow         -0.3492 1.5990    54.5284 0.2114 3.4274
pigs          0.0599 0.0504    32.9078 0.8238 2.8620
bovines       0.4150 2.9475   202.4836 0.0875 4.5476 <--
milk          0.0672 0.0669   415.7607 0.7960 4.9395
agrlateboy   -0.0117 0.0961    53.1848 0.7578 1.7351
valchild     -0.0120 1.1049   168.0110 0.2947 1.4363
fratgrpstr   -0.1910 5.2525    63.1268 0.0253 3.7837 <--
Whyte577      0.0553 0.5900    13.7994 0.4554 1.7766
Whyte580      0.0348 0.1048     7.4079 0.7551 1.6341
Whyte584      0.0399 0.1110    12.4791 0.7446 2.0106
Whyte585      0.0816 0.1639    11.2865 0.6931 1.6355
Whyte595      0.1047 1.2584    35.5462 0.2695 1.8121
Whyte602      0.0625 0.0696     8.0675 0.7986 1.7948
Whyte615     -0.0315 0.3543    35.0186 0.5555 1.7826
Whyte620      0.1057 0.8667   104.8110 0.3540 2.2588
Whyte626      0.1114 0.3580    48.1964 0.5524 2.2232
Whyte629     -0.0411 0.1010    12.4482 0.7559 1.7793
Whyte630      0.1230 1.3064   431.4241 0.2537 1.9433
Whyte631      0.1000 2.0276  1312.4623 0.1547 1.5954 <--
Whyte632      0.0128 0.0285   131.6790 0.8661 1.6696
Whyte633      0.0758 0.4683    16.2372 0.5034 1.9098
Whyte635     -0.0465 0.1042     8.9186 0.7542 1.6388
Paige657      0.0179 0.0103 15395.5205 0.9193 2.0123
femproduceND -0.1274 0.4567   420.8971 0.4995 1.7195
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.3817238       0.9944530       0.9870875 
>  ols_stats$restrict_diagnostics
                Fstat        df pvalue
RESET          13.666  1588.333  0.000
Wald.on.restrs  0.743    34.625  0.395
NCV            19.835    90.245  0.000
SW.normal       8.623   187.194  0.004
lag..language   0.517 12954.971  0.472
lag..distance   0.746  1452.677  0.388

5A Copied 4A into 5A and restricted to variables appearing significant in 4B

setwd("C:/My Documents/sccs")

library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
famsize=sccs$v68,    # similar to v80
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c(
"famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
restrict_vars=c(
"famsize","exogamy","ncmallow","settype","bovines","fratgrpstr",
"Whyte631")
library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

5B

               coef  Fstat       ddf pvalue   VIF
(Intercept)  1.598  4.417    88.875  0.038    NA
language    -0.073  0.024  3090.990  0.877 3.019
distance     0.262  0.548  8432.433  0.459 2.550
famsize      0.037  4.729   136.774  0.031 1.159 <--
exogamy     -0.087  3.497 48384.337  0.061 1.099 <--
ncmallow    -0.016  0.491   227.104  0.484 1.064
settype     -0.022  0.753   189.594  0.387 1.241
bovines      0.144  1.033   195.661  0.311 1.507
fratgrpstr  -0.190 12.227   125.077  0.001 1.739 <--
Whyte631     0.073  0.869    13.994  0.367 1.065
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.1970504       0.9944997       0.9876629 
>  ols_stats$restrict_diagnostics
                Fstat         df pvalue
RESET           7.032    553.858  0.008
Wald.on.restrs  0.876     31.653  0.356
NCV            15.189    302.944  0.000
SW.normal      29.088   7893.057  0.000
lag..language   0.314 577909.296  0.575
lag..distance   0.435 103022.623  0.509
>

6A Trying to raise R2 value (of variable 216) by restricting to bottom 1/3 independent variables

setwd("C:/My Documents/sccs")

library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
famsize=sccs$v68,    # similar to v80
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c(
"famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
restrict_vars=c("famsize","exogamy","fratgrpstr","Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)


library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

6B results of 6A

              coef Fstat      ddf pvalue   VIF
(Intercept)  2.308 3.010  222.314  0.084    NA
language     0.144 0.073 2800.867  0.788 4.140
distance    -0.132 0.097  628.855  0.755 3.715
famsize      0.018 1.086  185.339  0.299 1.297
exogamy     -0.094 3.256  183.872  0.073 1.311 <--
fratgrpstr  -0.183 6.444   19.527  0.020 2.472 <--
Rohner806    0.028 0.271   24.623  0.608 1.564
Rohner807   -0.040 0.083  540.619  0.774 1.589
Rohner808    0.057 0.161  151.694  0.689 1.602
Rohner809    0.204 0.783  279.726  0.377 1.723
Rohner810   -0.098 0.094  444.130  0.759 1.320
Rohner811    0.035 0.340   40.938  0.563 1.655
Rohner812    0.056 0.411   41.538  0.525 1.451
Rohner813   -0.082 0.927  150.362  0.337 1.540
foodtrade   -0.013 4.334  104.782  0.040 1.379 <--
fem_agri     0.002 0.462   39.606  0.501 1.942
dateobs      0.000 0.360   74.777  0.550 1.476
rain        -0.059 1.866  280.516  0.173 2.343
temp        -0.033 0.554  215.330  0.458 2.570
ecorich     -0.076 0.433  201.682  0.511 2.358
pctFemPolyg -0.004 1.576   22.285  0.222 1.569
femsubs     -0.015 0.106  713.760  0.745 1.860
intwar       0.030 0.088   35.291  0.769 1.379
extwar       0.024 0.074  589.315  0.785 1.640
himilexp    -0.015 0.015  499.677  0.903 1.376
AP1         -0.005 0.039  280.459  0.844 2.426
AP2         -0.050 1.108  847.328  0.293 2.173
pathstress   0.047 3.735  173.662  0.055 2.920 <--
war          0.014 0.622   36.417  0.435 4.458
intwarB     -0.038 5.780   33.009  0.022 2.879
extwarB      0.022 2.111   24.645  0.159 2.757
foodscarc    0.020 0.142   29.891  0.709 1.335
sexratio    -0.083 0.609   15.869  0.446 1.348
wagelabor    0.052 0.358   21.850  0.556 1.508
CVrain      -0.001 1.246  498.638  0.265 1.343
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.3531687       0.9945487       0.9876063 
>  ols_stats$restrict_diagnostics
                Fstat        df pvalue
RESET          13.540   509.675  0.000
Wald.on.restrs  0.327    95.383  0.569
NCV            15.051    54.296  0.000
SW.normal      12.686   306.913  0.000
lag..language   0.529 16146.686  0.467
lag..distance   0.780 39135.580  0.377
>

7A trying to increase R2 value (of v216)

setwd("C:/My Documents/sccs")

library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
famsize=sccs$v68,    # similar to v80
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c(
"famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
restrict_vars=c("exogamy","fratgrpstr","foodtrade","pathstress","Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805")


library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

7B results of 7A

               coef Fstat       ddf pvalue   VIF
(Intercept)   6.651 0.627    16.055  0.440    NA
language      0.298 0.206    30.494  0.653 4.541
distance     -0.229 0.273   110.262  0.603 3.597
exogamy      -0.070 1.265    23.137  0.272 1.384
fratgrpstr   -0.155 5.832    96.830  0.018 2.368 <--
foodtrade    -0.008 1.553   227.675  0.214 1.597
pathstress    0.021 1.012   271.759  0.315 2.139
Whyte630      0.067 0.321    19.628  0.577 1.556
Whyte631      0.116 2.465    31.571  0.126 1.367 <--
Whyte632     -0.062 0.843   355.781  0.359 1.506
Whyte633      0.147 1.756    25.199  0.197 1.958
Whyte635     -0.107 0.928    37.619  0.342 1.422
Paige657      0.135 0.621    62.966  0.434 1.606
femproduceND  0.015 0.004    43.806  0.952 2.432
Paige659     -0.148 0.536    19.950  0.473 2.129
Paige660     -0.050 0.041    10.645  0.843 2.361
Paige661      0.054 0.061    13.110  0.809 2.371
Paige662      0.032 0.026    21.151  0.873 1.947
fempower      0.004 0.005    45.147  0.945 3.139
interperviol -0.019 0.005    11.600  0.945 3.268
migr          0.022 0.021    31.023  0.886 1.618
Sanday664     0.075 0.082     8.478  0.781 1.752
Sanday665     0.057 0.059     9.464  0.813 1.576
Sanday666     0.201 0.604    13.635  0.450 3.229
Sanday667    -0.012 0.007   126.193  0.932 1.557
Sanday668    -0.165 0.698    12.694  0.419 1.752
Sanday669    -0.019 0.085    10.301  0.777 2.576
Whyte718      0.060 0.679    24.517  0.418 1.625
Whyte719      0.017 0.055   175.899  0.815 1.639
Whyte720      0.113 0.861    20.743  0.364 1.411
Whyte721     -0.127 1.778   131.532  0.185 2.039
Whyte722      0.046 0.062    12.846  0.807 2.444
Whyte723      0.036 0.022     6.185  0.887 2.624
Whyte724      0.002 0.000    17.748  0.992 1.564
Whyte725     -0.062 0.424    99.972  0.517 1.559
Rohner798     0.002 0.720    79.891  0.399 1.473
Rohner799     0.000 0.090 23513.177  0.764 1.516
Rohner800     0.001 0.196   547.317  0.658 2.778
Rohner801    -0.352 0.224   509.743  0.636 2.499
Rohner802    -0.005 1.347     7.767  0.280 1.489
Rohner803     0.003 1.203    31.626  0.281 1.511
Rohner804    -0.127 0.571   145.852  0.451 1.493
Rohner805     0.013 0.029    26.611  0.867 1.442
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.3743797       0.9957128       0.9902161 
>  ols_stats$restrict_diagnostics
                Fstat        df pvalue
RESET           7.412    52.137  0.009
Wald.on.restrs  3.914    12.934  0.070
NCV             8.447    13.813  0.012
SW.normal      11.430    25.768  0.002
lag..language   0.381 72940.731  0.537
lag..distance   0.569  4230.271  0.451
>

8A trying to increase R2 (v216) copied 7A into 8A

setwd("C:/My Documents/sccs")

library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
famsize=sccs$v68,    # similar to v80
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c(
"famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
restrict_vars=c("fratgrpstr","Whyte631","anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte629",
"Whyte630","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724")
library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

8B results of 8A

               coef Fstat     ddf pvalue   VIF
(Intercept)   0.337 0.052 240.656  0.820    NA
language      0.257 0.132 417.859  0.717 6.783
distance     -0.333 0.361  33.175  0.552 4.874
fratgrpstr   -0.135 2.684  91.063  0.105 4.215 <--
Whyte631      0.150 3.519 120.347  0.063 1.804 <--
anim         -0.085 2.495  49.813  0.121 3.903 <--
brideprice   -0.147 0.508  20.118  0.484 2.454
nuclearfam   -0.049 0.075  44.529  0.786 2.077
ncmallow     -0.031 1.178  69.115  0.282 1.630
cultints      0.054 0.488 182.929  0.486 5.997
tree          0.473 1.275  87.149  0.262 3.638
roots         0.159 0.249  78.419  0.619 5.177
cereals       0.314 1.036 247.974  0.310 8.133
settype      -0.092 3.630  28.327  0.067 3.566 <--
localjh       0.078 0.431 631.891  0.512 1.814
superjh      -0.004 0.002  40.512  0.963 3.326
moralgods     0.017 0.055 121.172  0.815 2.308
segadlboys    0.082 2.427 237.713  0.121 1.744 <--
plow         -0.243 0.625  28.284  0.436 3.698
pigs         -0.117 0.227 132.934  0.635 2.776
bovines       0.460 2.907  57.403  0.094 5.111 <--
milk         -0.097 0.135 994.834  0.714 5.323
agrlateboy   -0.010 0.051  13.172  0.824 1.756
valchild     -0.012 0.993  91.615  0.322 1.520
Whyte577      0.069 0.409   7.607  0.541 2.131
Whyte580      0.077 0.778 273.640  0.378 1.953
Whyte584      0.048 0.144  24.509  0.707 2.440
Whyte585      0.254 1.888  29.484  0.180 1.731
Whyte595      0.040 0.123  17.584  0.730 2.075
Whyte602      0.067 0.104  18.560  0.750 1.913
Whyte615      0.043 0.495  26.126  0.488 2.080
Whyte620      0.045 0.101  12.581  0.756 2.242
Whyte629      0.015 0.014  22.881  0.908 2.036
Whyte630      0.060 0.237  45.393  0.629 2.103
Whyte632      0.025 0.101 111.025  0.752 1.963
Whyte633      0.093 0.733 112.638  0.394 2.391
Whyte635     -0.118 1.028 184.777  0.312 1.727
Paige657     -0.012 0.004  80.497  0.949 2.084
femproduceND  0.130 0.251 128.125  0.617 3.060
Paige659     -0.207 0.948  21.649  0.341 2.376
Paige660     -0.039 0.038 179.498  0.845 2.768
Paige661      0.089 0.184  32.589  0.670 2.877
Paige662     -0.050 0.060  22.093  0.809 2.286
fempower      0.008 0.011  11.120  0.918 3.645
interperviol  0.109 0.155  16.388  0.699 3.990
migr          0.069 0.179  59.977  0.674 1.973
Sanday664    -0.080 0.147  32.370  0.704 2.034
Sanday665     0.040 0.022   8.518  0.885 1.871
Sanday666     0.001 0.000  18.230  0.996 3.980
Sanday667     0.083 0.205  18.089  0.656 1.955
Sanday668    -0.056 0.108  54.707  0.743 1.988
Sanday669    -0.041 0.323  13.109  0.579 3.474
Whyte718      0.030 0.143  18.977  0.709 1.810
Whyte719      0.073 0.764  39.979  0.387 1.931
Whyte720      0.045 0.113  31.821  0.738 1.827
Whyte721     -0.152 2.340 193.218  0.128 2.356 <--
Whyte722      0.080 0.189  11.763  0.672 2.281
Whyte723      0.042 0.070  21.261  0.794 2.704
Whyte724      0.026 0.024  15.617  0.879 1.826
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.4460656       0.9949848       0.9879116 
>  ols_stats$restrict_diagnostics
                Fstat       df pvalue
RESET          12.487   28.442  0.001
Wald.on.restrs  0.427    9.470  0.529
NCV            20.246 2292.542  0.000
SW.normal       6.844  269.462  0.009
lag..language   0.557 5640.756  0.456
lag..distance   0.884 8286.272  0.347
>

9A copied and pasted 8A into 9A and restricted to only the varibles that appeared significant in 8B

setwd("C:/My Documents/sccs")

library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
famsize=sccs$v68,    # similar to v80
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c(
"famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
restrict_vars=c("fratgrpstr","Whyte631","anim","settype","segadlboys","bovines","Whyte721")
library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

9B

              coef Fstat      ddf pvalue   VIF
(Intercept)  1.480 3.038   38.594  0.089    NA
language     0.333 0.511 1427.633  0.475 2.927
distance    -0.122 0.119 1325.601  0.730 2.487
fratgrpstr  -0.163 8.234  148.010  0.005 1.882
Whyte631     0.086 1.347   14.515  0.265 1.087 <--
anim        -0.087 5.578  197.994  0.019 1.965 
settype     -0.038 1.830  422.384  0.177 1.519
segadlboys   0.051 1.540 1585.167  0.215 1.104 <--
bovines      0.344 4.987  560.295  0.026 1.877
Whyte721    -0.048 0.291   28.917  0.594 1.471 <--
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.1994758       0.9944934       0.9875274 
>  ols_stats$restrict_diagnostics
                Fstat        df pvalue
RESET           3.663    11.591  0.081
Wald.on.restrs  0.618     8.321  0.454
NCV            17.867  1880.655  0.000
SW.normal      31.485 29555.157  0.000
lag..language   0.353  5125.497  0.552
lag..distance   0.442 11482.680  0.506
>

10A running program with ALL significant values from different runs together as restricted variables

setwd("C:/My Documents/sccs")

library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
famsize=sccs$v68,    # similar to v80
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c(
"famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
restrict_vars=c("fratgrpstr","Whyte631","anim","settype","segadlboys","bovines","Whyte721","famsize","exogamy","ncmallow","foodtrade","pathstress")
library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

10B

              coef Fstat       ddf pvalue   VIF
(Intercept)  2.296 7.743   215.887  0.006    NA
language    -0.129 0.071  1186.586  0.791 3.365
distance    -0.001 0.000  2351.823  0.999 2.729
fratgrpstr  -0.175 9.372   196.831  0.003 2.149
Whyte631     0.068 0.679    10.600  0.428 1.148 <--out
anim        -0.074 3.799   141.834  0.053 2.163
settype     -0.065 5.252   643.075  0.022 1.674
segadlboys   0.061 1.571    45.189  0.217 1.287 <--out
bovines      0.326 4.769  6939.215  0.029 1.959
Whyte721    -0.126 2.312    64.237  0.133 1.542
famsize      0.031 3.990 17675.181  0.046 1.183 
exogamy     -0.095 4.183  2710.078  0.041 1.136 
ncmallow    -0.028 1.556   168.898  0.214 1.130 <--out
foodtrade   -0.008 2.039   672.286  0.154 1.170 
pathstress   0.029 3.028 12232.893  0.082 1.500 
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.2707276       0.9952433       0.9878371 
>  ols_stats$restrict_diagnostics
                Fstat          df pvalue
RESET          11.801      86.285  0.001
Wald.on.restrs  1.255      30.795  0.271
NCV             9.450     178.616  0.002
SW.normal      25.551     681.220  0.000
lag..language   0.277 1329100.775  0.599
lag..distance   0.529   12696.008  0.467
>

11A adding a new variable?

setwd("C:/My Documents/sccs")

library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
famsize=sccs$v68,    # similar to v80
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
newvar=sccs$v111,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c(
"famsize","exogamy",  "newvar",  "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
restrict_vars=c("fratgrpstr","Whyte631","anim","newvar","settype","segadlboys","bovines","Whyte721","famsize","exogamy","ncmallow","foodtrade","pathstress")
library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

12A results from 10A restricted to only the variables that are significant in 10B (FINAL MODEL**)

#12B: you didn’t the right list
setwd("C:/My Documents/sccs")
library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
famsize=sccs$v68,    # similar to v80
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c(
"famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
#restrict_vars=c("Whyte631","segadlboys","famsize","exogamy","ncmallow","foodtrade","pathstress")
#12B: that wasn’t the right list
restrict_vars=c("fratgrpstr","anim","settype","bovines","famsize","exogamy","foodtrade","pathstress")


library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: After First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
 ztxt<-gsub("NaN",".",ztxt)
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

12B (keep variables that worked in 10B)

DRW: THESE SHOULD HAVE BEEN THE RESULTS
              coef Fstat       ddf pvalue   VIF
(Intercept)  2.039 7.422    72.992  0.008    NA
language    -0.069 0.022  3704.880  0.882 3.051
distance     0.053 0.020   123.969  0.888 2.656
fratgrpstr  -0.164 4.581    10.669  0.056 1.972 <--
anim        -0.068 3.682   692.243  0.055 1.972 <--
settype     -0.051 3.571  2862.366  0.059 1.511 <--
bovines      0.225 2.384  6429.491  0.123 1.794 <--
famsize      0.032 4.008  1835.967  0.045 1.160 <--
exogamy     -0.106 5.363 10129.656  0.021 1.085 <--
foodtrade   -0.008 2.040  1129.482  0.153 1.126 <--
pathstress   0.028 2.902   453.593  0.089 1.318 <--
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.2265011       0.9951105       0.9872714 
>  ols_stats$restrict_diagnostics
                Fstat        df pvalue
RESET          13.282    88.479  0.000
Wald.on.restrs  0.245     8.364  0.634
NCV            11.393  5213.017  0.001
SW.normal      28.764   553.662  0.000
lag..language   0.257 11161.428  0.612
lag..distance   0.431 13923.423  0.512
216.  TRANSFER OF RESIDENCE AT MARRIAGE: AFTER FIRST YEARS
     1    . = Missing Data
   121126 1 = Wife to Husband's Group 
    33 28 2 = Couple to either Group or Neolocal 
    30    3 = Husband to Wife's Group 
     1    4 = No Common Residence
    30    3 = Husband to Wife's Group (1, 2)
NOT THE RIGHT CHOICE
              coef Fstat       ddf pvalue   VIF
  (Intercept)  0.216 0.105  1460.889  0.746    NA
  language     0.450 0.909 15026.049  0.340 2.829
  distance     0.358 0.972 22439.425  0.324 2.491
  Whyte631     0.064 0.882    31.494  0.355 1.067
  segadlboys   0.046 1.020   262.194  0.314 1.158
  famsize      0.027 2.635 34403.986  0.105 1.115
  exogamy     -0.102 4.375 39850.094  0.036 1.116
  ncmallow    -0.021 0.757   149.700  0.386 1.095
  foodtrade   -0.010 3.342  9292.708  0.068 1.129
  pathstress   0.008 0.215 25391.066  0.643 1.243
  >  ols_stats$r2
   R2:final model R2:IV_ language R2:IV_ distance 
        0.1290323       0.9943425       0.9870204 
  >  ols_stats$restrict_diagnostics
                  Fstat         df pvalue
  RESET           6.473    179.392  0.012
  Wald.on.restrs  0.566      9.925  0.469
  NCV             6.454    292.604  0.012
  SW.normal      38.063   3426.667  0.000
  lag..language   0.319 152494.156  0.572
  lag..distance   0.467 343060.345  0.494
 >

13A added variable v73(communityintegration)to 12A model

setwd("C:/My Documents/sccs")

library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
famsize=sccs$v68,    # similar to v80
communityintegration=sccs$v73,
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c(
"communityintegration","famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
restrict_vars=c("communityintegration","Whyte631","segadlboys","famsize","exogamy","ncmallow","foodtrade","pathstress")
library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

13B

                       coef Fstat        ddf pvalue   VIF
(Intercept)           0.169 0.065   6232.297  0.800    NA
language              0.401 0.721  11797.059  0.396 2.854
distance              0.369 1.002   5969.404  0.317 2.567
communityintegration -0.014 0.178   8311.528  0.673 1.093
Whyte631              0.111 2.664     39.544  0.111 1.064
segadlboys            0.040 0.794    716.030  0.373 1.169
famsize               0.029 3.222 176343.315  0.073 1.113
exogamy              -0.105 4.729 104281.096  0.030 1.101
ncmallow             -0.019 0.669   2251.765  0.414 1.099
foodtrade            -0.011 3.955   7035.698  0.047 1.138
pathstress            0.008 0.245  12583.000  0.620 1.273
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.1430550       0.9953725       0.9882966 
>  ols_stats$restrict_diagnostics
                Fstat          df pvalue
RESET           4.960      71.245  0.029
Wald.on.restrs  1.744      11.751  0.212
NCV             6.670     296.649  0.010
SW.normal      38.201  121831.595  0.000
lag..language   0.203   21882.262  0.653
lag..distance   0.368 2179585.783  0.544
>

14A added variable v22(food supply) to model 13A

setwd("C:/My Documents/sccs")

library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
famsize=sccs$v68,    # similar to v80
foodsupply=sccs$v22,
communityintegration=sccs$v73,
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c(
"foodsupply","communityintegration","famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
restrict_vars=c("foodsupply","communityintegration","Whyte631","segadlboys","famsize","exogamy","ncmallow","foodtrade","pathstress")
library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

14B results show foodsupply is not a significant variable

                       coef Fstat        ddf pvalue   VIF
(Intercept)           0.143 0.036    111.146  0.849    NA
language              0.377 0.607   1207.105  0.436 2.885
distance              0.391 1.047    938.223  0.306 2.646
foodsupply            0.008 0.023   2055.300  0.878 1.166
communityintegration -0.014 0.176 211357.059  0.675 1.120
Whyte631              0.099 1.214     10.308  0.296 1.087
segadlboys            0.041 0.738    169.733  0.392 1.194
famsize               0.029 3.082  29137.665  0.079 1.128 <--
exogamy              -0.100 3.938    981.871  0.047 1.132 <--
ncmallow             -0.015 0.412   1889.285  0.521 1.093
foodtrade            -0.011 3.323  12153.790  0.068 1.154 <--
pathstress            0.009 0.299  38678.504  0.584 1.279
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.1372515       0.9949529       0.9883697 
>  ols_stats$restrict_diagnostics
                Fstat        df pvalue
RESET           5.778    80.941  0.019
Wald.on.restrs  2.465    72.686  0.121
NCV             7.196   530.013  0.008
SW.normal      36.222  1185.133  0.000
lag..language   0.222 32421.096  0.638
lag..distance   0.428 41952.367  0.513
>

15A taking 10A and adding v5(animal husbandry)

setwd("C:/My Documents/sccs")

library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
famsize=sccs$v68,    # similar to v80
animalhusbandry=sccs$v5,
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c(
"animalhusbandry","famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
restrict_vars=c("animalhusbandry","fratgrpstr","Whyte631","anim","settype","segadlboys","bovines","Whyte721","famsize","exogamy","ncmallow","foodtrade","pathstress")
library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

15B results show animal husbandry is not a significant variable

                  coef Fstat       ddf pvalue   VIF
(Intercept)      1.696 4.017   138.782  0.047    NA
language        -0.040 0.006    68.881  0.939 3.369
distance         0.016 0.002   209.072  0.965 2.734
animalhusbandry  0.071 1.047  5841.965  0.306 4.065
fratgrpstr      -0.160 6.806    47.792  0.012 2.140 <--
Whyte631         0.149 5.480    45.849  0.024 1.120 <--
anim            -0.121 5.225  5368.170  0.022 4.787 <--
settype         -0.069 6.126 12050.982  0.013 1.697 <--
segadlboys       0.062 2.134   606.546  0.145 1.226 <--
bovines          0.331 4.836   523.782  0.028 1.929 <--
Whyte721        -0.097 1.223    39.780  0.275 1.558
famsize          0.032 4.120  3580.055  0.042 1.176 <--
exogamy         -0.095 4.244  1615.312  0.040 1.141 <--
ncmallow        -0.032 2.296  1037.236  0.130 1.114 <--
foodtrade       -0.009 2.838 75553.079  0.092 1.176 <--
pathstress       0.024 1.982   225.051  0.161 1.509
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.2856689       0.9953951       0.9877727 
>  ols_stats$restrict_diagnostics
                Fstat        df pvalue
RESET           9.249    26.047  0.005
Wald.on.restrs -0.165     8.312  1.000
NCV             8.874    58.165  0.004
SW.normal      21.473   201.298  0.000
lag..language   0.280 18382.936  0.597
lag..distance   0.635 47178.418  0.425
>

16A copied 10A into 16A and added variable v17(money)

setwd("C:/My Documents/sccs")

library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
money=sccs$v17,
famsize=sccs$v68,    # similar to v80
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c(
"money","famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
restrict_vars=c("money","fratgrpstr","Whyte631","anim","settype","segadlboys","bovines","Whyte721","famsize","exogamy","ncmallow","foodtrade","pathstress")
library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

16B results show money is not a significant variable

              coef Fstat       ddf pvalue   VIF
(Intercept)  1.632 4.147  5604.352  0.042    NA
language     0.084 0.030  2596.585  0.861 3.321
distance    -0.007 0.000  1492.435  0.984 2.666
money        0.036 0.693   944.889  0.405 1.595
fratgrpstr  -0.158 8.001   180.599  0.005 1.984
Whyte631     0.115 3.316    69.064  0.073 1.144
anim        -0.081 5.361 18254.688  0.021 2.082
settype     -0.072 5.984   479.216  0.015 1.750
segadlboys   0.054 1.570   181.933  0.212 1.235
bovines      0.269 3.161 10726.097  0.075 1.987
Whyte721    -0.039 0.212   176.982  0.646 1.670
famsize      0.031 3.783  1088.687  0.052 1.180
exogamy     -0.084 3.225  3016.324  0.073 1.157
ncmallow    -0.031 2.122  7230.137  0.145 1.115
foodtrade   -0.010 3.104  2057.675  0.078 1.249
pathstress   0.025 2.228  1889.058  0.136 1.514
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.2654957       0.9953510       0.9880645 
>  ols_stats$restrict_diagnostics
                Fstat        df pvalue
RESET           9.710    31.263  0.004
Wald.on.restrs  0.550    12.597  0.472
NCV             8.064    70.127  0.006
SW.normal      26.406   777.041  0.000
lag..language   0.276 15359.468  0.600
lag..distance   0.469 19702.340  0.493
>

17A copy 10A into 17A and added v67(householdform)

setwd("C:/My Documents/sccs")

library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
householdform=sccs$v67,
famsize=sccs$v68,    # similar to v80
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c(
"householdform","famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
restrict_vars=c("householdform","fratgrpstr","Whyte631","anim","settype","segadlboys","bovines","Whyte721","famsize","exogamy","ncmallow","foodtrade","pathstress")
library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

17B results show household form is not a significant variable

                coef Fstat      ddf pvalue   VIF
(Intercept)    2.350 8.452  492.749  0.004    NA
language      -0.152 0.086   85.762  0.771 3.361
distance       0.005 0.000  159.261  0.989 2.750
householdform -0.002 0.003 2788.653  0.960 1.685
fratgrpstr    -0.178 9.502   85.438  0.003 2.135
Whyte631       0.061 1.023  284.524  0.313 1.141
anim          -0.072 4.091 1272.286  0.043 2.106
settype       -0.068 5.701 1303.682  0.017 1.690
segadlboys     0.053 1.466  491.203  0.227 1.276
bovines        0.332 4.791 1607.587  0.029 1.969
Whyte721      -0.117 2.214  291.868  0.138 1.578
famsize        0.032 3.554  305.361  0.060 1.267
exogamy       -0.091 3.826 6158.448  0.051 1.142
ncmallow      -0.027 1.543 5411.505  0.214 1.180
foodtrade     -0.008 2.231  448.495  0.136 1.185
pathstress     0.029 2.656  844.731  0.104 1.689
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.2710464       0.9950399       0.9887081 
>  ols_stats$restrict_diagnostics
                Fstat          df pvalue
RESET          15.409     662.663  0.000
Wald.on.restrs  1.109      27.809  0.301
NCV            10.150    2165.237  0.001
SW.normal      25.515     468.381  0.000
lag..language   0.317   20547.308  0.574
lag..distance   0.568 2326193.204  0.451
>

18A copy 10A into 18A and added variable v76

setwd("C:/My Documents/sccs")

library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
communityleadership=sccs$v76,
famsize=sccs$v68,    # similar to v80
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c(
"communityleadership","famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
restrict_vars=c("communityleadership","fratgrpstr","Whyte631","anim","settype","segadlboys","bovines","Whyte721","famsize","exogamy","ncmallow","foodtrade","pathstress")
library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

18B v76 not significant

                      coef Fstat      ddf pvalue   VIF
(Intercept)          1.735 4.477  269.305  0.035    NA
language             0.048 0.010 2062.873  0.920 3.264
distance            -0.020 0.003  159.168  0.958 2.702
communityleadership  0.021 0.318  148.333  0.574 1.324
fratgrpstr          -0.150 3.965   13.523  0.067 2.195
Whyte631             0.106 2.122   18.136  0.162 1.142
anim                -0.081 4.638  151.708  0.033 2.128
settype             -0.071 5.820 1628.210  0.016 1.772
segadlboys           0.048 1.201  291.048  0.274 1.252
bovines              0.304 3.872  478.697  0.050 1.944
Whyte721            -0.057 0.313   15.911  0.584 1.567
famsize              0.032 4.061 9288.743  0.044 1.187
exogamy             -0.087 3.001  161.638  0.085 1.207
ncmallow            -0.026 1.409  349.484  0.236 1.136
foodtrade           -0.009 2.517 1653.152  0.113 1.169
pathstress           0.024 1.797  168.271  0.182 1.516
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.2562106       0.9951004       0.9890701 
>  ols_stats$restrict_diagnostics
                Fstat        df pvalue
RESET          13.622    53.969  0.001
Wald.on.restrs  1.571    27.510  0.221
NCV             8.727  1082.891  0.003
SW.normal      28.407  1498.163  0.000
lag..language   0.345 33368.832  0.557
lag..distance   0.416 71073.506  0.519
>

19A copied 10A into 19A and added v85(executive)

setwd("C:/My Documents/sccs")

library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
executive=sccs$v85,
famsize=sccs$v68,    # similar to v80
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c(
"executive","famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
restrict_vars=c("executive","fratgrpstr","Whyte631","anim","settype","segadlboys","bovines","Whyte721","famsize","exogamy","ncmallow","foodtrade","pathstress")
library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

19B results show v85 is not significant

              coef Fstat      ddf pvalue   VIF
(Intercept)  2.066 6.469 1724.712  0.011    NA
language    -0.126 0.062  167.404  0.804 3.342
distance     0.033 0.008  234.473  0.929 2.696
executive   -0.002 0.003  574.183  0.955 1.392
fratgrpstr  -0.166 8.438  116.632  0.004 2.062
Whyte631     0.079 1.503   79.772  0.224 1.144
anim        -0.079 4.793  582.891  0.029 2.068
settype     -0.065 4.865  429.318  0.028 1.763
segadlboys   0.052 1.387  515.342  0.239 1.284
bovines      0.288 3.631 1599.320  0.057 1.937
Whyte721    -0.078 0.856   67.707  0.358 1.583
famsize      0.033 4.203  705.745  0.041 1.190
exogamy     -0.081 2.746  218.210  0.099 1.152
ncmallow    -0.025 1.322  396.736  0.251 1.114
foodtrade   -0.009 2.470  736.992  0.116 1.169
pathstress   0.028 2.510  429.473  0.114 1.529
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.2618882       0.9946827       0.9870071 
>  ols_stats$restrict_diagnostics
                Fstat         df pvalue
RESET          12.116    198.846  0.001
Wald.on.restrs  0.139    298.638  0.710
NCV             9.602    103.394  0.003
SW.normal      26.371   1458.241  0.000
lag..language   0.356  93580.878  0.551
lag..distance   0.577 124442.097  0.448
>

20A copied 10A into 20A and added v212(marital composition within extended families)

setwd("C:/My Documents/sccs")

library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
famsize=sccs$v68,    # similar to v80
maritalcompositionwithinextendedfamilies=sccs$v212,
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c(
"maritalcompositionwithinextendedfamilies","famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
restrict_vars=c("maritalcompositionwithinextendedfamilies","fratgrpstr","Whyte631","anim","settype","segadlboys","bovines","Whyte721","famsize","exogamy","ncmallow","foodtrade","pathstress")
library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

20B GOOD RESULTS! v212 proves to be significant and R2 increased to 0.29 :)

                                           coef Fstat         ddf pvalue   VIF
(Intercept)                               2.372 7.987     194.416  0.005    NA
language                                  0.046 0.010    3500.428  0.922 3.285
distance                                 -0.148 0.173    2505.791  0.678 2.780
maritalcompositionwithinextendedfamilies -0.051 2.938 1419619.088  0.087 2.025 v212 not a good indep_var because of category 7
fratgrpstr                               -0.144 5.209      32.288  0.029 2.145 <--
Whyte631                                  0.099 2.620      64.044  0.110 1.171 <--
anim                                     -0.077 4.562     252.454  0.034 2.104 <--
settype                                  -0.065 5.453    1013.169  0.020 1.653 <--
segadlboys                                0.051 1.075      26.605  0.309 1.231
bovines                                   0.212 1.873     705.867  0.172 2.070
Whyte721                                 -0.090 1.126      49.730  0.294 1.596
famsize                                   0.009 0.171    2423.591  0.680 2.064
exogamy                                  -0.085 3.355    1309.021  0.067 1.158 <--
ncmallow                                 -0.033 2.285     155.448  0.133 1.135 <--
foodtrade                                -0.010 3.161    2001.278  0.076 1.172 <--
pathstress                                0.035 4.024     387.942  0.046 1.561 <--
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.2906125       0.9952112       0.9882697 
>  ols_stats$restrict_diagnostics
                Fstat         df pvalue
RESET          11.459     62.430  0.001
Wald.on.restrs  0.091     17.921  0.766
NCV             9.696     62.701  0.003
SW.normal      19.406    158.259  0.000
lag..language   0.293 121022.711  0.589
lag..distance   0.593  23050.802  0.441
>

21A...copied 20A into 21A and made restricted variables the significant variables in 20B

setwd("C:/My Documents/sccs")

library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
famsize=sccs$v68,    # similar to v80
maritalcompositionwithinextendedfamilies=sccs$v212,
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c(
"maritalcompositionwithinextendedfamilies","famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
restrict_vars=c("maritalcompositionwithinextendedfamilies","fratgrpstr","Whyte631","anim","settype","exogamy","ncmallow","foodtrade","pathstress")
library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

21B GOOD results!

                                           coef Fstat      ddf pvalue   VIF
(Intercept)                               2.156 9.024  714.404  0.003    NA
language                                  0.104 0.058 2477.171  0.809 2.726
distance                                 -0.116 0.113  747.699  0.737 2.542
maritalcompositionwithinextendedfamilies -0.067 9.120 1163.531  0.003 1.084 v212 not a good indep_var because of category 7
fratgrpstr                               -0.149 7.775  359.657  0.006 1.947
Whyte631                                  0.091 2.143   42.520  0.151 1.103 v631 value of women's labor (GOOD!)
anim                                     -0.056 3.034  339.306  0.082 1.665
settype                                  -0.044 3.317 7543.936  0.069 1.302
exogamy                                  -0.091 3.815  492.941  0.051 1.117
ncmallow                                 -0.026 1.408  277.814  0.236 1.091
foodtrade                                -0.010 3.683 6590.259  0.055 1.138
pathstress                                0.041 6.357  302.833  0.012 1.363
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.2694309       0.9953879       0.9889340 
>  ols_stats$restrict_diagnostics
                Fstat        df pvalue
RESET           7.627    68.943  0.007
Wald.on.restrs  0.380    26.119  0.543
NCV            11.732   132.640  0.001
SW.normal      24.607  5105.104  0.000
lag..language   0.308 24180.311  0.579
lag..distance   0.463 21222.042  0.496
>

22A copied 21A into 22A and removed ncmallow restricted variable

setwd("C:/My Documents/sccs")

library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
famsize=sccs$v68,    # similar to v80
maritalcompositionwithinextendedfamilies=sccs$v212,
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c(
"maritalcompositionwithinextendedfamilies","famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
restrict_vars=c("maritalcompositionwithinextendedfamilies","fratgrpstr","Whyte631","anim","settype","exogamy","foodtrade","pathstress")
library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

22B

                                           coef Fstat       ddf pvalue   VIF
(Intercept)                               2.109 8.043   318.067  0.005    NA
language                                  0.000 0.000   321.508  0.999 2.824
distance                                 -0.010 0.001  3704.246  0.977 2.491
maritalcompositionwithinextendedfamilies -0.065 8.272  1169.290  0.004 1.099
fratgrpstr                               -0.164 8.451   358.191  0.004 2.088
Whyte631                                  0.064 1.077    84.991  0.302 1.104 <--
anim                                     -0.041 1.699  1993.452  0.193 1.697 <--
settype                                  -0.034 1.852  2241.481  0.174 1.304 <--
exogamy                                  -0.101 5.018 17327.357  0.025 1.097
foodtrade                                -0.008 2.524  2635.153  0.112 1.129
pathstress                                0.041 6.696  2325.173  0.010 1.344
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.2554551       0.9953187       0.9881482 
>  ols_stats$restrict_diagnostics
                Fstat         df pvalue
RESET           9.613    199.625  0.002
Wald.on.restrs  0.453    186.231  0.502
NCV            12.891   2088.483  0.000
SW.normal      25.351   7371.979  0.000
lag..language   0.297 123448.356  0.586
lag..distance   0.527  41269.575  0.468
>

23A copied 22A into 23A and removed insignificant variables in 22B from restricted variables

setwd("C:/My Documents/sccs")
library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
famsize=sccs$v68,    # similar to v80
maritalcompositionwithinextendedfamilies=sccs$v212,
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c(
"maritalcompositionwithinextendedfamilies","famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
restrict_vars=c("maritalcompositionwithinextendedfamilies","fratgrpstr","exogamy","foodtrade","pathstress")
library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

23B v216 NEW MOST FINISHED MODEL

v212 not a good indep_var because of category 7.
                                           coef  Fstat      ddf pvalue   VIF
(Intercept)                               2.055  9.471  296.341  0.002    NA
language                                  0.114  0.067  295.291  0.796 2.630
distance                                 -0.032  0.009  649.916  0.926 2.438
maritalcompositionwithinextendedfamilies -0.058  6.826 1240.874  0.009 1.069 v212 not a good indep_var because of category 7
fratgrpstr                               -0.200 13.683   36.894  0.001 1.615 
exogamy                                  -0.101  4.970  991.763  0.026 1.069
foodtrade                                -0.009  3.140 1406.184  0.077 1.084
pathstress                                0.038  5.838  503.912  0.016 1.254
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.2356914       0.9958482       0.9895318 
>  ols_stats$restrict_diagnostics
                Fstat        df pvalue
RESET           8.442   664.615  0.004
Wald.on.restrs  2.771    46.855  0.103
NCV            15.215   673.051  0.000
SW.normal      22.467   202.457  0.000
lag..language   0.155 74319.201  0.694
lag..distance   0.354 48807.633  0.552

20A copied 10A into 20A and added v212(marital composition within extended families)

setwd("C:/My Documents/sccs")
library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
famsize=sccs$v68,    # similar to v80
maritalcompositionwithinextendedfamilies=sccs$v212,
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c(
"maritalcompositionwithinextendedfamilies","famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"


restrict_vars=c(    #"maritalcompositionwithinextendedfamilies",
"Whyte631","anim","settype","segadlboys",  #"fratgrpstr",
"bovines","famsize","exogamy","foodtrade",  #"Whyte721","pathstress",
"ncmallow")   #


library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

20BB results - no v212, fratgrpstr, pathstress pathstress 721Nationality of authorities

Tara - I took out v212 and fratgrpstr (includes patrilocal), then pathstress (shouldnt have an effect), Whyte721 (Nationality of authorities))
not mcmallow
You might take out bovines and compare with taking out anim since they have the highest VIF
THERE SHOULD BE EITHER anim or bovines with a positive coefficient, not negative (anim is strange in this case)
216.  TRANSFER OF RESIDENCE AT MARRIAGE: AFTER FIRST YEARS
     1    . = Missing Data
   121126 1 = Wife to Husband's Group 
    33 28 2 = Couple to either Group or Neolocal 
    30    3 = Husband to Wife's Group 
     1    4 = No Common Residence
              coef  Fstat       ddf pvalue   VIF
(Intercept)  1.108  2.655  1093.621  0.104    NA
language     0.250  0.289  5618.673  0.591 2.974
distance     0.113  0.098   762.587  0.754 2.592
Whyte631     0.133  2.113    10.683  0.175 1.087 Value of Labor (female)
anim        -0.118 11.777   898.183  0.001 1.839
settype     -0.066  6.150 32024.511  0.013 1.458
segadlboys   0.064  2.057    88.170  0.155 1.130
bovines      0.280  3.585 15215.592  0.058 1.822
famsize      0.033  4.208 92665.957  0.040 1.155
exogamy     -0.099  4.449  4716.123  0.035 1.113
foodtrade   -0.009  2.368  1173.375  0.124 1.165
ncmallow    -0.030  1.846  4669.203  0.174 1.099
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.2114603       0.9948187       0.9894428 
>  ols_stats$restrict_diagnostics
                Fstat       df pvalue
RESET           8.874  612.743  0.003
Wald.on.restrs  1.011   10.052  0.338
NCV            11.603  655.713  0.001
SW.normal      27.211  413.554  0.000
lag..language   0.303 5474.348  0.582
lag..distance   0.330 5536.903  0.566
with ncmallow 
              coef Fstat       ddf pvalue   VIF
(Intercept)  1.729 4.612   960.494  0.032    NA
language    -0.067 0.019  1032.022  0.891 3.301
distance     0.069 0.038 43879.953  0.845 2.679
fratgrpstr  -0.154 6.975    78.496  0.010 1.956
Whyte631     0.099 1.883    89.252  0.173 1.139
anim        -0.074 4.054   536.784  0.045 2.121
settype     -0.063 5.102  1356.141  0.024 1.604
segadlboys   0.037 0.723   350.659  0.396 1.213
bovines      0.287 3.549   961.755  0.060 1.926
Whyte721    -0.080 0.990   149.864  0.321 1.468
famsize      0.033 4.438  3640.042  0.035 1.164
exogamy     -0.089 3.712  8227.705  0.054 1.129
foodtrade   -0.007 1.879  4111.254  0.171 1.155
pathstress   0.027 2.414   377.578  0.121 1.491
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.2467969       0.9951100       0.9877718 
>  ols_stats$restrict_diagnostics
                Fstat        df pvalue
RESET          13.773   270.345  0.000
Wald.on.restrs  1.042    22.057  0.319
NCV            11.253 17113.381  0.001
SW.normal      28.570 11878.347  0.000
lag..language   0.261 46826.838  0.609
lag..distance   0.567 17740.260  0.452

25 FINAL MODEL (I am going with 12A as my final model...I didn't realize the results for 12A are actually pretty good)

setwd("C:/My Documents/sccs")

library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
famsize=sccs$v68,    # similar to v80
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c(
"famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
#restrict_vars=c("Whyte631","segadlboys","famsize","exogamy","ncmallow","foodtrade","pathstress")
#12B: that wasn’t the right list
restrict_vars=c("fratgrpstr","anim","settype","bovines","famsize","exogamy","foodtrade","pathstress")


library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: After First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
 ztxt<-gsub("NaN",".",ztxt)
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

25B final model results(12B)

              coef Fstat       ddf pvalue   VIF
(Intercept)  2.039 7.422    72.992  0.008    NA
language    -0.069 0.022  3704.880  0.882 3.051
distance     0.053 0.020   123.969  0.888 2.656
fratgrpstr  -0.164 4.581    10.669  0.056 1.972 <--
anim        -0.068 3.682   692.243  0.055 1.972 <--
settype     -0.051 3.571  2862.366  0.059 1.511 <--
bovines      0.225 2.384  6429.491  0.123 1.794 <--
famsize      0.032 4.008  1835.967  0.045 1.160 <--
exogamy     -0.106 5.363 10129.656  0.021 1.085 <--
foodtrade   -0.008 2.040  1129.482  0.153 1.126 <--
pathstress   0.028 2.902   453.593  0.089 1.318 <--
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.2265011       0.9951105       0.9872714 
>  ols_stats$restrict_diagnostics
                Fstat        df pvalue
RESET          13.282    88.479  0.000
Wald.on.restrs  0.245     8.364  0.634
NCV            11.393  5213.017  0.001
SW.normal      28.764   553.662  0.000
lag..language   0.257 11161.428  0.612
lag..distance   0.431 13923.423  0.512
216.  TRANSFER OF RESIDENCE AT MARRIAGE: AFTER FIRST YEARS
     1    . = Missing Data
   121126 1 = Wife to Husband's Group 
    33 28 2 = Couple to either Group or Neolocal 
    30    3 = Husband to Wife's Group 
     1    4 = No Common Residence
    30    3 = Husband to Wife's Group (1, 2)

25B R2 higher

              coef  Fstat      ddf pvalue   VIF
(Intercept)  2.002  8.625 1490.746  0.003    NA
language    -0.019  0.002  330.101  0.967 3.036
distance     0.016  0.002  991.594  0.964 2.680
fratgrpstr  -0.200 10.929   53.867  0.002 2.081
anim        -0.057  2.657  749.527  0.104 1.994
settype     -0.051  3.688 2185.534  0.055 1.507
bovines      0.260  3.209 4101.814  0.073 1.812
famsize      0.030  3.671 7427.786  0.055 1.154
exogamy     -0.094  4.178 1577.696  0.041 1.097
foodtrade   -0.007  1.970 7330.280  0.160 1.121
pathstress   0.032  3.845  829.348  0.050 1.342
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.2402673       0.9946663       0.9873376 
>  ols_stats$restrict_diagnostics
                Fstat         df pvalue
RESET          14.965     90.918  0.000
Wald.on.restrs  0.567    385.380  0.452
NCV            11.816   2609.598  0.001
SW.normal      28.115    632.611  0.000
lag..language   0.314 192656.477  0.575
lag..distance   0.518  22794.815  0.472
>

26A DRW:adding v860 to FINAL MODEL: v860 is not significant

setwd("/Users/drwhite/Documents/sccs")  #for macintosh
setwd("C:/My Documents/sccs")
library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
famsize=sccs$v68,    # similar to v80
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
polygyny860=sccs$v860,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c("polygyny860",
"famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
#restrict_vars=c("Whyte631","segadlboys","famsize","exogamy","ncmallow","foodtrade","pathstress")
#12B: that wasn’t the right list
restrict_vars=c("polygyny860",
"fratgrpstr","anim","settype","bovines","famsize","exogamy","foodtrade","pathstress")


library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: After First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
 ztxt<-gsub("NaN",".",ztxt)
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

26B DRW:adding v860 to FINAL MODEL - not significant

              coef Fstat       ddf pvalue   VIF
(Intercept)  2.010 8.524  1303.316  0.004    NA
language     0.064 0.018   672.395  0.893 3.138
distance    -0.022 0.004   627.472  0.952 2.679
polygyny860 -0.053 1.405   756.263  0.236 1.369
fratgrpstr  -0.149 4.761    17.604  0.043 2.181
anim        -0.069 3.687   238.388  0.056 1.967
settype     -0.059 4.844 74831.662  0.028 1.525
bovines      0.221 2.258  1815.066  0.133 1.820
famsize      0.034 4.509   741.930  0.034 1.166
exogamy     -0.101 4.963  6682.771  0.026 1.088
foodtrade   -0.009 2.853  2603.853  0.091 1.142
pathstress   0.036 4.578  1484.318  0.033 1.468 <-- Bayesian inference (prior knowledge) says not causal
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.2398690       0.9952533       0.9897928 
>  ols_stats$restrict_diagnostics
                Fstat        df pvalue
RESET          14.018  4445.284  0.000
Wald.on.restrs  0.869     9.935  0.373
NCV            11.638   917.207  0.001
SW.normal      28.193   921.526  0.000
lag..language   0.263  5593.078  0.608
lag..distance   0.372 75235.462  0.542

26A DRW:Drop pathstress after dropping v860 to FINAL MODEL

setwd("/Users/drwhite/Documents/sccs")  #for macintosh
setwd("C:/My Documents/sccs")
library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
famsize=sccs$v68,    # similar to v80
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
anim=sccs$v206,
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
polygyny860=sccs$v860,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c("polygyny860",
"famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
#restrict_vars=c("Whyte631","segadlboys","famsize","exogamy","ncmallow","foodtrade","pathstress")
#12B: that wasn’t the right list
restrict_vars=c("fratgrpstr","anim","settype","bovines","famsize","exogamy","foodtrade")  #drop ,"pathstress")


library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: After First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
 ztxt<-gsub("NaN",".",ztxt)
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

26B Transfer of Residence at Marriage (v216)

              coef  Fstat        ddf pvalue   VIF
(Intercept)  2.184 11.134   1377.549  0.001    NA
language    -0.036  0.006   4848.280  0.937 2.911
distance     0.079  0.049  14278.368  0.825 2.657
fratgrpstr  -0.142  6.245     66.334  0.015 1.786
anim        -0.069  3.824   2070.425  0.051 1.982
settype     -0.046  3.003   3659.718  0.083 1.451
bovines      0.269  3.371  15373.749  0.066 1.795
famsize      0.032  4.172 109962.990  0.041 1.152
exogamy     -0.103  5.041   3179.187  0.025 1.072
foodtrade   -0.007  1.641   6494.510  0.200 1.121 <-- drop
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.2081387       0.9951156       0.9890491 
>  ols_stats$restrict_diagnostics
                Fstat        df pvalue
RESET          10.616    69.284  0.002
Wald.on.restrs  1.291    31.048  0.265
NCV            14.772 13913.442  0.000
SW.normal      30.119  7766.285  0.000
lag..language   0.287 72903.914  0.592
lag..distance   0.421 55854.233  0.516

27A log anim after DRW:Drop foodtrade, after dropping pathstreess, v860 to FINAL MODEL

setwd("/Users/drwhite/Documents/sccs")  #for macintosh
setwd("C:/My Documents/sccs")
library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
famsize=sccs$v68,    # similar to v80
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
#anim=sccs$v206,
anim=log(1+sccs$v206),
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
polygyny860=sccs$v860,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c("polygyny860",
"famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
#restrict_vars=c("Whyte631","segadlboys","famsize","exogamy","ncmallow","foodtrade","pathstress")
#12B: that wasn’t the right list
restrict_vars=c("fratgrpstr","anim","settype","bovines","famsize","exogamy")#,"foodtrade")  #drop ,"pathstress")


library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: After First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
 ztxt<-gsub("NaN",".",ztxt)
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics

27B FINAL MODEL v216 residence rule DRW:Drop foodtrade, after dropping pathstreess, v860

              coef  Fstat       ddf pvalue   VIF
(Intercept)  2.167 10.012   186.349  0.002    NA
language    -0.175  0.138  1036.084  0.710 2.974
distance     0.179  0.256  9638.212  0.613 2.582
fratgrpstr  -0.141  5.086    21.880  0.034 1.822
anim        -0.081  5.407  1130.643  0.020 1.897
settype     -0.047  3.033  3802.302  0.082 1.456
bovines      0.251  2.765   365.729  0.097 1.787
famsize      0.034  4.632 13588.631  0.031 1.146
exogamy     -0.091  3.925  4488.599  0.048 1.077
> ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.2015373       0.9948653       0.9884199 
> ols_stats$restrict_diagnostics
                Fstat        df pvalue
RESET           9.251   221.921  0.003 some variable here needs to be logged? e.g. Anim?
Wald.on.restrs -0.172     5.414  1.000
NCV            15.420  1590.155  0.000
SW.normal      28.249   601.922  0.000
lag..language   0.304 15899.304  0.581
lag..distance   0.355 40070.502  0.551

27BB log anim after DRW:Drop foodtrade, after dropping pathstress, v860 to FINAL MODEL

LOG (anim didnt make much difference except for making settype less significant 
              coef  Fstat        ddf pvalue   VIF
(Intercept)  2.164 10.776   1705.769  0.001    NA
language    -0.159  0.117   4172.064  0.732 2.966
distance     0.144  0.162  17959.271  0.687 2.632
fratgrpstr  -0.145  7.552    188.885  0.007 1.779
anim        -0.266  5.148 120172.475  0.023 2.338
settype     -0.032  1.620   1239.504  0.203 1.278 <--
bovines      0.305  3.706    978.069  0.055 2.027
famsize      0.032  4.081  20550.264  0.043 1.154
exogamy     -0.084  3.227   1275.761  0.073 1.089
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.2009417       0.9949950       0.9882028 
>  ols_stats$restrict_diagnostics
                Fstat         df pvalue
RESET          10.877    499.017  0.001
Wald.on.restrs  1.134   1140.253  0.287
NCV            14.222    188.766  0.000
SW.normal      28.807   1631.313  0.000
lag..language   0.295  37720.766  0.587
lag..distance   0.386 793986.693  0.535

28A drop settype log anim after DRW:Drop foodtrade, after dropping pathstreess, v860 to FINAL MODEL

setwd("/Users/drwhite/Documents/sccs")  #for macintosh
setwd("C:/My Documents/sccs")
library(sccs)
data(sccs)                                 
depvar=sccs$v216
my_sccs<-data.frame(
dep_var=sccs$v216,
socname=sccs$socname,socID=sccs$"sccs#",
famsize=sccs$v68,    # similar to v80
exogamy=sccs$v72,
#famsizeB=sccs$v80,   # similar to v68
money=sccs$v155,
popdens=sccs$v156,
premarsexatt=sccs$v165,
premarsexfrq=sccs$v166,
malesexag=sccs$v175,
ndrymonth=sccs$v196,
gath=sccs$v203,
hunt=sccs$v204,
fish=sccs$v205,
#anim=sccs$v206,
anim=log(1+sccs$v206),
brideprice=(sccs$v208==1)*1,
nuclearfam=(sccs$v210<=3)*1,
ncmallow=sccs$v227,
cultints=sccs$v232,
tree=(sccs$v233==4)*1,
roots=(sccs$v233==5)*1,
cereals=(sccs$v233==6)*1,
settype=sccs$v234,
localjh=sccs$v236-1,
superjh=sccs$v237,
moralgods=sccs$v238,
segadlboys=sccs$v242,
plow=(sccs$v243>1)*1,
pigs=(sccs$v244==2)*1,
bovines=(sccs$v244==7)*1,
milk=(sccs$v245>1)*1,
agrlateboy=sccs$v300,
valchild=(sccs$v473+sccs$v474+sccs$v475+sccs$v476),
fratgrpstr=sccs$v570,
Whyte577=sccs$v577,    #take care using Whyte variables - only coded 1/2 the sample
Whyte580=sccs$v580,
Whyte584=sccs$v583,
Whyte585=sccs$v584,
Whyte595=sccs$v594,
Whyte602=sccs$v602,
Whyte615=sccs$v615,
Whyte620=sccs$v620,
Whyte626=sccs$v626,
Whyte629=sccs$v629,
Whyte630=sccs$v630,
Whyte631=sccs$v631,
Whyte632=sccs$v632,
Whyte633=sccs$v633,
Whyte635=sccs$v635,
#                    #take care using Paige variables - coded less than 1/2 the sample
Paige657=sccs$v657,  # summed in v663#  Paige657 Paige658 Paige659 Paige660 Paige661 Paige662
femproduceND=sccs$v658, #Paige658=sccs$v658,  # summed in v663 
Paige659=sccs$v659,  # summed in v663
Paige660=sccs$v660,  # summed in v663
Paige661=sccs$v661,  # summed in v663
Paige662=sccs$v662,  # summed in v663
fempower=sccs$v663, # sum of v657-662
interperviol=sccs$v666,   ###synonyms: violence / interviol / freintovio
migr=(sccs$v677==2)*1,
#                    #take care using Sanday variables - only coded 1/2 the sample
Sanday664=sccs$v664,  # summed in v669
Sanday665=sccs$v665,  # summed in v669
Sanday666=sccs$v666,  # summed in v669
Sanday667=sccs$v667,  # summed in v669
Sanday668=sccs$v668,  # summed in v669
Sanday669=sccs$v669, # sum of v664-668 
 #WHYTE Data Quality Whyte718 Whyte719 Whyte720 Whyte721 Whyte722 Whyte723 Whyte724 Whyte725
Whyte718=sccs$v718,    #take care using Whyte variables - only coded 1/2 the sample
Whyte719=sccs$v719,
Whyte720=sccs$v720,
Whyte721=sccs$v721,
Whyte722=sccs$v722,
Whyte723=sccs$v723,
Whyte724=sccs$v724,
Whyte725=sccs$v725,
 #Rohner Data Quality Codes 
Rohner798=sccs$v798,
Rohner799=sccs$v799,
Rohner800=sccs$v800,
Rohner801=sccs$v801,
Rohner802=sccs$v802,
Rohner803=sccs$v803,
Rohner804=sccs$v804,
Rohner805=sccs$v805,
Rohner806=sccs$v806,
Rohner807=sccs$v807,
Rohner808=sccs$v808,
Rohner809=sccs$v809,
Rohner810=sccs$v810,
Rohner811=sccs$v811,
Rohner812=sccs$v812,
Rohner813=sccs$v813,
foodtrade=sccs$v819,
fem_agri=sccs$v821, 
dateobs=sccs$v838,
rain=sccs$v854,
temp=sccs$v855,
#ecorich=sccs$v857,
ecorich=(sccs$v857==3|sccs$v857==4)*1+(sccs$v857==5)*2,
polygyny860=sccs$v860,
pctFemPolyg=sccs$v872,
marrcaptives=sccs$v870,
femsubs=sccs$v890,
intwar=sccs$v891,    # similar to 1649
extwar=sccs$v892,    # similar to 1650
himilexp=(sccs$v899==1)*1,
plunder=sccs$v912,
AP1=sccs$v921,           ###agricultural potential 1
AP2=sccs$v928,           ###agricultural potential 2
pathstress=sccs$v1260,
war=sccs$v1648,     # overall -- sum of internal and external
intwarB=sccs$v1649,  # similar to v891
extwarB=sccs$v1650,  # similar to v892
foodscarc=sccs$v1685,
sexratio=1+(sccs$v1689>85)+(sccs$v1689>115),
wagelabor=sccs$v1732,
CVrain=sccs$v1914/sccs$v1913   #no comma
)  
indep_vars<-c("polygyny860",
"famsize","exogamy",    "money","popdens","malesexag","ndrymonth","gath","hunt","fish",
"anim","brideprice","nuclearfam","ncmallow","cultints","tree","roots","cereals","settype","localjh",
"superjh","moralgods","segadlboys","plow","pigs","bovines","milk","agrlateboy","valchild","fratgrpstr",
"Whyte577","Whyte580","Whyte584","Whyte585","Whyte595","Whyte602","Whyte615","Whyte620","Whyte626","Whyte629",
"Whyte630","Whyte631","Whyte632","Whyte633","Whyte635","Paige657","femproduceND","Paige659","Paige660",
"Paige661","Paige662","fempower","interperviol","migr","Sanday664","Sanday665","Sanday666","Sanday667",
"Sanday668","Sanday669","Whyte718","Whyte719","Whyte720","Whyte721","Whyte722","Whyte723","Whyte724",
"Whyte725","Rohner798","Rohner799","Rohner800","Rohner801","Rohner802","Rohner803","Rohner804","Rohner805",
"Rohner806","Rohner807","Rohner808","Rohner809","Rohner810","Rohner811","Rohner812","Rohner813","foodtrade","fem_agri",
"dateobs","rain","temp","ecorich","pctFemPolyg","femsubs","intwar","extwar","himilexp","AP1","AP2",
"pathstress","war","intwarB","extwarB","foodscarc","sexratio","wagelabor","CVrain"
)
#restrictvars must drop one or more indepvars - in this case, dropping "premarsexatt"
#restrict_vars=c("Whyte631","segadlboys","famsize","exogamy","ncmallow","foodtrade","pathstress")
#12B: that wasn’t the right list
restrict_vars=c("fratgrpstr","anim",#"settype",
"bovines","famsize","exogamy")#,"foodtrade")  #drop ,"pathstress")


library(foreign)
#--Read in two weight matrices--
Wll<-as.matrix(read.dta("./examples/data/langwm.dta")[,-1])
Wdd<-as.matrix(read.dta("./examples/data/dist25wm.dta")[,c(-1,-2,-189)])
load("./examples/data/vaux.Rdata",.GlobalEnv)
my_aux = vaux
row.names(my_aux)<-NULL
#--remove the society name field--
my_aux<-my_aux[,-28]
name<-"Transfer of Residence at Marriage: After First Years"
alias<-"TLCtransferresidence"
model=list(name=name,
           alias=alias,
           data=my_sccs,
           aux_data=my_aux,
           prox_list=list(language=Wll,distance=Wdd),
           dep_var="dep_var",
           indep_vars=indep_vars,
           restrict_vars=restrict_vars)
save(model,file=paste(alias,".Rdata",sep=""))
source("examples/src/run_model.R") #does for this model multiple imputation, two stage ols, saves to file to working directory.
lat<-sccs$v833.1
lon<-sccs$v833.2
plot(lon,lat, cex=.1)
ztxt=as.character(depvar) #above "my_sccs( " -- a new line inserted: depvar= as defined in my_sccs( 
 ztxt<-gsub("NaN",".",ztxt)
text(lon,lat,ztxt)
ols_stats$restrict_stats
ols_stats$r2
ols_stats$restrict_diagnostics



28B drop settype log anim depvar v216 residence

              coef Fstat      ddf pvalue   VIF
(Intercept)  1.805 7.447  141.051  0.007    NA
language    -0.024 0.003  475.383  0.958 2.831
distance     0.138 0.146 7187.044  0.703 2.636
fratgrpstr  -0.129 4.279   17.412  0.054 1.626
anim        -0.251 4.280  260.344  0.040 2.266
bovines      0.218 2.129 3219.519  0.145 1.813
famsize      0.029 3.236 5377.380  0.072 1.113
exogamy     -0.085 3.362 9165.872  0.067 1.076
>  ols_stats$r2
 R2:final model R2:IV_ language R2:IV_ distance 
      0.1829706       0.9948414       0.9877222 
>  ols_stats$restrict_diagnostics
                Fstat        df pvalue
RESET           8.189   191.309  0.005
Wald.on.restrs  0.992    21.881  0.330
NCV            17.186 20563.303  0.000
SW.normal      30.777  2522.627  0.000
lag..language   0.198 34348.290  0.657
lag..distance   0.416 10179.647  0.519