For W 11/1

# SOCY7113 A PCA example

# We'll be using tools from the psych library.
library(psych)

# We'll use an example from the ANES2012.
ANES2012<-read.csv("http://www.courseserve.info/files/ANES2012r.csv")
attach(ANES2012)

For W 10/4

#Recode
V162034r<-'NA'; V162034r[V162034a==1]<-1; V162034r[V162034a==2]<-2

#Contingency table
CrossTable(V162034r,V161310a,prop.r=FALSE,prop.c=TRUE,prop.t=FALSE,prop.chisq=FALSE,chisq=TRUE,fisher=TRUE)

For W 9/27

Logistic Regression

Let's test a model to predict voting for Trump in 2016.

First, some recodes:
Vote4Trump<-ifelse(V162034a==2,1,0) #This will be our DV
Gender<-'NA'; Gender[V161342==1]<-1; Gender[V161342==2]<-0
V161310r<-'NA'; V161310r[V161310a>=0]<-0; V161310r[V161310a==1]<-1

Now, the model:
summary(glm(Vote4Trump~Gender+V161310r+V161126))
exp(coef(glm(Vote4Trump~Gender+V161310r+V161126)))

Reading the ANES 2016 dataframe

Use the code:
ANES2016<-read.csv("http://www.shortell.nyc/online/files/anes_timeseries_2016.csv")

If you save your data library (session) in R, you won't have to read in the data again. You need to use attach(ANES2016) to load the variable names in the search string each session, however.

For W 9/6

Let's review the linear model with an example.

DATAFRAME: ANES 2012

DV: Favorability to Democratic Party (ft_dem)

IVs: Political view (libcpre_self)
Attitude toward DACA (immig_citizen) * recoded
Attitude toward affirmative action (aa_uni) * recoded
Religiosity (relig_import)
Gender (gender_respondent)

RECODES
immig_citizenr<-ifelse(immig_citizen==1,1,0)
aa_unir<-ifelse(aa_uni==1,1,0)

MODEL
summary(lm(ft_dem~libcpre_self+immig_citizenr+aa_unir+relig_import+gender_respondent))

Pages

Subscribe to SOCY 7113 RSS