You are here

Group Exercise: More Practice with Factorial ANOVA

We'll examine another example of a linear model with two categorical independent variables and a numeric dependent variable. In the group exercise, you'll select new independent variables to explain variation in the same dependent variable.

# Our DV will be favorability toward the Tea Party movement, V162109

# Our initial independent variables will be gender, V161342, and party affiliation, V161155.
# We'll recode these variables to make the comparisons clearer:
Gender<-0; Gender[V161342==1]<-1; Gender[V161342==2]<-2
PartyAffil<-0; PartyAffil[V161155==1]<-1; PartyAffil[V161155==2]<-2; PartyAffil[V161155==3]<-3

# Now, we'll compute means for the DV by the IVs
describeBy(V162109,Gender)
describeBy(V162109,PartyAffil)
describeBy(V162109,list(Gender,PartyAffil))

# Finally, we'll test the significance of the model. This is the hypothesis test.
summary(lm(V162109~Gender*PartyAffil))

Group Exercise:
Identify different independent variables that you think could explain favorability toward the Tea Party movement and perform the hypothesis test. Interpret the results as appropriate. Paste your R code beneath your interpretation.

Comments

> Race1<-0;Race1[V161310x==1]<-1;Race1[V161310x==2]<-2;Race1[V161310x==3]<-3;Race1[V161310x==4]<-4;Race1[V161310x==5]<-5
> describeBy(V162109,Race1)
> describeBy(V162109,V161307)
> describeBy(V162109,list(Race1,V161307))
> summary(lm(V162109~Race1*V161307))

There is no no evidence that race and class affect favorability toward tea party.

There is no reliable evidence that social class and sexual orientation influence favorability towards the Tea Party.

> ANES2016<-read.csv("http://www.shortell.nyc/online/files/anes_timeseries_2016.csv")
> library(psych)
> attach(ANES2016)
> Class<-0; Class[V161307==1]<-1; Class[V161307==2]<-2; Class[V161307==3]<-3; Class[V161307==4]<-4
> Sexual<-0; Sexual[V161511==1]<-1; Sexual[V161511==2]<-2; Sexual[V161511==3]<-3
> describeBy(V162109, Class)
> describeBy(V162109, Sexual)
> describeBy(V162109,list(Class, Sexual)
+ )
> summary(lm(V162109~Class*Sexual))

describeBy(V162109,V161307)

Descriptive statistics by group
group: 1
vars n mean sd median trimmed mad min max range skew kurtosis se
X1 1 232 62.14 126.79 50 46.59 14.83 0 999 999 6.94 48.4 8.32
-------------------------------------------------------------------------------
group: 2
vars n mean sd median trimmed mad min max range skew kurtosis se
X1 1 723 54.49 90.02 50 47.33 14.83 0 999 999 9.54 97.4 3.35
-------------------------------------------------------------------------------
group: 3
vars n mean sd median trimmed mad min max range skew kurtosis se
X1 1 1159 52.35 96.6 50 43.32 29.65 0 999 999 8.89 84.39 2.84
-------------------------------------------------------------------------------
group: 4
vars n mean sd median trimmed mad min max range skew kurtosis se
X1 1 98 34.68 29.35 30 32.25 41.51 0 100 100 0.44 -0.84 2.96
> describeBy(V162109,V161310b)

Descriptive statistics by group
group: 0
vars n mean sd median trimmed mad min max range skew kurtosis se
X1 1 3128 58.71 115.22 50 46.04 20.76 0 999 999 7.62 59.33 2.06
-------------------------------------------------------------------------------
group: 1
vars n mean sd median trimmed mad min max range skew kurtosis se
X1 1 396 55.92 129.3 50 39.12 28.91 0 999 999 6.83 46.95 6.5
> describeBy(V162109,list(V161310b,V161307))

Descriptive statistics by group
: 0
: 1
vars n mean sd median trimmed mad min max range skew kurtosis se
X1 1 183 57.2 102.13 50 47.61 14.83 0 999 999 8.55 76.06 7.55
-------------------------------------------------------------------------------
: 1
: 1
vars n mean sd median trimmed mad min max range skew kurtosis se
X1 1 46 63.04 143.69 50 42.55 22.98 0 999 999 5.99 36.14 21.19
-------------------------------------------------------------------------------
: 0
: 2
vars n mean sd median trimmed mad min max range skew kurtosis se
X1 1 612 57.61 96.77 50 49.34 14.83 0 999 999 8.99 84.62 3.91
-------------------------------------------------------------------------------
: 1
: 2
vars n mean sd median trimmed mad min max range skew kurtosis se
X1 1 104 35.9 27.87 50 35.06 29.65 0 100 100 -0.03 -1.23 2.73
-------------------------------------------------------------------------------
: 0
: 3
vars n mean sd median trimmed mad min max range skew kurtosis se
X1 1 1054 52.39 92.01 50 44.4 29.65 0 999 999 9.26 92.5 2.83
-------------------------------------------------------------------------------
: 1
: 3
vars n mean sd median trimmed mad min max range skew kurtosis se
X1 1 98 52.4 139.54 40.5 32.88 34.1 0 999 999 6.34 40.14 14.1
-------------------------------------------------------------------------------
: 0
: 4
vars n mean sd median trimmed mad min max range skew kurtosis se
X1 1 91 33.05 28.46 30 30.81 41.51 0 100 100 0.43 -0.92 2.98
-------------------------------------------------------------------------------
: 1
: 4
vars n mean sd median trimmed mad min max range skew kurtosis se
X1 1 7 55.86 34.79 50 55.86 14.83 1 100 99 0.01 -1.37 13.15
> summary(lm(V162109~V161310b*V161307))

Call:
lm(formula = V162109 ~ V161310b * V161307)

Residuals:
Min 1Q Median 3Q Max
-62.06 -26.57 -6.57 8.93 951.94

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 67.557 7.790 8.673 <2e-16 ***
V161310b -17.971 19.742 -0.910 0.3628
V161307 -5.494 2.945 -1.866 0.0622 .
V161310b:V161307 4.653 8.143 0.571 0.5678
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 94.49 on 2191 degrees of freedom
(2076 observations deleted due to missingness)
Multiple R-squared: 0.001991, Adjusted R-squared: 0.0006247
F-statistic: 1.457 on 3 and 2191 DF, p-value: 0.2244

I have no evidence that race and social class affect favorability towards the Tea Party.

> attach(ANES2016)
> class<-0;class[V162132<2]<-1;class[V162132>2]<-2
> lvlofed<-0;lvlofed[V161270<12]<-1;lvlofed[V161270>12]<-2
> describeBy(V162109,class)

Descriptive statistics by group
group: 0
vars n mean sd median trimmed mad min max range skew kurtosis se
X1 1 1 50 NA 50 50 0 50 50 0 NA NA NA
------------------------------------------------------
group: 1
vars n mean sd median trimmed mad min max range skew
X1 1 104 102.84 223.61 50 51.13 1.48 0 999 999 3.69
kurtosis se
X1 11.88 21.93
------------------------------------------------------
group: 2
vars n mean sd median trimmed mad min max range skew
X1 1 722 57.28 120.21 50 42.85 29.65 0 999 999 7.3
kurtosis se
X1 54.32 4.47
> describeBy(V162109,lvlofed)

Descriptive statistics by group
group: 1
vars n mean sd median trimmed mad min max range skew
X1 1 1866 70.31 142.91 50 50.79 14.83 0 999 999 6.15
kurtosis se
X1 37.1 3.31
------------------------------------------------------
group: 2
vars n mean sd median trimmed mad min max range skew
X1 1 1451 43.72 76.22 40 37.33 31.13 0 999 999 10.82
kurtosis se
X1 132.84 2
> describeBy(V162109,list(class,lvlofed))

Descriptive statistics by group
: 0
: 1
vars n mean sd median trimmed mad min max range skew kurtosis se
X1 1 1 50 NA 50 50 0 50 50 0 NA NA NA
------------------------------------------------------
: 1
: 1
vars n mean sd median trimmed mad min max range skew kurtosis
X1 1 89 112.76 240.18 50 51.78 1.48 0 999 999 3.36 9.49
se
X1 25.46
------------------------------------------------------
: 2
: 1
vars n mean sd median trimmed mad min max range skew
X1 1 269 75.23 153.32 50 52.24 23.72 0 999 999 5.67
kurtosis se
X1 31.28 9.35
------------------------------------------------------
: 0
: 2
NULL
------------------------------------------------------
: 1
: 2
vars n mean sd median trimmed mad min max range skew kurtosis
X1 1 9 41 30.7 50 41 29.65 0 89 89 -0.06 -1.48
se
X1 10.23
------------------------------------------------------
: 2
: 2
vars n mean sd median trimmed mad min max range skew kurtosis
X1 1 404 46.47 99 40 35.81 31.88 0 999 999 8.79 81.7
se
X1 4.93

Gender<-0; Gender[V161342==1]<-1; Gender[V161342==2]<-2
> Religion<-0; Religion[V161241==1]<-1; Religion[V161241==2]<-2
> SocClass<-0; SocClass[V162132==1]<-1; SocClass[V162132==2]<-2;SocClass[V162132==3]<-3;SocClass[V162132==4]<-4
> describeBy(V162109,Religion)

Descriptive statistics by group
group: 1
vars n mean sd median trimmed mad min max range skew
X1 1 2308 68.36 134.91 50 51.11 14.83 0 999 999 6.52
kurtosis se
X1 42.08 2.81
---------------------------------------------------
group: 2
vars n mean sd median trimmed mad min max range skew
X1 1 1242 40.29 71.81 40 34.54 29.65 0 999 999 11.46
kurtosis se
X1 150.26 2.04
> describeBy(V162109,SocClass)

Descriptive statistics by group
group: 0
vars n mean sd median trimmed mad min max range skew kurtosis se
X1 1 1 50 NA 50 50 0 50 50 0 NA NA NA
---------------------------------------------------
group: 1
vars n mean sd median trimmed mad min max range skew
X1 1 104 102.84 223.61 50 51.13 1.48 0 999 999 3.69
kurtosis se
X1 11.88 21.93
---------------------------------------------------
group: 2
vars n mean sd median trimmed mad min max range skew
X1 1 508 72.28 151.95 50 50.01 14.83 0 999 999 5.78
kurtosis se
X1 32.37 6.74
---------------------------------------------------
group: 3
vars n mean sd median trimmed mad min max range skew
X1 1 664 58.9 124.92 50 43.38 29.65 0 999 999 7.04
kurtosis se
X1 50.09 4.85
---------------------------------------------------
group: 4
vars n mean sd median trimmed mad min max range skew
X1 1 58 38.74 30.16 37.5 37.02 33.36 0 100 100 0.36
kurtosis se
X1 -0.94 3.96
> describeBy(V162109,list(Religion,SocClass))

Descriptive statistics by group
: 1
: 0
vars n mean sd median trimmed mad min max range skew kurtosis se
X1 1 1 50 NA 50 50 0 50 50 0 NA NA NA
---------------------------------------------------
: 2
: 0
NULL
---------------------------------------------------
: 1
: 1
vars n mean sd median trimmed mad min max range skew
X1 1 74 101.82 216.75 50 53.12 5.19 0 999 999 3.82
kurtosis se
X1 12.87 25.2
---------------------------------------------------
: 2
: 1
vars n mean sd median trimmed mad min max range skew
X1 1 30 105.33 243.55 50 45.21 0.74 0 999 999 3.27
kurtosis se
X1 9.07 44.47
---------------------------------------------------
: 1
: 2
vars n mean sd median trimmed mad min max range skew
X1 1 335 82.54 170.3 50 53.77 14.83 0 999 999 5.1
kurtosis se
X1 24.5 9.3
---------------------------------------------------
: 2
: 2
vars n mean sd median trimmed mad min max range skew
X1 1 171 52.73 106.07 50 42.08 14.83 0 999 999 8.28
kurtosis se
X1 71.09 8.11
---------------------------------------------------
: 1
: 3
vars n mean sd median trimmed mad min max range skew
X1 1 427 73.99 152.53 50 51.33 14.83 0 999 999 5.72
kurtosis se
X1 31.81 7.38
---------------------------------------------------
: 2
: 3
vars n mean sd median trimmed mad min max range skew
X1 1 234 31.63 25.83 30 29.62 29.65 0 100 100 0.45
kurtosis se
X1 -0.74 1.69
---------------------------------------------------
: 1
: 4
vars n mean sd median trimmed mad min max range skew
X1 1 34 45.82 29.8 50 45.46 29.65 0 100 100 0.03
kurtosis se
X1 -1.01 5.11
---------------------------------------------------
: 2
: 4
vars n mean sd median trimmed mad min max range skew
X1 1 24 28.71 28.32 20.5 25.2 29.65 0 100 100 0.89
kurtosis se
X1 -0.14 5.78
> summary(lm(V162109~Religion*SocClass))

Call:
lm(formula = V162109 ~ Religion * SocClass)

Residuals:
Min 1Q Median 3Q Max
-98.14 -34.89 -21.64 -2.95 941.20

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 115.297 43.236 2.667 0.00775 **
Religion -3.905 30.768 -0.127 0.89902
SocClass -1.656 16.622 -0.100 0.92064
Religion:SocClass -11.595 11.736 -0.988 0.32336
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 142.5 on 1326 degrees of freedom
(2941 observations deleted due to missingness)
Multiple R-squared: 0.0207, Adjusted R-squared: 0.01849
F-statistic: 9.344 on 3 and 1326 DF, p-value: 4.096e-06\
There is a significant difference but there is no evidence to prove no religiosity and social class affect favorability of the Tea party

> summary(lm(V162109~class*lvlofed))

Call:
lm(formula = V162109 ~ class * lvlofed)

Residuals:
Min 1Q Median 3Q Max
-110.61 -45.47 -24.58 3.53 952.53

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 255.77 112.41 2.275 0.0232 *
class -75.54 58.41 -1.293 0.1963
lvlofed -110.12 99.28 -1.109 0.2677
class:lvlofed 40.51 50.55 0.801 0.4232
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 141.3 on 768 degrees of freedom
(3499 observations deleted due to missingness)
Multiple R-squared: 0.02324, Adjusted R-squared: 0.01942
F-statistic: 6.09 on 3 and 768 DF, p-value: 0.0004259

WE HAVE NO EVIDENCE THAT CLASS AND LEVEL OF EDUCATION HAVE A SIGNIFICANT AFFECT TOWARDS THE FAVORABILITY OF THE TEA PARTY