library(Zelig)
## Loading required package: MASS
## Loading required package: boot
## ##
## ## Zelig (Version 3.5.3, built: 2011-11-29)
## ## Please refer to http://gking.harvard.edu/zelig for full
## ## documentation or help.zelig() for help with commands and
## ## models supported by Zelig.
## ##
##
## ## Zelig project citations:
## ## Kosuke Imai, Gary King, and Olivia Lau. (2009).
## ## ``Zelig: Everyone's Statistical Software,''
## ## http://gking.harvard.edu/zelig.
## ## and
## ## Kosuke Imai, Gary King, and Olivia Lau. (2008).
## ## ``Toward A Common Framework for Statistical Analysis
## ## and Development,'' Journal of Computational and
## ## Graphical Statistics, Vol. 17, No. 4 (December)
## ## pp. 892-913.
##
## ## To cite individual Zelig models, please use the citation format printed with
## ## each model run and in the documentation.
## ##
library(DescTools)
library(stargazer)
##
## Please cite as:
##
## Hlavac, Marek (2014). stargazer: LaTeX code and ASCII text for well-formatted regression and summary statistics tables.
## R package version 5.1. http://CRAN.R-project.org/package=stargazer
library(dplyr)
##
## Attaching package: 'dplyr'
##
## The following object is masked from 'package:MASS':
##
## select
##
## The following object is masked from 'package:stats':
##
## filter
##
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyr)
library(memisc)
## Loading required package: lattice
##
## Attaching package: 'lattice'
##
## The following object is masked from 'package:boot':
##
## melanoma
##
##
## Attaching package: 'memisc'
##
## The following objects are masked from 'package:dplyr':
##
## collect, query, rename
##
## The following object is masked from 'package:DescTools':
##
## %nin%
##
## The following objects are masked from 'package:stats':
##
## contr.sum, contr.treatment, contrasts
##
## The following object is masked from 'package:base':
##
## as.array
library(pander)
library(foreign)
library(gmodels)
library(car)
##
## Attaching package: 'car'
##
## The following object is masked from 'package:memisc':
##
## recode
##
## The following object is masked from 'package:DescTools':
##
## Recode
##
## The following object is masked from 'package:boot':
##
## logit
library(visreg)
library(aod)
library(erer)
## Loading required package: lmtest
## Loading required package: zoo
##
## Attaching package: 'zoo'
##
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
GSS = read.spss("C:\\Users\\Robert Johnson\\RSquared\\GSS2014.sav", to.data.frame=TRUE)
## Warning in read.spss("C:\\Users\\Robert Johnson\\RSquared\\GSS2014.sav", :
## C:\Users\Robert Johnson\RSquared\GSS2014.sav: Unrecognized record type 7,
## subtype 18 encountered in system file
## Warning in `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels)
## else paste0(labels, : duplicated levels in factors are deprecated
## Warning in `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels)
## else paste0(labels, : duplicated levels in factors are deprecated
## Warning in `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels)
## else paste0(labels, : duplicated levels in factors are deprecated
## Warning in `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels)
## else paste0(labels, : duplicated levels in factors are deprecated
## How to cite this model in Zelig:
## Kosuke Imai, Gary King, and Oliva Lau. 2008. "logit: Logistic Regression for Dichotomous Dependent Variables" in Kosuke Imai, Gary King, and Olivia Lau, "Zelig: Everyone's Statistical Software," http://gking.harvard.edu/zelig
##
## Model: logit
## Number of simulations: 1000
##
## Values of X
## (Intercept) raceBLACK raceOTHER age
## 1 1 0 0 49.43758
##
## Expected Values: E(Y|X)
## mean sd 2.5% 97.5%
## 1 0.5925005 0.01442349 0.5636585 0.6196563
##
## Predicted Values: Y|X
## 0 1
## 1 0.432 0.568
## How to cite this model in Zelig:
## Kosuke Imai, Gary King, and Oliva Lau. 2008. "logit: Logistic Regression for Dichotomous Dependent Variables" in Kosuke Imai, Gary King, and Olivia Lau, "Zelig: Everyone's Statistical Software," http://gking.harvard.edu/zelig
##
## Model: logit
## Number of simulations: 1000
##
## Values of X
## (Intercept) raceBLACK raceOTHER age sexFEMALE
## 1 1 0 0 49.43758 1
##
## Expected Values: E(Y|X)
## mean sd 2.5% 97.5%
## 1 0.5924156 0.01886343 0.5546601 0.6284884
##
## Predicted Values: Y|X
## 0 1
## 1 0.378 0.622
The below two logistical regressions look at the relationship between race sex and political views, whether or not race or sex is a factor in political views. 1 looks at the relationship between sex and political views. 2 does the same thing but uses age instead of race. 1 has as a lower Akaike so is better to interpret over model 2. According to the chart sex is least likely to be a factor in voting and this is not statistically significant. When race is considered the likelihood of it having an effect on someone’s political views it is 49.9% and is statistically significant. According to the logistical regression race plays a bigger factor in political views than sex.
lmod1<- zelig(sex~ polviews + race, model="logit", data= GSS)
## How to cite this model in Zelig:
## Kosuke Imai, Gary King, and Oliva Lau. 2008. "logit: Logistic Regression for Dichotomous Dependent Variables" in Kosuke Imai, Gary King, and Olivia Lau, "Zelig: Everyone's Statistical Software," http://gking.harvard.edu/zelig
lmod2<- zelig(sex~ polviews + age, model="logit", data= GSS)
## How to cite this model in Zelig:
## Kosuke Imai, Gary King, and Oliva Lau. 2008. "logit: Logistic Regression for Dichotomous Dependent Variables" in Kosuke Imai, Gary King, and Olivia Lau, "Zelig: Everyone's Statistical Software," http://gking.harvard.edu/zelig
stargazer(lmod1, lmod2, type="text")
##
## ==============================================
## Dependent variable:
## ----------------------------
## sex
## (1) (2)
## ----------------------------------------------
## polviews 0.001 0.001
## (0.003) (0.003)
##
## raceBLACK 0.499***
## (0.117)
##
## raceOTHER -0.041
## (0.134)
##
## age 0.001
## (0.002)
##
## Constant 0.124** 0.121
## (0.049) (0.122)
##
## ----------------------------------------------
## Observations 2,514 2,505
## Log Likelihood -1,719.986 -1,723.633
## Akaike Inf. Crit. 3,447.973 3,453.265
## ==============================================
## Note: *p<0.1; **p<0.05; ***p<0.01
GSS2 <- zelig(polviewsbinary ~ agebinary + educbinary + agebinary:educbinary, data = GSS, model = "logit")
## How to cite this model in Zelig:
## Kosuke Imai, Gary King, and Oliva Lau. 2008. "logit: Logistic Regression for Dichotomous Dependent Variables" in Kosuke Imai, Gary King, and Olivia Lau, "Zelig: Everyone's Statistical Software," http://gking.harvard.edu/zelig
xh1 <- setx(GSS2, agebinary = 1, sex = "yes")
xl1 <- setx(GSS2, agebinary = 0, sex = "yes")
xh0 <- setx(GSS2, agebinary = 1, sex = "no")
xl0 <- setx(GSS2, agebinary = 0, sex = "no")
zh1 <- sim(GSS2, x=xh1)
zl1 <- sim(GSS2, x=xl1)
zh0 <- sim(GSS2, x=xh0)
zl0 <- sim(GSS2, x=xl0)
eff <- (zh1$qi$ev - zl1$qi$ev) - (zh0$qi$ev - zl0$qi$ev)
quantile(eff, c(.025,.975))
## 2.5% 97.5%
## -0.09966472 0.09312542
hist(eff)