You are here

Group Exercise: Factorial Analysis of Variance

Formulate a sociological model to explain political view. Compute a factorial analysis of variance using ANES 2016, like we did in class with ANES 2012. Perform the hypothesis test. Interpret the results, as appropriate.

Comments

Employment status and class do not affect party affiliation of a person.
> employment<-ifelse(V161276x>=2,1,0)
> describeBy(V161157,list(employment,V161307))

> summary(lm(V161157~employment*V161307))

R version 3.4.1 (2017-06-30) -- "Single Candle"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(psych)
> ANES2016<-read.csv("http://www.shortell.nyc/online/files/anes_timeseries_2016.csv")
> attach(ANES2016)
>
> describeBy(pid_x,list(V161342,V161241))
Error in by(x, group, describe, type = type, ...) :
object 'pid_x' not found
> describeBy(V161158x,list(V161342,V161241))

Descriptive statistics by group
: 1
: 1
vars n mean sd median trimmed mad min max range
X1 1 1197 4.43 2.13 5 4.54 2.97 1 7 6
skew kurtosis se
X1 -0.32 -1.25 0.06
----------------------------------------------
: 2
: 1
vars n mean sd median trimmed mad min max range skew
X1 1 1536 3.96 2.26 4 3.95 2.97 1 7 6 0.02
kurtosis se
X1 -1.49 0.06
----------------------------------------------
: 3
: 1
vars n mean sd median trimmed mad min max range skew
X1 1 8 2.62 1.3 2.5 2.62 2.22 1 4 3 -0.07
kurtosis se
X1 -1.91 0.46
----------------------------------------------
: 1
: 2
vars n mean sd median trimmed mad min max range skew
X1 1 777 3.55 1.96 3 3.44 2.97 1 7 6 0.26
kurtosis se
X1 -1.12 0.07
----------------------------------------------
: 2
: 2
vars n mean sd median trimmed mad min max range skew
X1 1 668 3 1.81 3 2.82 1.48 1 7 6 0.58
kurtosis se
X1 -0.76 0.07
----------------------------------------------
: 3
: 2
vars n mean sd median trimmed mad min max range skew
X1 1 3 2.33 1.15 3 2.33 0 1 3 2 -0.38
kurtosis se
X1 -2.33 0.67
> summary(lm(V161158x~(V161342*V161241))
+
+
+ summary(lm(V161158x~(V161342*V161241))
Error: unexpected symbol in:
"
summary"
>
> summary(lm(V161158x~(V161342*V161241))
+ )

Call:
lm(formula = V161158x ~ (V161342 * V161241))

Residuals:
Min 1Q Median 3Q Max
-3.4400 -1.9522 0.0478 2.0478 4.0025

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.75071 0.31300 18.373 < 2e-16 ***
V161342 -0.42192 0.19384 -2.177 0.02957 *
V161241 -0.82285 0.21479 -3.831 0.00013 ***
V161342:V161241 -0.06592 0.13568 -0.486 0.62713
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2.098 on 4185 degrees of freedom
(82 observations deleted due to missingness)
Multiple R-squared: 0.05118, Adjusted R-squared: 0.0505
F-statistic: 75.25 on 3 and 4185 DF, p-value: < 2.2e-16

> summary(lm(V161158x~V161342*V161241))

Call:
lm(formula = V161158x ~ V161342 * V161241)

Residuals:
Min 1Q Median 3Q Max
-3.4400 -1.9522 0.0478 2.0478 4.0025

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 5.75071 0.31300 18.373 < 2e-16 ***
V161342 -0.42192 0.19384 -2.177 0.02957 *
V161241 -0.82285 0.21479 -3.831 0.00013 ***
V161342:V161241 -0.06592 0.13568 -0.486 0.62713
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2.098 on 4185 degrees of freedom
(82 observations deleted due to missingness)
Multiple R-squared: 0.05118, Adjusted R-squared: 0.0505
F-statistic: 75.25 on 3 and 4185 DF, p-value: < 2.2e-16

There is a significant affect between religiosity and party identification. There is a signficant affect between gender and party identification.

> library(gmodels)
> ANES2016<-read.csv("http://www.shortell.nyc/online/files/anes_timeseries_2016.csv")
> attach(ANES2016)
> library(psych)
> describeBy(V161158x,list(V161310x,V161342))

Descriptive statistics by group
: 1
: 1
vars n mean sd median trimmed mad min max range
X1 1 1418 4.4 2.1 5 4.5 2.97 1 7 6
skew kurtosis se
X1 -0.28 -1.25 0.06
---------------------------------------------
: 2
: 1
vars n mean sd median trimmed mad min max range skew
X1 1 157 2.23 1.5 2 2 1.48 1 7 6 1.27
kurtosis se
X1 1.22 0.12
---------------------------------------------
: 3
: 1
vars n mean sd median trimmed mad min max range skew
X1 1 81 4.19 1.82 4 4.26 2.97 1 7 6 -0.28
kurtosis se
X1 -1.08 0.2
---------------------------------------------
: 4
: 1
vars n mean sd median trimmed mad min max range skew
X1 1 12 3.75 1.66 4 3.7 1.48 1 7 6 -0.08
kurtosis se
X1 -0.45 0.48
---------------------------------------------
: 5
: 1
vars n mean sd median trimmed mad min max range skew
X1 1 228 3.35 1.93 3 3.21 1.48 1 7 6 0.43
kurtosis se
X1 -0.95 0.13
---------------------------------------------
: 6
: 1
vars n mean sd median trimmed mad min max range skew
X1 1 76 4.14 1.63 4 4.18 1.48 1 7 6 -0.16
kurtosis se
X1 -0.43 0.19
---------------------------------------------
: 1
: 2
vars n mean sd median trimmed mad min max range
X1 1 1582 4.07 2.17 4 4.08 2.97 1 7 6
skew kurtosis se
X1 -0.04 -1.41 0.05
---------------------------------------------
: 2
: 2
vars n mean sd median trimmed mad min max range skew
X1 1 235 1.84 1.29 1 1.59 0 1 7 6 1.76
kurtosis se
X1 2.94 0.08
---------------------------------------------
: 3
: 2
vars n mean sd median trimmed mad min max range skew
X1 1 66 3.39 2 3 3.26 1.48 1 7 6 0.44
kurtosis se
X1 -1.16 0.25
---------------------------------------------
: 4
: 2
vars n mean sd median trimmed mad min max range skew
X1 1 14 3.57 1.79 3 3.5 1.48 1 7 6 0.38
kurtosis se
X1 -1.21 0.48
---------------------------------------------
: 5
: 2
vars n mean sd median trimmed mad min max range skew
X1 1 212 2.95 1.87 2 2.74 1.48 1 7 6 0.66
kurtosis se
X1 -0.69 0.13
---------------------------------------------
: 6
: 2
vars n mean sd median trimmed mad min max range skew
X1 1 94 3.41 2.09 3 3.28 2.97 1 7 6 0.42
kurtosis se
X1 -1.16 0.22
---------------------------------------------
: 1
: 3
vars n mean sd median trimmed mad min max range skew
X1 1 6 3.17 1.17 3.5 3.17 0.74 1 4 3 -0.88
kurtosis se
X1 -0.9 0.48
---------------------------------------------
: 2
: 3
NULL
---------------------------------------------
: 3
: 3
NULL
---------------------------------------------
: 4
: 3
vars n mean sd median trimmed mad min max range skew
X1 1 1 2 NA 2 2 0 2 2 0 NA
kurtosis se
X1 NA NA
---------------------------------------------
: 5
: 3
vars n mean sd median trimmed mad min max range skew
X1 1 2 1.5 0.71 1.5 1.5 0.74 1 2 1 0
kurtosis se
X1 -2.75 0.5
---------------------------------------------
: 6
: 3
vars n mean sd median trimmed mad min max range skew
X1 1 2 2 1.41 2 2 1.48 1 3 2 0
kurtosis se
X1 -2.75 1
> summary(lm(V161158x,V161340x))
Error in is.data.frame(data) : object 'V161340x' not found
> summary(lm(V161158x,V161310x))
Error in formula.default(object, env = baseenv()) : invalid formula
> summary(lm(V161158x,V161310x))
Error in formula.default(object, env = baseenv()) : invalid formula
> summary(lm(V161158x~V161310x))

Call:
lm(formula = V161158x ~ V161310x)

Residuals:
Min 1Q Median 3Q Max
-3.0323 -2.0323 -0.0323 1.9677 4.0393

Coefficients:
Estimate Std. Error t value
(Intercept) 4.24668 0.05070 83.76
V161310x -0.21433 0.02132 -10.05
Pr(>|t|)
(Intercept) <2e-16 ***
V161310x <2e-16 ***
---
Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2.128 on 4216 degrees of freedom
(53 observations deleted due to missingness)
Multiple R-squared: 0.02341, Adjusted R-squared: 0.02318
F-statistic: 101.1 on 1 and 4216 DF, p-value: < 2.2e-16

> summary(lm(V161158x~V161310x*V161342))

Call:
lm(formula = V161158x ~ V161310x * V161342)

Residuals:
Min 1Q Median 3Q Max
-3.2470 -1.8571 0.1416 1.7530 4.3539

Coefficients:
Estimate Std. Error t value
(Intercept) 4.78326 0.16172 29.578
V161310x -0.14639 0.06691 -2.188
V161342 -0.34199 0.10026 -3.411
V161310x:V161342 -0.04790 0.04165 -1.150
Pr(>|t|)
(Intercept) < 2e-16 ***
V161310x 0.028722 *
V161342 0.000653 ***
V161310x:V161342 0.250150
---
Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2.116 on 4182 degrees of freedom
(85 observations deleted due to missingness)
Multiple R-squared: 0.0345, Adjusted R-squared: 0.03381
F-statistic: 49.81 on 3 and 4182 DF, p-value: < 2.2e-16

There is no significant interaction between race and gender. However, there is a significant interaction between gender and party affiliation and there is a significant interaction race and party affiliation.

The overall test is significant. I have no evidence that a person's racial identity affects party affiliation, but the interaction for gender is significant
Men on average are more strongly republican.

Cat. C, Alessia.S, Kenton.B.

137 V161095 PRE: Feeling Thermometer: Democratic Party
654 V161511 PRE FTF CASI / WEB: Sexual orientation of R
437 V161310x PRE: SUMMARY ‐ R self‐identified race

describeBy(V161095 ,list(V161511,V161310x))

Both independent variables are significant factors in Democratic Party opinion. Heterosexual Blacks have the highest favorability rating for the Democratic Party, all other races within the same Sexual Orientation fall much lower. Homosexual respondents of the Native American and Other groups showed a higher than average favorability towards the Democratic Party. Regardless of Self-Identified Race Homosexuals and Bisexual people have a higher favorabilty towards the Democratic Party.

> library(psych)
> ANES2016<-read.csv("http://www.shortell.nyc/online/files/anes_timeseries_2016.csv")
> attach(ANES2016)
> library(gmodels)
> library(psych)
> library(pastecs)
Loading required package: boot

Attaching package: ‘boot’

The following object is masked from ‘package:psych’:

logit

> library(gmodels)
>
> library(pastecs)
>
> describeBy(V161095 ,list(V161511,V161310x))

Descriptive statistics by group
: 1
: 1
vars n mean sd median trimmed mad
X1 1 2788 41.86 28.68 40 41.06 37.06
min max range skew kurtosis se
X1 0 100 100 0.09 -1.02 0.54
------------------------------------
: 2
: 1
vars n mean sd median trimmed mad min
X1 1 67 62.22 26.93 70 65.16 22.24 0
max range skew kurtosis se
X1 100 100 -1.02 0.29 3.29
------------------------------------
: 3
: 1
vars n mean sd median trimmed mad min
X1 1 76 58.09 28.44 60 59.68 29.65 0
max range skew kurtosis se
X1 100 100 -0.42 -0.58 3.26
------------------------------------
: 1
: 2
vars n mean sd median trimmed mad min
X1 1 357 74.29 23.78 85 77.5 22.24 0
max range skew kurtosis se
X1 100 100 -1.17 1.31 1.26
------------------------------------
: 2
: 2
vars n mean sd median trimmed mad min
X1 1 15 74.6 28.35 85 77.23 22.24 15
max range skew kurtosis se
X1 100 85 -0.71 -0.95 7.32
------------------------------------
: 3
: 2
vars n mean sd median trimmed mad min
X1 1 14 69.14 22.55 70 71 22.98 16
max range skew kurtosis se
X1 100 84 -0.56 -0.14 6.03
------------------------------------
: 1
: 3
vars n mean sd median trimmed mad min
X1 1 133 50.52 25.24 50 51.63 29.65 0
max range skew kurtosis se
X1 100 100 -0.34 -0.47 2.19
------------------------------------
: 2
: 3
vars n mean sd median trimmed mad min
X1 1 3 80 22.91 85 80 22.24 55
max range skew kurtosis se
X1 100 45 -0.21 -2.33 13.23
------------------------------------
: 3
: 3
vars n mean sd median trimmed mad min max
X1 1 4 64 14.63 60 64 6.67 51 85
range skew kurtosis se
X1 34 0.55 -1.78 7.31
------------------------------------
: 1
: 4
vars n mean sd median trimmed mad min
X1 1 18 52.44 26.09 50 52.62 14.83 2
max range skew kurtosis se
X1 100 98 -0.15 -0.22 6.15
------------------------------------
: 2
: 4
vars n mean sd median trimmed mad min
X1 1 2 75 35.36 75 75 37.06 50
max range skew kurtosis se
X1 100 50 0 -2.75 25
------------------------------------
: 3
: 4
vars n mean sd median trimmed mad min max
X1 1 2 42.5 60.1 42.5 42.5 63.01 0 85
range skew kurtosis se
X1 85 0 -2.75 42.5
------------------------------------
: 1
: 5
vars n mean sd median trimmed mad min
X1 1 388 58.67 27.71 60 60.45 29.65 0
max range skew kurtosis se
X1 100 100 -0.53 -0.35 1.41
------------------------------------
: 2
: 5
vars n mean sd median trimmed mad min
X1 1 18 69.39 20.86 70 69.38 28.91 39
max range skew kurtosis se
X1 100 61 0.09 -1.31 4.92
------------------------------------
: 3
: 5
vars n mean sd median trimmed mad min
X1 1 8 70.75 19.02 72.5 70.75 25.2 50
max range skew kurtosis se
X1 100 50 0.1 -1.72 6.72
------------------------------------
: 1
: 6
vars n mean sd median trimmed mad min
X1 1 150 50.27 31 50 50.68 29.65 0
max range skew kurtosis se
X1 100 100 -0.25 -1.03 2.53
------------------------------------
: 2
: 6
vars n mean sd median trimmed mad min
X1 1 2 85 21.21 85 85 22.24 70
max range skew kurtosis se
X1 100 30 0 -2.75 15
------------------------------------
: 3
: 6
vars n mean sd median trimmed mad min
X1 1 11 49.82 25.25 60 51.44 14.83 0
max range skew kurtosis se
X1 85 85 -0.64 -0.85 7.61
> summary(lm(V161095~V161511*V161310x))

Call:
lm(formula = V161095 ~ V161511 * V161310x)

Residuals:
Min 1Q Median 3Q Max
-64.181 -26.633 4.679 25.367 55.367

Coefficients:
Estimate Std. Error t value
(Intercept) 29.5264 2.2360 13.205
V161511 11.5439 1.9593 5.892
V161310x 5.3421 0.8827 6.052
V161511:V161310x -1.7794 0.7523 -2.365
Pr(>|t|)
(Intercept) < 2e-16 ***
V161511 4.13e-09 ***
V161310x 1.56e-09 ***
V161511:V161310x 0.0181 *
---
Signif. codes:
0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 29.33 on 4052 degrees of freedom
(215 observations deleted due to missingness)
Multiple R-squared: 0.0412, Adjusted R-squared: 0.04049
F-statistic: 58.04 on 3 and 4052 DF, p-value: < 2.2e-16